#include "../../../patio/patio.h" #include "../../gc.h" #include "../../memory.h" #define MAX(a,b) (((a)>(b))?(a):(b)) void* ptr = NULL; intptr_t remaining = 0; // == Initialization == void shed__runtime__gc_init(void) { ptr = shed__runtime__memory_init(sizeof(PatioInt)); } // == Allocation == void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) { if (size % sizeof(PatioInt) != 0) { size = size + (sizeof(PatioInt) - size % sizeof(PatioInt)); } if (remaining < size) { // TODO: what should we grow by? intptr_t increment = MAX(1024 * 1024, size); // TODO: check for -1 from shed__runtime__memory_grow // TODO: shed__runtime__memory_grow may grow by more than requested amount. // Return the amount of allocated memory? shed__runtime__memory_grow(increment); remaining += increment; } struct ShedGcObjectHeader* object = ptr; ptr += size; remaining -= size; object->runtime_type_tag = runtime_type_tag; return object; } // == Collection == void shed__runtime__gc_collect(void) { } // == Clearing == void shed__runtime__gc_clear(void) { shed__runtime__gc_clear_roots(); }