aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/gc.c
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 14:39:10 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 14:39:38 +0000
commit9bbc9fb8a4666e7c084f56916e993cb07ea4dabd (patch)
treea9dbe1af76ab00821c6a9972effdec9492c087ba /runtime/src/gc.c
parentfeeb048fe9ab2e2d9f748a6028a8ca05d8a8eacf (diff)
Add mark for GC objects
Diffstat (limited to 'runtime/src/gc.c')
-rw-r--r--runtime/src/gc.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/runtime/src/gc.c b/runtime/src/gc.c
new file mode 100644
index 00000000..5c485b26
--- /dev/null
+++ b/runtime/src/gc.c
@@ -0,0 +1,18 @@
+#include <stdbool.h>
+
+#include "./patio/patio.h"
+#include "./gc.h"
+
+// The mark value for each object is initialized to 0. Each mark phase
+// alternates between using 0b010 and 0b100 as the mark value. We check only for
+// the bit set to 1, meaning static values can have a mark value of 0b110 to be
+// considered always marked.
+PatioInt current_mark_value = 0b010;
+
+void alternate_mark_value() {
+ current_mark_value ^= 0b110;
+}
+
+bool is_marked(struct ShedGcObjectHeader* object) {
+ return (object->mark & current_mark_value) == current_mark_value;
+}