]> git.mdlowis.com Git - archive/atc.git/commitdiff
Started rough implementation of the gc layer
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 2 Apr 2015 02:04:49 +0000 (22:04 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 2 Apr 2015 02:04:49 +0000 (22:04 -0400)
source/runtime/gc.c

index 541d26b453431d257491e20eb670028cde83d06e..49e1410bffada54c763ef60a7da5ced5372ad3a0 100644 (file)
@@ -1,28 +1,21 @@
 #include "gc.h"
-#include <stdlib.h>
-
-/*****************************************************************************/
+#include "heap.h"
 
 typedef struct {
     uint64_t objmap;
     uint8_t data[];
 } obj_t;
 
+static heap_t* heap = NULL;
+
 void gc_init(void* stack_bottom)
 {
+    heap = heap_create();
 }
 
 void* gc_alloc(uint64_t objmap, size_t num_slots)
 {
-    obj_t* obj;
-    if (num_slots <= (sizeof(uint64_t) - 1u)) {
-        obj = (void*)malloc(sizeof(obj_t) + (num_slots * sizeof(uintptr_t)));
-    } else {
-        obj = (void*)malloc(sizeof(obj_t) + (num_slots * sizeof(uintptr_t)));
-    }
-    obj->objmap = objmap;
-    obj++;
-    return (void*)obj;
+    return heap_allocate(heap, num_slots+1);
 }
 
 void gc_collect(void)
@@ -31,6 +24,7 @@ void gc_collect(void)
 
 void gc_shutdown(void)
 {
+    heap_destroy(heap);
 }
 
 /*****************************************************************************/