everything except keyword args seems to work for now
This commit is contained in:
+1
-1
Submodule 3rd/ftb updated: 7d8eabf479...7b128b33c9
Binary file not shown.
Executable → Regular
+3
-1
@@ -77,7 +77,8 @@ namespace Slime {
|
||||
try result = eval_expr(expr);
|
||||
}
|
||||
|
||||
delete program;
|
||||
program->dealloc();
|
||||
free(program);
|
||||
free(file_content);
|
||||
|
||||
return result;
|
||||
@@ -1012,6 +1013,7 @@ namespace Slime {
|
||||
profile_with_name("(exit)");
|
||||
fetch(code);
|
||||
try assert_type(code, Lisp_Object_Type::Number);
|
||||
Slime::Memory::free_everything();
|
||||
exit((int)code->value.number);
|
||||
};
|
||||
define((break), "TODO") {
|
||||
|
||||
+25
-18
@@ -44,6 +44,7 @@ namespace Slime {
|
||||
|
||||
Lisp_Object* sym, *val; // used as temp storage to use `try`
|
||||
Array_List<Lisp_Object*> read_in_keywords;
|
||||
read_in_keywords.alloc();
|
||||
int obligatory_keywords_count = 0;
|
||||
int read_obligatory_keywords_count = 0;
|
||||
|
||||
@@ -73,6 +74,7 @@ namespace Slime {
|
||||
};
|
||||
|
||||
proc read_keyword_args = [&] {
|
||||
// debug_break();
|
||||
// keyword arguments: use all given ones and keep track of the
|
||||
// added ones (array list), if end of parameters in encountered or
|
||||
// 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) {
|
||||
// check if this one is even an accepted keyword
|
||||
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])
|
||||
{
|
||||
accepted = true;
|
||||
@@ -146,12 +148,12 @@ namespace Slime {
|
||||
try_void sym = Memory::get_symbol(next_arg->value.symbol);
|
||||
next_arg = cs->data[++arg_start];
|
||||
--arg_count;
|
||||
|
||||
// NOTE(Felix): It seems we do not need to evaluate the argument here...
|
||||
if (is_c_function) {
|
||||
try_void define_symbol(sym, next_arg);
|
||||
} else {
|
||||
try_void define_symbol(
|
||||
sym,
|
||||
try_void define_symbol(sym,
|
||||
Memory::copy_lisp_object_except_pairs(next_arg));
|
||||
}
|
||||
|
||||
@@ -239,7 +241,6 @@ namespace Slime {
|
||||
try check_keyword_args();
|
||||
try read_rest_arg();
|
||||
|
||||
// TODO(Felix): fucking destructors
|
||||
return new_env;
|
||||
}
|
||||
proc create_extended_environment_for_function_application(
|
||||
@@ -283,6 +284,10 @@ namespace Slime {
|
||||
|
||||
Lisp_Object* sym, *val; // used as temp storage to use `try`
|
||||
Array_List<Lisp_Object*> read_in_keywords;
|
||||
read_in_keywords.alloc();
|
||||
defer {
|
||||
read_in_keywords.dealloc();
|
||||
};
|
||||
int obligatory_keywords_count = 0;
|
||||
int read_obligatory_keywords_count = 0;
|
||||
|
||||
@@ -664,6 +669,11 @@ namespace Slime {
|
||||
Array_List<Action> nas;
|
||||
Array_List<int> ams;
|
||||
|
||||
cs.alloc();
|
||||
pcs.alloc();
|
||||
nas.alloc();
|
||||
ams.alloc();
|
||||
|
||||
proc debug_step = [&] {
|
||||
printf("cs:\n ");
|
||||
for (auto lo : cs) {
|
||||
@@ -1020,20 +1030,17 @@ namespace Slime {
|
||||
|
||||
Lisp_Object* parsed, * evaluated;
|
||||
while (true) {
|
||||
[&] {
|
||||
delete_error();
|
||||
fputs("> ", stdout);
|
||||
line = read_expression();
|
||||
defer {
|
||||
free(line);
|
||||
};
|
||||
try_void parsed = Parser::parse_single_expression(line);
|
||||
try_void evaluated = nrc_eval(parsed);
|
||||
if (evaluated != Memory::nil) {
|
||||
print(evaluated);
|
||||
fputs("\n", stdout);
|
||||
}
|
||||
}();
|
||||
delete_error();
|
||||
fputs("> ", stdout);
|
||||
line = read_expression();
|
||||
try_void parsed = Parser::parse_single_expression(line);
|
||||
free(line);
|
||||
try_void evaluated = nrc_eval(parsed);
|
||||
// try_void evaluated = eval_expr(parsed);
|
||||
if (evaluated != Memory::nil) {
|
||||
print(evaluated);
|
||||
fputs("\n", stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -38,16 +38,16 @@ namespace Slime {
|
||||
delete this->value.hashMap;
|
||||
} break;
|
||||
case Lisp_Object_Type::CFunction: {
|
||||
this->value.cFunction->args.positional.symbols.~Array_List();
|
||||
this->value.cFunction->args.keyword.keywords.~Array_List();
|
||||
this->value.cFunction->args.keyword.values.~Array_List();
|
||||
delete this->value.cFunction;
|
||||
this->value.cFunction->args.positional.symbols.dealloc();
|
||||
this->value.cFunction->args.keyword.keywords.dealloc();
|
||||
this->value.cFunction->args.keyword.values.dealloc();
|
||||
free(this->value.cFunction);
|
||||
} break;
|
||||
case Lisp_Object_Type::Function:{
|
||||
this->value.function->args.positional.symbols.~Array_List();
|
||||
this->value.function->args.keyword.keywords.~Array_List();
|
||||
this->value.function->args.keyword.values.~Array_List();
|
||||
delete this->value.function;
|
||||
this->value.function->args.positional.symbols.dealloc();
|
||||
this->value.function->args.keyword.keywords.dealloc();
|
||||
this->value.function->args.keyword.values.dealloc();
|
||||
free(this->value.function);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
+6
-6
@@ -3,12 +3,12 @@
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// enable colored terminal output for windows
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwMode = 0;
|
||||
GetConsoleMode(hOut, &dwMode);
|
||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
SetConsoleMode(hOut, dwMode);
|
||||
// enable colored terminal output for windows
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwMode = 0;
|
||||
GetConsoleMode(hOut, &dwMode);
|
||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
SetConsoleMode(hOut, dwMode);
|
||||
#endif
|
||||
|
||||
if (argc > 1) {
|
||||
|
||||
+18
-4
@@ -139,10 +139,15 @@ namespace Slime::Memory {
|
||||
lo->~Lisp_Object();
|
||||
});
|
||||
environment_memory.for_each([](Environment* env){
|
||||
env->parents.dealloc();
|
||||
env->~Environment();
|
||||
});
|
||||
// free the exe dir:
|
||||
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();
|
||||
|
||||
// inject a new array list;
|
||||
new(&env->parents) Array_List<Environment*>;
|
||||
|
||||
env->parents.alloc();
|
||||
if (parent)
|
||||
env->parents.append(parent);
|
||||
|
||||
@@ -171,6 +175,10 @@ namespace Slime::Memory {
|
||||
profile_this();
|
||||
char* exe_path = get_exe_dir();
|
||||
// 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("../bin/");
|
||||
|
||||
@@ -420,7 +428,10 @@ namespace Slime::Memory {
|
||||
Lisp_Object* node;
|
||||
try node = create_lisp_object();
|
||||
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;
|
||||
return node;
|
||||
}
|
||||
@@ -429,7 +440,10 @@ namespace Slime::Memory {
|
||||
Lisp_Object* func;
|
||||
try func = Memory::create_lisp_object();
|
||||
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;
|
||||
return func;
|
||||
}
|
||||
|
||||
+2
-1
@@ -381,7 +381,8 @@ namespace Slime::Parser {
|
||||
parser_line = 1;
|
||||
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;
|
||||
Lisp_Object* parsed;
|
||||
|
||||
@@ -96,7 +96,6 @@ namespace Slime {
|
||||
Hash_Map<void*, Lisp_Object*> hm;
|
||||
|
||||
~Environment() {
|
||||
parents.~Array_List();
|
||||
hm.~Hash_Map();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,6 +118,10 @@ namespace Slime {
|
||||
proc test_array_lists_adding_and_removing() -> testresult {
|
||||
// test adding and removing
|
||||
Array_List<int> list;
|
||||
list.alloc();
|
||||
defer {
|
||||
list.dealloc();
|
||||
};
|
||||
list.append(1);
|
||||
list.append(2);
|
||||
list.append(3);
|
||||
@@ -144,6 +148,11 @@ namespace Slime {
|
||||
proc test_array_lists_sorting() -> testresult {
|
||||
// test adding and removing
|
||||
Array_List<int> list;
|
||||
list.alloc();
|
||||
defer {
|
||||
list.dealloc();
|
||||
};
|
||||
|
||||
list.append(1);
|
||||
list.append(2);
|
||||
list.append(3);
|
||||
@@ -177,6 +186,11 @@ namespace Slime {
|
||||
|
||||
proc test_array_lists_searching() -> testresult {
|
||||
Array_List<int> list;
|
||||
list.alloc();
|
||||
defer {
|
||||
list.dealloc();
|
||||
};
|
||||
|
||||
list.append(1);
|
||||
list.append(2);
|
||||
list.append(3);
|
||||
|
||||
Executable → Regular
Executable → Regular
Reference in New Issue
Block a user