From: Michael D. Lowis Date: Thu, 2 Apr 2015 02:04:49 +0000 (-0400) Subject: Started rough implementation of the gc layer X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=9e74f13c0ffca475fd834f0a1967050b94de55c6;p=archive%2Fatc.git Started rough implementation of the gc layer --- diff --git a/source/runtime/gc.c b/source/runtime/gc.c index 541d26b..49e1410 100644 --- a/source/runtime/gc.c +++ b/source/runtime/gc.c @@ -1,28 +1,21 @@ #include "gc.h" -#include - -/*****************************************************************************/ +#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); } /*****************************************************************************/