From 9e74f13c0ffca475fd834f0a1967050b94de55c6 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 1 Apr 2015 22:04:49 -0400 Subject: [PATCH] Started rough implementation of the gc layer --- source/runtime/gc.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) 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); } /*****************************************************************************/ -- 2.54.0