aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
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
parentfeeb048fe9ab2e2d9f748a6028a8ca05d8a8eacf (diff)
Add mark for GC objects
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/gc.c18
-rw-r--r--runtime/src/gc.h3
2 files changed, 21 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;
+}
diff --git a/runtime/src/gc.h b/runtime/src/gc.h
index d7f5f9af..f8da17d3 100644
--- a/runtime/src/gc.h
+++ b/runtime/src/gc.h
@@ -1,8 +1,11 @@
#ifndef SHED_GC_H
#define SHED_GC_H
+#include "./patio/patio.h"
+
struct ShedGcObjectHeader {
struct ShedGcObjectHeader* next;
+ PatioInt mark;
};
#endif