Environment HM now map from ptr to ptr because syms are unique
This commit is contained in:
+1
-1
@@ -537,7 +537,7 @@ proc load_built_ins_into_environment() -> void {
|
||||
Environment* target_env;
|
||||
in_caller_env {
|
||||
val = eval_expr(val);
|
||||
target_env = find_binding_environment(sym->value.symbol.identifier, get_current_environment());
|
||||
target_env = find_binding_environment(sym, get_current_environment());
|
||||
try assert(target_env);
|
||||
}
|
||||
|
||||
|
||||
+11
-12
@@ -1,21 +1,21 @@
|
||||
proc define_symbol(Lisp_Object* symbol, Lisp_Object* value) -> void {
|
||||
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;
|
||||
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 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 t_sym = Memory::get_or_create_lisp_object_symbol("t");
|
||||
// first check current environment
|
||||
String* identifier = node->value.symbol.identifier;
|
||||
Lisp_Object* result;
|
||||
result = lookup_symbol_in_this_envt(identifier, env);
|
||||
result = lookup_symbol_in_this_envt(node, env);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
@@ -98,9 +97,9 @@ proc print_environment_indent(Environment* env, int indent) -> void {
|
||||
// return;
|
||||
// }
|
||||
|
||||
for_str_hash_map (env->hm) {
|
||||
for_ptr_hash_map (env->hm) {
|
||||
print_indent(indent);
|
||||
printf("-> %s :: ", key);
|
||||
printf("-> %s :: ", &(((Lisp_Object*)key)->value.symbol.identifier->data));
|
||||
print((Lisp_Object*)value);
|
||||
printf(" (%lld)", (unsigned long long)value);
|
||||
puts("");
|
||||
|
||||
+1
-1
@@ -412,7 +412,7 @@ namespace Memory {
|
||||
if (parent)
|
||||
append_to_array_list(&env->parents, parent);
|
||||
|
||||
env->hm = create_String_hashmap();
|
||||
env->hm = create_Void_Ptr_hashmap();
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
+1
-7
@@ -140,13 +140,7 @@ struct Arguments {
|
||||
|
||||
struct Environment {
|
||||
Environment_Array_List parents;
|
||||
String_Hash_Map* hm;
|
||||
// int capacity;
|
||||
// int next_index;
|
||||
|
||||
// // TODO(Felix): Use a hashmap here.
|
||||
// char** keys;
|
||||
// Lisp_Object** values;
|
||||
Void_Ptr_Hash_Map* hm;
|
||||
};
|
||||
|
||||
struct Function {
|
||||
|
||||
Reference in New Issue
Block a user