Rewrite the stack

This commit is contained in:
2026-07-18 22:31:01 -07:00
parent 891e5359bf
commit bd7ca2fa25
9 changed files with 343 additions and 200 deletions
+24 -13
View File
@@ -285,13 +285,30 @@ static void mark_stack_local_refs(struct LocalReferences *restrict refs,
saturating_dec(limit, refs->num_refs);
}
static void mark_stack_frame(struct StackFrame *frame, size_t *restrict limit) {
mark_object(frame->name);
mark_object(frame->args);
mark_object(frame->fobj);
mark_object(frame->lexenv);
saturating_dec(limit, 4);
mark_stack_local_refs(&frame->local_refs, limit);
static void mark_stack_frame(StackFrame *frame, size_t *restrict limit) {
switch (frame->kind) {
case STACK_FRAME_LOCAL_REFERENCES:
mark_stack_local_refs(&frame->local_references, limit);
break;
case STACK_FRAME_CALL:
mark_object(frame->call.name);
mark_object(frame->call.args);
mark_object(frame->call.fobj);
saturating_dec(limit, 3);
break;
case STACK_FRAME_UNWIND_PROTECT:
// nothing to do
break;
case STACK_FRAME_CONDITION_CASE:
mark_object(frame->condition_case.exceptions);
saturating_dec(limit, 1);
break;
case STACK_FRAME_DYNAMIC_BINDING:
mark_object(frame->dynamic_binding.symbol);
mark_object(frame->dynamic_binding.old_value);
saturating_dec(limit, 2);
break;
}
}
static void mark_and_compact_the_stack(size_t *restrict limit) {
@@ -306,11 +323,6 @@ static void mark_and_compact_the_stack(size_t *restrict limit) {
}
}
if (i == the_stack.depth) {
for (; i < the_stack.first_clear_local_refs; ++i) {
compact_stack_frame(&the_stack.frames[i]);
}
the_stack.first_clear_local_refs = the_stack.depth;
// move to the next step
incremental_state.step = GC_STEP_HEAP;
}
}
@@ -402,7 +414,6 @@ void lisp_gc_yield(struct timespec *restrict time_took, bool full) {
}
void lisp_gc_teardown(void) {
assert(the_stack.depth == 0);
while (white_objects) {
free_object(white_objects->obj);
}