first evaluator draft
This commit is contained in:
parent
9fc5f10fc6
commit
2532dd9f4a
8 changed files with 399 additions and 43 deletions
20
gc.c
20
gc.c
|
|
@ -8,10 +8,6 @@
|
|||
|
||||
E heap;
|
||||
|
||||
#define ALIGN(n) (((n) + 7) & ~7)
|
||||
#define INFROM(x) \
|
||||
(((const U8 *)x) >= heap.from.start && ((const U8 *)x) < heap.from.end)
|
||||
|
||||
// roots management
|
||||
void addroot(O *ptr) {
|
||||
if (heap.root_count >= heap.root_capacity) {
|
||||
|
|
@ -48,6 +44,8 @@ static O forward(O obj, U8 **freep) {
|
|||
return NIL;
|
||||
if (IMM(obj))
|
||||
return obj;
|
||||
if (TYPE(obj) != TAG_GC)
|
||||
return obj;
|
||||
|
||||
H *h = UNBOX(obj);
|
||||
if (!INFROM(h))
|
||||
|
|
@ -62,6 +60,8 @@ static O forward(O obj, U8 **freep) {
|
|||
}
|
||||
|
||||
void collect(void) {
|
||||
return; // DEBUG
|
||||
|
||||
U8 *freep = heap.to.start;
|
||||
U8 *scan = freep;
|
||||
|
||||
|
|
@ -75,12 +75,10 @@ void collect(void) {
|
|||
switch (h->type) {
|
||||
case OBJ_CONS: {
|
||||
C *c = (C *)(h + 1);
|
||||
c->head = forward(c->head, &freep);
|
||||
c->tail = forward(c->tail, &freep);
|
||||
c->car = forward(c->car, &freep);
|
||||
c->cdr = forward(c->cdr, &freep);
|
||||
break;
|
||||
}
|
||||
case OBJ_SYM:
|
||||
break;
|
||||
case OBJ_FWD:
|
||||
fprintf(stderr, "gc internal error: forwarding pointer in to-space\n");
|
||||
abort();
|
||||
|
|
@ -122,12 +120,14 @@ H *alloc(Z sz) {
|
|||
|
||||
void gcinit(void) {
|
||||
heap.from.start = malloc(GC_HEAP_BYTES);
|
||||
if (!heap.from.start) abort();
|
||||
if (!heap.from.start)
|
||||
abort();
|
||||
heap.from.free = heap.from.start;
|
||||
heap.from.end = heap.from.start + GC_HEAP_BYTES;
|
||||
|
||||
heap.to.start = malloc(GC_HEAP_BYTES);
|
||||
if (!heap.to.start) abort();
|
||||
if (!heap.to.start)
|
||||
abort();
|
||||
heap.to.free = heap.to.start;
|
||||
heap.to.end = heap.to.start + GC_HEAP_BYTES;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue