Add basic lexenv support
This commit is contained in:
+29
-1
@@ -161,7 +161,7 @@ static inline void add_local_refs_for_object_sub_vals(LispVal *seen_objs,
|
||||
break;
|
||||
}
|
||||
case TYPE_STRING:
|
||||
// ho held refs
|
||||
// no held refs
|
||||
break;
|
||||
case TYPE_FIXNUM:
|
||||
case TYPE_FLOAT:
|
||||
@@ -190,3 +190,31 @@ void compact_stack_frame(struct StackFrame *restrict frame) {
|
||||
lisp_realloc(refs->blocks, sizeof(struct LocalReferencesBlock *));
|
||||
refs->num_blocks = 1;
|
||||
}
|
||||
|
||||
bool set_lexical_variable(LispVal *name, LispVal *value,
|
||||
bool create_if_absent) {
|
||||
assert(the_stack.depth != 0);
|
||||
DOTAILS(rest, LISP_STACK_TOP()->lexenv) {
|
||||
if (EQ(XCAR(rest), name)) {
|
||||
RPLACA(XCDR(rest), value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (create_if_absent) {
|
||||
new_lexical_variable(name, value);
|
||||
}
|
||||
return create_if_absent;
|
||||
}
|
||||
|
||||
void new_lexical_variable(LispVal *name, LispVal *value) {
|
||||
assert(the_stack.depth != 0);
|
||||
LISP_STACK_TOP()->lexenv =
|
||||
CONS(name, CONS(value, LISP_STACK_TOP()->lexenv));
|
||||
}
|
||||
|
||||
void copy_parent_lexenv(void) {
|
||||
assert(the_stack.depth != 0);
|
||||
if (the_stack.depth > 1) {
|
||||
LISP_STACK_TOP()->lexenv = the_stack.frames[the_stack.depth - 2].lexenv;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user