work on generic extend
This commit is contained in:
+19
-1
@@ -366,6 +366,18 @@ proc load_built_ins_into_environment() -> void {
|
||||
|
||||
return Memory::create_lisp_object_number(x);
|
||||
};
|
||||
define_special((bound? var), "TODO") {
|
||||
fetch(var);
|
||||
try assert_type(var, Lisp_Object_Type::Symbol);
|
||||
|
||||
Lisp_Object* res;
|
||||
in_caller_env {
|
||||
res = try_lookup_symbol(var, get_current_environment());
|
||||
}
|
||||
if (res)
|
||||
return Memory::t;
|
||||
return Memory::nil;
|
||||
};
|
||||
define((assert test), "TODO") {
|
||||
fetch(test);
|
||||
|
||||
@@ -541,12 +553,18 @@ proc load_built_ins_into_environment() -> void {
|
||||
in_caller_env {
|
||||
val = eval_expr(val);
|
||||
target_env = find_binding_environment(sym, get_current_environment());
|
||||
try assert(target_env);
|
||||
if (!target_env)
|
||||
target_env = get_root_environment();
|
||||
}
|
||||
|
||||
|
||||
push_environment(target_env);
|
||||
{
|
||||
printf("set!ing:: ");
|
||||
print(sym);
|
||||
printf(" to ");
|
||||
print(val);
|
||||
printf(" in %llu\n", (unsigned long long) target_env);
|
||||
define_symbol(sym, val);
|
||||
}
|
||||
pop_environment();
|
||||
|
||||
+5
-5
@@ -14,11 +14,11 @@ proc environment_binds_symbol(Lisp_Object* sym, Environment* env) -> bool {
|
||||
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(sym, env->parents.data[i]))
|
||||
return env->parents.data[i];
|
||||
for_array_list (env->parents) {
|
||||
if (Environment* ret = find_binding_environment(sym, it))
|
||||
return it;
|
||||
}
|
||||
return get_root_environment();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* {
|
||||
@@ -34,7 +34,7 @@ proc try_lookup_symbol(Lisp_Object* node, Environment* env) -> Lisp_Object* {
|
||||
if (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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user