From: Michael D. Lowis Date: Tue, 17 Jul 2018 19:49:15 +0000 (-0400) Subject: added a default main function to runtime to store off the stack bottom X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=995a7142a0cc95affba7a6f46d0092ccb36fcd1f;p=proto%2Fsclpl.git added a default main function to runtime to store off the stack bottom --- diff --git a/source/rt/gc.c b/source/rt/gc.c index abf50fe..c4f0b9a 100644 --- a/source/rt/gc.c +++ b/source/rt/gc.c @@ -18,12 +18,8 @@ typedef struct { void* val; /* pointer to the original cell value */ } entry_t; -size_t EntryCount; -entry_t EntryLog[NENTRIES]; - -void gc_init(void* stkbtm) { - EntryCount = 0; -} +size_t EntryCount = 0; +entry_t EntryLog[NENTRIES] = {0}; void gc_collect(void) { @@ -34,6 +30,10 @@ void* gc_alloc(size_t sz, void (*dtor)(void*)) { if (obj) { obj->dtor = dtor; obj->refs = 0u; + EntryLog[EntryCount].ref = NULL; + EntryLog[EntryCount].val = obj->data; + if (++EntryCount == NENTRIES) + gc_collect(); } else { perror("refcreate() failed :"); abort(); @@ -58,5 +58,3 @@ void gc_setref(void** ref, void* val) { void* gc_getref(void** ref) { return (void*)((uintptr_t)*ref & ~DIRTY_BIT); } - - diff --git a/source/rt/main.c b/source/rt/main.c new file mode 100644 index 0000000..fbb53ce --- /dev/null +++ b/source/rt/main.c @@ -0,0 +1,9 @@ +#include + +uintptr_t* StackBot; + +int main(int argc, char** argv) { + { StackBot = (uintptr_t*)&(int){0}; } + extern int usermain(int argc, char** argv); + return usermain(argc, argv); +}