From 2db7a2e86c27b99a616af80ae75920347c5e6cc0 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 14 Oct 2015 23:01:58 -0400 Subject: [PATCH] WIP --- include/cyclone/types.h | 2 +- runtime.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 4b55a1d6..92ff5ae7 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -68,7 +68,7 @@ gc_heap *gc_heap_last(gc_heap *h); size_t gc_heap_total_size(gc_heap *h); void gc_mark(gc_heap *h, object obj); size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr); -//void gc_collect(gc_heap *h, size_t *sum_freed) +void gc_collect(gc_heap *h, size_t *sum_freed); /* GC debugging flags */ //#define DEBUG_GC 0 diff --git a/runtime.c b/runtime.c index deb7260d..12f50bad 100644 --- a/runtime.c +++ b/runtime.c @@ -2345,6 +2345,27 @@ void Cyc_apply_from_buf(int argc, object prim, object *buf) { // longjmp(jmp_main,1); /* Return globals gc_cont, gc_ans. */ //} +// NEW GC algorithm +void gc_collect(gc_heap *h, size_t *sum_freed) +{ + printf("(heap: %p size: %d)\n", h, (unsigned int)gc_heap_total_size(h)); + // Mark global variables + gc_mark(h, Cyc_global_variables); /* Internal global used by the runtime */ + { + list l = global_table; + for(; !nullp(l); l = cdr(l)){ + cvar_type *c = (cvar_type *)car(l); + gc_mark(h, *(c->pvar)); // Mark global, not the pvar + } + } + // TODO: what else to mark? gc_mark( + // conservative mark? + // weak refs? + // finalize? + gc_sweep(h, sum_freed); + // debug print free stats + // return value from sweep?? +} void GC(cont,ans,num_ans) closure cont; object *ans; int num_ans; // TODO: take 'live' objects from the stack and allocate them on the heap /*