From a107593b6b362fb68e409c9d7b79427776d137d7 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 1 Sep 2026 20:59:47 -0400 Subject: pit: Tail call optimization! --- pit/src/runtime/gc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pit/src/runtime/gc.c') diff --git a/pit/src/runtime/gc.c b/pit/src/runtime/gc.c index 1cc6547..e96e36b 100644 --- a/pit/src/runtime/gc.c +++ b/pit/src/runtime/gc.c @@ -27,7 +27,9 @@ static pit_value gc_copy_value(pit_runtime *rt, pit_value v) { return v; } } +// #include void pit_gc(pit_runtime *rt) { + // fprintf(stderr, "running gc: heap size is %ld\n", rt->heap->next); rt->frozen_values = 0; rt->frozen_symtab = 0; pit_arena *fromspace = rt->heap; @@ -60,6 +62,11 @@ void pit_gc(pit_runtime *rt) { pit_value *v = pit_vec_get(pit_value)(rt->saved_bindings, i); if (v != NULL) *v = gc_copy_value(rt, *v); /* TODO warn on failure here? */ } + /* the evaluation stack is reachable */ + for (i64 i = 0; i < rt->result_stack->next; ++i) { + pit_value *v = pit_vec_get(pit_value)(rt->result_stack, i); + if (v != NULL) *v = gc_copy_value(rt, *v); /* TODO warn on failure here? */ + } /* recursively populate all reachable values from that initial set */ for (i64 scan = 0; scan < tospace->next; ++scan) { pit_value_heavy *h = pit_arena_get(tospace, scan); @@ -106,4 +113,5 @@ void pit_gc(pit_runtime *rt) { rt->annotations = tospace_ann; rt->annotations_backbuffer = fromspace_ann; pit_hashtable_reset(pit_ref, pit_annotation)(rt->annotations_backbuffer); + // fprintf(stderr, "done! heap size is %ld\n", rt->heap->next); } -- cgit v1.3.1