Added gc_move, but still need to build it out

This commit is contained in:
Justin Ethier 2015-10-15 22:52:38 -04:00
parent 3363bf477d
commit d7640c988b
2 changed files with 28 additions and 1 deletions

View file

@ -13,6 +13,7 @@
long global_stack_size = 0;
long global_heap_size = 0;
gc_heap *Cyc_heap;
static void c_entry_pt(int,closure,closure);
static void Cyc_main(long stack_size,long heap_size,char *stack_base);
@ -56,6 +57,10 @@ static void Cyc_main (stack_size,heap_size,stack_base)
#if DEBUG_SHOW_DIAG
printf("main: Allocating and initializing heap...\n");
#endif
Cyc_heap = gc_heap_create(heap_size, 0);
// JAE TODO: clean up below (and all of this old code, really)
bottom = calloc(1,heap_size);
allocp = (char *) ((((long) bottom)+7) & -8);
alloc_end = allocp + heap_size - 8;

View file

@ -2375,11 +2375,33 @@ void gc_collect(gc_heap *h, size_t *sum_freed)
// TODO: move globals to thread-specific structures.
// for example - gc_cont, gc_ans, gc_num_ans
char *gc_move(char *obj) {
if (!is_object_type(obj)) return obj;
switch(type_of(obj)){
case cons_tag: {
list hobj = gc_alloc(Cyc_heap, sizeof(cons_type));
hobj->hdr.mark = 0;
type_of(hobj) = cons_tag;
car(hobj) = car(obj);
cdr(hobj) = cdr(hobj);
forward(obj) = hobj;
type_of(obj) = forward_tag;
// TODO: add hobj to bump pointer, so we can scan/move the whole live object 'tree'
// will require we pass the 'bump' space to this function,
// and will require us to check somewhere for overflow of this space, and
// realloc/expand it if necessary
return (char *)hobj;
}
// TODO: other types
}
}
#define gc_move2heap(obj) { \
temp = obj; \
if (check_overflow(low_limit, temp) && \
check_overflow(temp, high_limit)){ \
(obj) = TODO: allocate on heap, return new address, replace old w/fwd ptr \
(obj) = (object) gc_move(temp); \
} \
}