everything except keyword args seems to work for now

This commit is contained in:
FelixBrendel
2020-01-15 00:21:45 +01:00
parent 5b6a26b067
commit b83a479533
14 changed files with 77 additions and 40 deletions
+1 -1
Submodule 3rd/ftb updated: 7d8eabf479...7b128b33c9
BIN
View File
Binary file not shown.
Executable → Regular
View File
Executable → Regular
View File
+3 -1
View File
@@ -77,7 +77,8 @@ namespace Slime {
try result = eval_expr(expr); try result = eval_expr(expr);
} }
delete program; program->dealloc();
free(program);
free(file_content); free(file_content);
return result; return result;
@@ -1012,6 +1013,7 @@ namespace Slime {
profile_with_name("(exit)"); profile_with_name("(exit)");
fetch(code); fetch(code);
try assert_type(code, Lisp_Object_Type::Number); try assert_type(code, Lisp_Object_Type::Number);
Slime::Memory::free_everything();
exit((int)code->value.number); exit((int)code->value.number);
}; };
define((break), "TODO") { define((break), "TODO") {
+25 -18
View File
@@ -44,6 +44,7 @@ namespace Slime {
Lisp_Object* sym, *val; // used as temp storage to use `try` Lisp_Object* sym, *val; // used as temp storage to use `try`
Array_List<Lisp_Object*> read_in_keywords; Array_List<Lisp_Object*> read_in_keywords;
read_in_keywords.alloc();
int obligatory_keywords_count = 0; int obligatory_keywords_count = 0;
int read_obligatory_keywords_count = 0; int read_obligatory_keywords_count = 0;
@@ -73,6 +74,7 @@ namespace Slime {
}; };
proc read_keyword_args = [&] { proc read_keyword_args = [&] {
// debug_break();
// keyword arguments: use all given ones and keep track of the // keyword arguments: use all given ones and keep track of the
// added ones (array list), if end of parameters in encountered or // added ones (array list), if end of parameters in encountered or
// something that is not a keyword is encountered or a keyword // something that is not a keyword is encountered or a keyword
@@ -93,7 +95,7 @@ namespace Slime {
while (Memory::get_type(next_arg) == Lisp_Object_Type::Keyword) { while (Memory::get_type(next_arg) == Lisp_Object_Type::Keyword) {
// check if this one is even an accepted keyword // check if this one is even an accepted keyword
bool accepted = false; bool accepted = false;
for (int i = 0; i < arg_spec->keyword.values.next_index; ++i) { for (int i = 0; i < arg_spec->keyword.keywords.next_index; ++i) {
if (next_arg == arg_spec->keyword.keywords.data[i]) if (next_arg == arg_spec->keyword.keywords.data[i])
{ {
accepted = true; accepted = true;
@@ -146,12 +148,12 @@ namespace Slime {
try_void sym = Memory::get_symbol(next_arg->value.symbol); try_void sym = Memory::get_symbol(next_arg->value.symbol);
next_arg = cs->data[++arg_start]; next_arg = cs->data[++arg_start];
--arg_count; --arg_count;
// NOTE(Felix): It seems we do not need to evaluate the argument here... // NOTE(Felix): It seems we do not need to evaluate the argument here...
if (is_c_function) { if (is_c_function) {
try_void define_symbol(sym, next_arg); try_void define_symbol(sym, next_arg);
} else { } else {
try_void define_symbol( try_void define_symbol(sym,
sym,
Memory::copy_lisp_object_except_pairs(next_arg)); Memory::copy_lisp_object_except_pairs(next_arg));
} }
@@ -239,7 +241,6 @@ namespace Slime {
try check_keyword_args(); try check_keyword_args();
try read_rest_arg(); try read_rest_arg();
// TODO(Felix): fucking destructors
return new_env; return new_env;
} }
proc create_extended_environment_for_function_application( proc create_extended_environment_for_function_application(
@@ -283,6 +284,10 @@ namespace Slime {
Lisp_Object* sym, *val; // used as temp storage to use `try` Lisp_Object* sym, *val; // used as temp storage to use `try`
Array_List<Lisp_Object*> read_in_keywords; Array_List<Lisp_Object*> read_in_keywords;
read_in_keywords.alloc();
defer {
read_in_keywords.dealloc();
};
int obligatory_keywords_count = 0; int obligatory_keywords_count = 0;
int read_obligatory_keywords_count = 0; int read_obligatory_keywords_count = 0;
@@ -664,6 +669,11 @@ namespace Slime {
Array_List<Action> nas; Array_List<Action> nas;
Array_List<int> ams; Array_List<int> ams;
cs.alloc();
pcs.alloc();
nas.alloc();
ams.alloc();
proc debug_step = [&] { proc debug_step = [&] {
printf("cs:\n "); printf("cs:\n ");
for (auto lo : cs) { for (auto lo : cs) {
@@ -1020,20 +1030,17 @@ namespace Slime {
Lisp_Object* parsed, * evaluated; Lisp_Object* parsed, * evaluated;
while (true) { while (true) {
[&] { delete_error();
delete_error(); fputs("> ", stdout);
fputs("> ", stdout); line = read_expression();
line = read_expression(); try_void parsed = Parser::parse_single_expression(line);
defer { free(line);
free(line); try_void evaluated = nrc_eval(parsed);
}; // try_void evaluated = eval_expr(parsed);
try_void parsed = Parser::parse_single_expression(line); if (evaluated != Memory::nil) {
try_void evaluated = nrc_eval(parsed); print(evaluated);
if (evaluated != Memory::nil) { fputs("\n", stdout);
print(evaluated); }
fputs("\n", stdout);
}
}();
} }
} }
} }
+8 -8
View File
@@ -38,16 +38,16 @@ namespace Slime {
delete this->value.hashMap; delete this->value.hashMap;
} break; } break;
case Lisp_Object_Type::CFunction: { case Lisp_Object_Type::CFunction: {
this->value.cFunction->args.positional.symbols.~Array_List(); this->value.cFunction->args.positional.symbols.dealloc();
this->value.cFunction->args.keyword.keywords.~Array_List(); this->value.cFunction->args.keyword.keywords.dealloc();
this->value.cFunction->args.keyword.values.~Array_List(); this->value.cFunction->args.keyword.values.dealloc();
delete this->value.cFunction; free(this->value.cFunction);
} break; } break;
case Lisp_Object_Type::Function:{ case Lisp_Object_Type::Function:{
this->value.function->args.positional.symbols.~Array_List(); this->value.function->args.positional.symbols.dealloc();
this->value.function->args.keyword.keywords.~Array_List(); this->value.function->args.keyword.keywords.dealloc();
this->value.function->args.keyword.values.~Array_List(); this->value.function->args.keyword.values.dealloc();
delete this->value.function; free(this->value.function);
} break; } break;
default: break; default: break;
} }
+6 -6
View File
@@ -3,12 +3,12 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
#ifdef _MSC_VER #ifdef _MSC_VER
// enable colored terminal output for windows // enable colored terminal output for windows
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0; DWORD dwMode = 0;
GetConsoleMode(hOut, &dwMode); GetConsoleMode(hOut, &dwMode);
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(hOut, dwMode); SetConsoleMode(hOut, dwMode);
#endif #endif
if (argc > 1) { if (argc > 1) {
+18 -4
View File
@@ -139,10 +139,15 @@ namespace Slime::Memory {
lo->~Lisp_Object(); lo->~Lisp_Object();
}); });
environment_memory.for_each([](Environment* env){ environment_memory.for_each([](Environment* env){
env->parents.dealloc();
env->~Environment(); env->~Environment();
}); });
// free the exe dir: // free the exe dir:
free(Globals::load_path.data[0]); free(Globals::load_path.data[0]);
Globals::load_path.dealloc();
Globals::Current_Execution::call_stack.dealloc();
Globals::Current_Execution::envi_stack.dealloc();
} }
@@ -151,8 +156,7 @@ namespace Slime::Memory {
Environment* env = environment_memory.allocate(); Environment* env = environment_memory.allocate();
// inject a new array list; // inject a new array list;
new(&env->parents) Array_List<Environment*>; env->parents.alloc();
if (parent) if (parent)
env->parents.append(parent); env->parents.append(parent);
@@ -171,6 +175,10 @@ namespace Slime::Memory {
profile_this(); profile_this();
char* exe_path = get_exe_dir(); char* exe_path = get_exe_dir();
// don't free exe path because it will be used until end of time // don't free exe path because it will be used until end of time
Globals::load_path.alloc();
Globals::Current_Execution::call_stack.alloc();
Globals::Current_Execution::envi_stack.alloc();
add_to_load_path(exe_path); add_to_load_path(exe_path);
add_to_load_path("../bin/"); add_to_load_path("../bin/");
@@ -420,7 +428,10 @@ namespace Slime::Memory {
Lisp_Object* node; Lisp_Object* node;
try node = create_lisp_object(); try node = create_lisp_object();
set_type(node, Lisp_Object_Type::CFunction); set_type(node, Lisp_Object_Type::CFunction);
node->value.cFunction = new cFunction; node->value.cFunction = (cFunction*)malloc(sizeof(cFunction));
node->value.cFunction->args.keyword.keywords.alloc();
node->value.cFunction->args.keyword.values.alloc();
node->value.cFunction->args.positional.symbols.alloc();
node->value.cFunction->is_special_form = is_special; node->value.cFunction->is_special_form = is_special;
return node; return node;
} }
@@ -429,7 +440,10 @@ namespace Slime::Memory {
Lisp_Object* func; Lisp_Object* func;
try func = Memory::create_lisp_object(); try func = Memory::create_lisp_object();
Memory::set_type(func, Lisp_Object_Type::Function); Memory::set_type(func, Lisp_Object_Type::Function);
func->value.function = new Function; func->value.function = (Function*)malloc(sizeof(Function));
func->value.function->args.keyword.keywords.alloc();
func->value.function->args.keyword.values.alloc();
func->value.function->args.positional.symbols.alloc();
func->value.function->type = ft; func->value.function->type = ft;
return func; return func;
} }
+2 -1
View File
@@ -381,7 +381,8 @@ namespace Slime::Parser {
parser_line = 1; parser_line = 1;
parser_col = 0; parser_col = 0;
Array_List<Lisp_Object*>* program = new Array_List<Lisp_Object*>; Array_List<Lisp_Object*>* program = (Array_List<Lisp_Object*>*)malloc(sizeof(Array_List<Lisp_Object*>));
program->alloc();
int index_in_text = 0; int index_in_text = 0;
Lisp_Object* parsed; Lisp_Object* parsed;
-1
View File
@@ -96,7 +96,6 @@ namespace Slime {
Hash_Map<void*, Lisp_Object*> hm; Hash_Map<void*, Lisp_Object*> hm;
~Environment() { ~Environment() {
parents.~Array_List();
hm.~Hash_Map(); hm.~Hash_Map();
} }
}; };
+14
View File
@@ -118,6 +118,10 @@ namespace Slime {
proc test_array_lists_adding_and_removing() -> testresult { proc test_array_lists_adding_and_removing() -> testresult {
// test adding and removing // test adding and removing
Array_List<int> list; Array_List<int> list;
list.alloc();
defer {
list.dealloc();
};
list.append(1); list.append(1);
list.append(2); list.append(2);
list.append(3); list.append(3);
@@ -144,6 +148,11 @@ namespace Slime {
proc test_array_lists_sorting() -> testresult { proc test_array_lists_sorting() -> testresult {
// test adding and removing // test adding and removing
Array_List<int> list; Array_List<int> list;
list.alloc();
defer {
list.dealloc();
};
list.append(1); list.append(1);
list.append(2); list.append(2);
list.append(3); list.append(3);
@@ -177,6 +186,11 @@ namespace Slime {
proc test_array_lists_searching() -> testresult { proc test_array_lists_searching() -> testresult {
Array_List<int> list; Array_List<int> list;
list.alloc();
defer {
list.dealloc();
};
list.append(1); list.append(1);
list.append(2); list.append(2);
list.append(3); list.append(3);
Executable → Regular
View File
Executable → Regular
View File