From 9bbc9fb8a4666e7c084f56916e993cb07ea4dabd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 16 Dec 2023 14:39:10 +0000 Subject: Add mark for GC objects --- runtime/src/gc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 runtime/src/gc.c (limited to 'runtime/src/gc.c') 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 + +#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; +} -- cgit v1.2.3