why do static variables break everything?
This commit is contained in:
+5
-5
@@ -102,7 +102,7 @@ proc load_built_ins_into_environment() -> void {
|
|||||||
|
|
||||||
|
|
||||||
#define fetch1(var) \
|
#define fetch1(var) \
|
||||||
static Lisp_Object* var##_symbol = Memory::get_or_create_lisp_object_symbol(#var); \
|
Lisp_Object* var##_symbol = Memory::get_or_create_lisp_object_symbol(#var); \
|
||||||
Lisp_Object* var = lookup_symbol(var##_symbol, get_current_environment()); \
|
Lisp_Object* var = lookup_symbol(var##_symbol, get_current_environment()); \
|
||||||
if (Globals::error) printf("in %s:%d\n", __FILE__, __LINE__)
|
if (Globals::error) printf("in %s:%d\n", __FILE__, __LINE__)
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ proc load_built_ins_into_environment() -> void {
|
|||||||
); \
|
); \
|
||||||
assert_type(label(params,__LINE__), Lisp_Object_Type::Pair); \
|
assert_type(label(params,__LINE__), Lisp_Object_Type::Pair); \
|
||||||
assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \
|
assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \
|
||||||
static auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \
|
auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \
|
||||||
auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \
|
auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \
|
||||||
/*NOTE(Felix): for evaluating default args*/ \
|
/*NOTE(Felix): for evaluating default args*/ \
|
||||||
/*push_environment(get_root_environment());*/ \
|
/*push_environment(get_root_environment());*/ \
|
||||||
@@ -586,14 +586,14 @@ proc load_built_ins_into_environment() -> void {
|
|||||||
};
|
};
|
||||||
define_special((quasiquote expr), "TODO") {
|
define_special((quasiquote expr), "TODO") {
|
||||||
fetch(expr);
|
fetch(expr);
|
||||||
static auto unquote_sym = Memory::get_or_create_lisp_object_symbol("unquote");
|
Lisp_Object* unquote_sym = Memory::get_or_create_lisp_object_symbol("unquote");
|
||||||
static auto unquote_splicing_sym = Memory::get_or_create_lisp_object_symbol("unquote-splicing");
|
Lisp_Object* unquote_splicing_sym = Memory::get_or_create_lisp_object_symbol("unquote-splicing");
|
||||||
/* recursive lambdas in lambdas yay!! */
|
/* recursive lambdas in lambdas yay!! */
|
||||||
// NOTE(Felix): first we have to initialize the variable
|
// NOTE(Felix): first we have to initialize the variable
|
||||||
// with a garbage lambda, so that we can then overwrite it
|
// with a garbage lambda, so that we can then overwrite it
|
||||||
// a recursive lambda
|
// a recursive lambda
|
||||||
std::function<Lisp_Object*(Lisp_Object*)> unquoteSomeExpressions; // = [] (Lisp_Object* expr) -> Lisp_Object* {return nullptr;};
|
std::function<Lisp_Object*(Lisp_Object*)> unquoteSomeExpressions; // = [] (Lisp_Object* expr) -> Lisp_Object* {return nullptr;};
|
||||||
unquoteSomeExpressions = [&unquoteSomeExpressions] (Lisp_Object* expr) -> Lisp_Object* {
|
unquoteSomeExpressions = [&] (Lisp_Object* expr) -> Lisp_Object* {
|
||||||
// if it is an atom, return it
|
// if it is an atom, return it
|
||||||
if (Memory::get_type(expr) != Lisp_Object_Type::Pair)
|
if (Memory::get_type(expr) != Lisp_Object_Type::Pair)
|
||||||
return Memory::copy_lisp_object(expr);
|
return Memory::copy_lisp_object(expr);
|
||||||
|
|||||||
+3
-2
@@ -22,8 +22,6 @@ proc find_binding_environment(Lisp_Object* sym, Environment* env) -> Environment
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* {
|
proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* {
|
||||||
static auto nil_sym = Memory::get_or_create_lisp_object_symbol("nil");
|
|
||||||
static auto t_sym = Memory::get_or_create_lisp_object_symbol("t");
|
|
||||||
// first check current environment
|
// first check current environment
|
||||||
Lisp_Object* result;
|
Lisp_Object* result;
|
||||||
result = lookup_symbol_in_this_envt(node, env);
|
result = lookup_symbol_in_this_envt(node, env);
|
||||||
@@ -37,6 +35,9 @@ proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto nil_sym = Memory::get_or_create_lisp_object_symbol("nil");
|
||||||
|
auto t_sym = Memory::get_or_create_lisp_object_symbol("t");
|
||||||
|
|
||||||
if (node == nil_sym) {
|
if (node == nil_sym) {
|
||||||
return Memory::nil;
|
return Memory::nil;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -329,9 +329,9 @@ proc print(Lisp_Object* node, bool print_repr = false, FILE* file = stdout) -> v
|
|||||||
|
|
||||||
|
|
||||||
auto symbol = head->value.pair.first;
|
auto symbol = head->value.pair.first;
|
||||||
static auto quote_sym = Memory::get_or_create_lisp_object_symbol("quote");
|
auto quote_sym = Memory::get_or_create_lisp_object_symbol("quote");
|
||||||
static auto unquote_sym = Memory::get_or_create_lisp_object_symbol("unquote");
|
auto unquote_sym = Memory::get_or_create_lisp_object_symbol("unquote");
|
||||||
static auto quasiquote_sym = Memory::get_or_create_lisp_object_symbol("quasiquote");
|
auto quasiquote_sym = Memory::get_or_create_lisp_object_symbol("quasiquote");
|
||||||
if (symbol == quote_sym || symbol == unquote_sym)
|
if (symbol == quote_sym || symbol == unquote_sym)
|
||||||
{
|
{
|
||||||
putc(symbol == quote_sym
|
putc(symbol == quote_sym
|
||||||
|
|||||||
+4
-1
@@ -644,7 +644,7 @@ proc run_all_tests() -> bool {
|
|||||||
|
|
||||||
printf("\n-- Test Files --\n");
|
printf("\n-- Test Files --\n");
|
||||||
|
|
||||||
invoke_test_script("sicp");
|
// print_environment(get_current_environment());
|
||||||
invoke_test_script("evaluation_of_default_args");
|
invoke_test_script("evaluation_of_default_args");
|
||||||
invoke_test_script("alists");
|
invoke_test_script("alists");
|
||||||
invoke_test_script("case_and_cond");
|
invoke_test_script("case_and_cond");
|
||||||
@@ -653,6 +653,9 @@ proc run_all_tests() -> bool {
|
|||||||
invoke_test_script("import_and_load");
|
invoke_test_script("import_and_load");
|
||||||
invoke_test_script("macro_expand");
|
invoke_test_script("macro_expand");
|
||||||
invoke_test_script("automata");
|
invoke_test_script("automata");
|
||||||
|
invoke_test_script("sicp");
|
||||||
|
|
||||||
|
// visualize_lisp_machine();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user