WIP, integrating directly with cyclone

This commit is contained in:
Justin Ethier 2015-10-14 22:48:38 -04:00
parent 057c40eba8
commit 3a68ce5a32

53
gc.c
View file

@ -1,4 +1,4 @@
/* TODO: a basic mark-sweep GC /* A basic mark-sweep GC
As of now, the GC code is based off the implementation from chibi scheme As of now, the GC code is based off the implementation from chibi scheme
Goals of this project: Goals of this project:
@ -146,23 +146,45 @@ void gc_mark(gc_heap *h, object obj)
return; return;
#if GC_DEBUG_PRINTFS #if GC_DEBUG_PRINTFS
fprintf(stdout, "gc_mark %p\n", obj); fprintf(stdout, "gc_mark %p\n", obj);
#endif #endif
((list)obj)->hdr.mark = 1; ((list)obj)->hdr.mark = 1;
// TODO: mark heap saves (??) // TODO: mark heap saves (??)
// could this be a write barrier? // could this be a write barrier?
// Mark objects this one references // Mark objects this one references
if (type_of(obj) == cons_tag) { if (type_of(obj) == cons_tag) {
gc_mark(h, car(obj)); gc_mark(h, car(obj));
gc_mark(h, cdr(obj)); gc_mark(h, cdr(obj));
} } else if (type_of(obj) == closure1_tag) {
// TODO: will be more work in here the "real" implementation gc_mark(h, ((closure1) obj)->elt1);
} else if (type_of(obj) == closure2_tag) {
gc_mark(h, ((closure2) obj)->elt1);
gc_mark(h, ((closure2) obj)->elt2);
} else if (type_of(obj) == closure3_tag) {
gc_mark(h, ((closure3) obj)->elt1);
gc_mark(h, ((closure3) obj)->elt2);
gc_mark(h, ((closure3) obj)->elt3);
} else if (type_of(obj) == closure4_tag) {
gc_mark(h, ((closure4) obj)->elt1);
gc_mark(h, ((closure4) obj)->elt2);
gc_mark(h, ((closure4) obj)->elt3);
gc_mark(h, ((closure4) obj)->elt4);
} else if (type_of(obj) == closureN_tag) {
int i, n = ((closureN) obj)->num_elt;
for (i = 0; i < n; i++) {
gc_mark(h, ((closureN) obj)->elts[i]);
}
} else if (type_of(obj) == vector_tag) {
int i, n = ((vector) obj)->num_elt;
for (i = 0; i < n; i++) {
gc_mark(h, ((vector) obj)->elts[i]);
}
}
} }
size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr) size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr)
{ {
// TODO: scan entire heap, freeing objects that have not been marked
size_t freed, max_freed=0, sum_freed=0, size; size_t freed, max_freed=0, sum_freed=0, size;
object p, end; object p, end;
gc_free_list *q, *r, *s; gc_free_list *q, *r, *s;
@ -240,19 +262,6 @@ size_t gc_sweep(gc_heap *h, size_t *sum_freed_ptr)
return max_freed; return max_freed;
} }
void gc_collect(gc_heap *h, size_t *sum_freed)
{
printf("(heap: %p size: %d)\n", h, (unsigned int)gc_heap_total_size(h));
// TODO: mark globals
// TODO: gc_mark(h, h);
// conservative mark?
// weak refs?
// finalize?
gc_sweep(h, sum_freed);
// debug print free stats
// return value from sweep??
}
// void gc_init() // void gc_init()
// { // {
// } // }