aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 15:04:31 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 15:04:31 +0000
commite3aad385a1de7798e359b9be453dd22b5c037eb1 (patch)
treee0958f4b71f67d447610cd4611e15929ef60ea1a /runtime/src
parentc9a490e81469b0722ee62c06f14cdd083cb8a9da (diff)
Add GC root stack
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/gc.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/runtime/src/gc.c b/runtime/src/gc.c
index 08c39cf9..42fc95f2 100644
--- a/runtime/src/gc.c
+++ b/runtime/src/gc.c
@@ -3,6 +3,17 @@
#include "./patio/patio.h"
#include "./alloc.h"
#include "./gc.h"
+#include "./primitives.h"
+
+// == GC objects ==
+
+bool is_gc_object(ShedObject object) {
+ // Check that the object is not one of:
+ // * unit (0)
+ // * false (0)
+ // * true (1)
+ return !(object == 0 || object == 1);
+}
// == Marking ==
@@ -50,3 +61,27 @@ void* shed__runtime__gc_alloc(size_t size, size_t children_offset, size_t childr
return object;
}
+// == Roots ==
+
+typedef size_t ShedGcRootStackIndex;
+
+ShedGcRootStackIndex gc_root_stack_index = 0;
+
+struct ShedGcObjectHeader* gc_root_stack[16384];
+
+ShedGcRootStackIndex shed__runtime__gc_get_root_stack_index() {
+ return gc_root_stack_index;
+}
+
+void shed__runtime__gc_set_root_stack_index(ShedGcRootStackIndex new_gc_root_stack_index) {
+ gc_root_stack_index = new_gc_root_stack_index;
+}
+
+void shed__runtime__gc_push_root(ShedObject gc_root) {
+ if (!is_gc_object(gc_root)) {
+ return;
+ }
+
+ gc_root_stack[gc_root_stack_index] = (struct ShedGcObjectHeader*) gc_root;
+ gc_root_stack_index++;
+}