]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added a default main function to runtime to store off the stack bottom
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 17 Jul 2018 19:49:15 +0000 (15:49 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 17 Jul 2018 19:49:15 +0000 (15:49 -0400)
source/rt/gc.c
source/rt/main.c [new file with mode: 0644]

index abf50fef54b111fa48e1dd7d9638812f84f397ac..c4f0b9a323f5efd22b155b9c4d1d33c64606a073 100644 (file)
@@ -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 (file)
index 0000000..fbb53ce
--- /dev/null
@@ -0,0 +1,9 @@
+#include <stdint.h>
+
+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);
+}