|
|
@@ -1,21 +1,21 @@ |
|
|
proc define_symbol(Lisp_Object* symbol, Lisp_Object* value) -> void { |
|
|
proc define_symbol(Lisp_Object* symbol, Lisp_Object* value) -> void { |
|
|
Environment* env = get_current_environment(); |
|
|
Environment* env = get_current_environment(); |
|
|
hm_set(env->hm, Memory::get_c_str(symbol->value.symbol.identifier), value); |
|
|
|
|
|
|
|
|
hm_set(env->hm, symbol, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
inline proc lookup_symbol_in_this_envt(String* identifier, Environment* env) -> Lisp_Object* { |
|
|
|
|
|
return (Lisp_Object*)hm_get_object(env->hm, Memory::get_c_str(identifier)); |
|
|
|
|
|
|
|
|
inline proc lookup_symbol_in_this_envt(Lisp_Object* sym, Environment* env) -> Lisp_Object* { |
|
|
|
|
|
return (Lisp_Object*)hm_get_object(env->hm, sym); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
proc environment_binds_symbol(String* identifier, Environment* env) -> bool { |
|
|
|
|
|
return lookup_symbol_in_this_envt(identifier, env) != nullptr; |
|
|
|
|
|
|
|
|
proc environment_binds_symbol(Lisp_Object* sym, Environment* env) -> bool { |
|
|
|
|
|
return lookup_symbol_in_this_envt(sym, env) != nullptr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
proc find_binding_environment(String* identifier, Environment* env) -> Environment* { |
|
|
|
|
|
if (environment_binds_symbol(identifier, env)) |
|
|
|
|
|
|
|
|
proc find_binding_environment(Lisp_Object* sym, Environment* env) -> Environment* { |
|
|
|
|
|
if (environment_binds_symbol(sym, env)) |
|
|
return env; |
|
|
return env; |
|
|
for (int i = 0; i < env->parents.next_index; ++i) { |
|
|
for (int i = 0; i < env->parents.next_index; ++i) { |
|
|
if (environment_binds_symbol(identifier, env->parents.data[i])) |
|
|
|
|
|
|
|
|
if (environment_binds_symbol(sym, env->parents.data[i])) |
|
|
return env->parents.data[i]; |
|
|
return env->parents.data[i]; |
|
|
} |
|
|
} |
|
|
return get_root_environment(); |
|
|
return get_root_environment(); |
|
|
@@ -25,9 +25,8 @@ 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 nil_sym = Memory::get_or_create_lisp_object_symbol("nil"); |
|
|
static auto t_sym = Memory::get_or_create_lisp_object_symbol("t"); |
|
|
static auto t_sym = Memory::get_or_create_lisp_object_symbol("t"); |
|
|
// first check current environment |
|
|
// first check current environment |
|
|
String* identifier = node->value.symbol.identifier; |
|
|
|
|
|
Lisp_Object* result; |
|
|
Lisp_Object* result; |
|
|
result = lookup_symbol_in_this_envt(identifier, env); |
|
|
|
|
|
|
|
|
result = lookup_symbol_in_this_envt(node, env); |
|
|
if (result) |
|
|
if (result) |
|
|
return result; |
|
|
return result; |
|
|
|
|
|
|
|
|
@@ -98,9 +97,9 @@ proc print_environment_indent(Environment* env, int indent) -> void { |
|
|
// return; |
|
|
// return; |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
for_str_hash_map (env->hm) { |
|
|
|
|
|
|
|
|
for_ptr_hash_map (env->hm) { |
|
|
print_indent(indent); |
|
|
print_indent(indent); |
|
|
printf("-> %s :: ", key); |
|
|
|
|
|
|
|
|
printf("-> %s :: ", &(((Lisp_Object*)key)->value.symbol.identifier->data)); |
|
|
print((Lisp_Object*)value); |
|
|
print((Lisp_Object*)value); |
|
|
printf(" (%lld)", (unsigned long long)value); |
|
|
printf(" (%lld)", (unsigned long long)value); |
|
|
puts(""); |
|
|
puts(""); |
|
|
|