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 ++++++++++++++++++ runtime/src/gc.h | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 runtime/src/gc.c (limited to 'runtime/src') 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; +} 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 -- cgit v1.2.3