void gc_sweep(void) { object *obj = active_list; object *next, *prev; fprintf(stderr, "sweeping objects...\n"); dump_active_list(); while (obj != NULL && obj == active_list) { next = chain(obj); if (gc_active(obj)) { gc_clear(obj); } else if (gc_free(obj)) { dump_object(obj); active_list = chain(obj); chain(obj) = free_list; free_list = obj; } else { error("illegal state while gc"); } obj = next; } prev = active_list; while (obj != NULL) { next = chain(obj); if (gc_active(obj)) { gc_clear(obj); prev = obj; } else if (gc_free(obj)) { dump_object(obj); chain(prev) = next; chain(obj) = free_list; free_list = obj; } else { error("illegal state while gc"); } obj = next; } dump_active_list(); fprintf(stderr, "finished sweep\n"); }
static struct ymd_mach *setup() { struct ymd_mach *vm = ymd_init(); gc_active(vm, +1); return vm; }
static void teardown(struct ymd_mach *vm) { gc_active(vm, -1); ymd_final(vm); }