From 2311c52ebf6c6dc8269c40a2cdba583520dd987b Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Mon, 19 Jul 2021 12:28:40 +0200 Subject: [PATCH] remove old gc code --- source/fs/menus/filemenu.c | 3 - source/script/ABadIdeaVersion3.c | 3 - source/script/garbageCollector.c | 116 +------------------------------ source/script/garbageCollector.h | 4 -- 4 files changed, 1 insertion(+), 125 deletions(-) diff --git a/source/fs/menus/filemenu.c b/source/fs/menus/filemenu.c index 0beff1a..34aba6b 100644 --- a/source/fs/menus/filemenu.c +++ b/source/fs/menus/filemenu.c @@ -98,8 +98,6 @@ void RunScript(char *path, FSEntry_t entry){ lexarVectorClear(&ctx.script); */ - gfx_printf("Init gc\n"); - initGarbageCollector(); gfx_printf("Parsing\n"); ParserRet_t ret = parseScript(script, size); free(script); @@ -111,7 +109,6 @@ void RunScript(char *path, FSEntry_t entry){ Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1); exitRuntimeVars(); - exitGarbageCollector(); exitStaticVars(&ret.staticVarHolder); exitFunction(ret.main.operations.data, ret.main.operations.count); vecFree(ret.staticVarHolder); diff --git a/source/script/ABadIdeaVersion3.c b/source/script/ABadIdeaVersion3.c index 5e0a4e0..5da3b17 100644 --- a/source/script/ABadIdeaVersion3.c +++ b/source/script/ABadIdeaVersion3.c @@ -62,8 +62,6 @@ int main() return; */ - - initGarbageCollector(); char* script = readFile("input.te"); if (script == NULL) @@ -80,7 +78,6 @@ int main() Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1); exitRuntimeVars(); - exitGarbageCollector(); exitStaticVars(&ret.staticVarHolder); exitFunction(ret.main.operations.data, ret.main.operations.count); vecFree(ret.staticVarHolder); diff --git a/source/script/garbageCollector.c b/source/script/garbageCollector.c index 0eaca3b..11bd98e 100644 --- a/source/script/garbageCollector.c +++ b/source/script/garbageCollector.c @@ -3,23 +3,6 @@ #include "compat.h" #include "garbageCollector.h" -typedef struct { - Variable_t* ref; - u16 refCount; -} ReferenceCounter_t; - -Vector_t pendingAdd = { 0 }; -Vector_t pendingRemove = { 0 }; -Vector_t storedReferences = { 0 }; - -void initGarbageCollector() { - pendingAdd = newVec(sizeof(Variable_t*), 4); - pendingRemove = newVec(sizeof(Variable_t*), 4); - storedReferences = newVec(sizeof(ReferenceCounter_t), 8); -} - -// TODO: create binary tree for this! - void modReference(Variable_t* ref, u8 add) { if (ref == NULL || ref->gcDoNotFree) return; @@ -30,6 +13,7 @@ void modReference(Variable_t* ref, u8 add) { else { ref->tagCount--; if (ref->tagCount <= 0) { + // TODO: move to parser.c if (ref->variableType == FunctionClass && ref->function.builtIn && ref->function.origin != NULL) modReference(ref->function.origin, 0); @@ -39,102 +23,4 @@ void modReference(Variable_t* ref, u8 add) { freeVariable(&ref); } } - - /* - ReferenceCounter_t* additionalFree = NULL; - - vecForEach(ReferenceCounter_t*, references, (&storedReferences)) { - if (!add && ( - (ref->variableType == FunctionClass && ref->function.builtIn && references->ref == ref->function.origin) || - (ref->variableType == SolvedArrayReferenceClass && references->ref == ref->solvedArray.arrayClassReference))) - if (--references->refCount <= 0) { - additionalFree = references; - continue; - } - - if (references->ref == ref) { - if (add) - references->refCount++; - else { - if (--references->refCount <= 0) { - freeVariable(&references->ref); - vecRem(&storedReferences, ((u8*)references - (u8*)storedReferences.data) / storedReferences.elemSz); - - if (additionalFree != NULL) { - freeVariable(&additionalFree->ref); - vecRem(&storedReferences, ((u8*)additionalFree - (u8*)storedReferences.data) / storedReferences.elemSz); - } - } - } - - return; - } - } - - if (!add) - return; - - ReferenceCounter_t r = { .ref = ref, .refCount = 1 }; - vecAdd(&storedReferences, r); - */ -} -/* -void addPendingReference(Variable_t* ref) { - if (ref == NULL || ref->gcDoNotFree) - return; - - //vecAdd(&pendingAdd, ref); - - modReference(ref, 1); - - // TODO: freeing issues when trying a = 0 while(1) { a.print() 1.print() a = a + 1 } - - //if (pendingAdd.count >= 16) - // processPendingReferences(); -} - -void removePendingReference(Variable_t* ref) { - if (ref == NULL || ref->gcDoNotFree) - return; - - if (!ref->gcDoNotFree) { - if (ref->variableType == FunctionClass && ref->function.builtIn) { - removePendingReference(ref->function.origin); - } - - if (ref->variableType == SolvedArrayReferenceClass) { - removePendingReference(ref->solvedArray.arrayClassReference); - } - - modReference(ref, 0); - - //vecAdd(&pendingRemove, ref); - } -} -*/ - -void processPendingReferences() { - return; //stubbed - vecForEach(Variable_t**, references, (&pendingAdd)) - modReference(*references, 1); - - pendingAdd.count = 0; - - vecForEach(Variable_t**, references, (&pendingRemove)) - modReference(*references, 0); - - pendingRemove.count = 0; -} - -void exitGarbageCollector() { - processPendingReferences(); - - vecForEach(ReferenceCounter_t*, references, (&storedReferences)) { - gfx_printf("[WARN] referenced var %p at exit\n", references->ref); - freeVariable(&references->ref); - } - - vecFree(pendingAdd); - vecFree(pendingRemove); - vecFree(storedReferences); } \ No newline at end of file diff --git a/source/script/garbageCollector.h b/source/script/garbageCollector.h index e014ebe..f60a706 100644 --- a/source/script/garbageCollector.h +++ b/source/script/garbageCollector.h @@ -1,9 +1,5 @@ #include "model.h" -void initGarbageCollector(); -//void addPendingReference(Variable_t* ref); -void processPendingReferences(); -void exitGarbageCollector(); //void removePendingReference(Variable_t* ref); void modReference(Variable_t* ref, u8 add);