store Value* as gc roots

This commit is contained in:
dzaima 2021-11-28 21:56:01 +02:00
parent 94e38e7162
commit 4af5f3d4a6
2 changed files with 5 additions and 4 deletions

View File

@ -638,7 +638,7 @@ B import_c2(B d, B w, B x) {
// defined in fns.c
i32 getPrevImport(B path);
i32 setPrevImport(B path, i32 pos);
void setPrevImport(B path, i32 pos);
static B importKeyList; // exists for GC roots as the hashmap doesn't
static B importValList;

View File

@ -9,11 +9,12 @@ void gc_addFn(vfn f) {
gc_roots[gc_rootSz++] = f;
}
B gc_rootObjs[256];
Value* gc_rootObjs[256];
u32 gc_rootObjSz;
void gc_add(B x) {
assert(isVal(x));
if (gc_rootObjSz>=256) err("Too many GC root objects");
gc_rootObjs[gc_rootObjSz++] = x;
gc_rootObjs[gc_rootObjSz++] = v(x);
}
@ -53,7 +54,7 @@ static void gc_resetTag(Value* x) {
void gc_visitRoots() {
for (u32 i = 0; i < gc_rootSz; i++) gc_roots[i]();
for (u32 i = 0; i < gc_rootObjSz; i++) mm_visit(gc_rootObjs[i]);
for (u32 i = 0; i < gc_rootObjSz; i++) mm_visitP(gc_rootObjs[i]);
}
u64 gc_lastAlloc;
void gc_forceGC() {