|
|
|
@@ -8,7 +8,7 @@ proc define_symbol(Lisp_Object* symbol, Lisp_Object* value) -> void { |
|
|
|
|
|
|
|
if (env->next_index == env->capacity) { |
|
|
|
env->capacity *= 2; |
|
|
|
env->keys = (char**)realloc(env->keys, env->capacity * sizeof(char*)); |
|
|
|
env->keys = (char**)realloc(env->keys, env->capacity * sizeof(char*)); |
|
|
|
env->values = (Lisp_Object**)realloc(env->values, env->capacity * sizeof(Lisp_Object*)); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -24,6 +24,20 @@ proc lookup_symbol_in_this_envt(String* identifier, Environment* env) -> Lisp_Ob |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
proc environment_binds_symbol(String* identifier, Environment* env) -> bool { |
|
|
|
return lookup_symbol_in_this_envt(identifier, env) != nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
proc find_binding_environment(String* identifier, Environment* env) -> Environment* { |
|
|
|
if (environment_binds_symbol(identifier, env)) |
|
|
|
return env; |
|
|
|
for (int i = 0; i < env->parents->next_index; ++i) { |
|
|
|
if (environment_binds_symbol(identifier, env->parents->data[i])) |
|
|
|
return env->parents->data[i]; |
|
|
|
} |
|
|
|
return get_root_environment(); |
|
|
|
} |
|
|
|
|
|
|
|
proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* { |
|
|
|
// first check current environment |
|
|
|
String* identifier = node->value.symbol.identifier; |
|
|
|
|