1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-29 15:22:09 +00:00

remove old gc code

This commit is contained in:
suchmememanyskill 2021-07-19 12:28:40 +02:00
parent 3cd78d6efd
commit 2311c52ebf
4 changed files with 1 additions and 125 deletions

View file

@ -98,8 +98,6 @@ void RunScript(char *path, FSEntry_t entry){
lexarVectorClear(&ctx.script); lexarVectorClear(&ctx.script);
*/ */
gfx_printf("Init gc\n");
initGarbageCollector();
gfx_printf("Parsing\n"); gfx_printf("Parsing\n");
ParserRet_t ret = parseScript(script, size); ParserRet_t ret = parseScript(script, size);
free(script); 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); Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1);
exitRuntimeVars(); exitRuntimeVars();
exitGarbageCollector();
exitStaticVars(&ret.staticVarHolder); exitStaticVars(&ret.staticVarHolder);
exitFunction(ret.main.operations.data, ret.main.operations.count); exitFunction(ret.main.operations.data, ret.main.operations.count);
vecFree(ret.staticVarHolder); vecFree(ret.staticVarHolder);

View file

@ -63,8 +63,6 @@ int main()
return; return;
*/ */
initGarbageCollector();
char* script = readFile("input.te"); char* script = readFile("input.te");
if (script == NULL) if (script == NULL)
return; return;
@ -80,7 +78,6 @@ int main()
Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1); Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1);
exitRuntimeVars(); exitRuntimeVars();
exitGarbageCollector();
exitStaticVars(&ret.staticVarHolder); exitStaticVars(&ret.staticVarHolder);
exitFunction(ret.main.operations.data, ret.main.operations.count); exitFunction(ret.main.operations.data, ret.main.operations.count);
vecFree(ret.staticVarHolder); vecFree(ret.staticVarHolder);

View file

@ -3,23 +3,6 @@
#include "compat.h" #include "compat.h"
#include "garbageCollector.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) { void modReference(Variable_t* ref, u8 add) {
if (ref == NULL || ref->gcDoNotFree) if (ref == NULL || ref->gcDoNotFree)
return; return;
@ -30,6 +13,7 @@ void modReference(Variable_t* ref, u8 add) {
else { else {
ref->tagCount--; ref->tagCount--;
if (ref->tagCount <= 0) { if (ref->tagCount <= 0) {
// TODO: move to parser.c
if (ref->variableType == FunctionClass && ref->function.builtIn && ref->function.origin != NULL) if (ref->variableType == FunctionClass && ref->function.builtIn && ref->function.origin != NULL)
modReference(ref->function.origin, 0); modReference(ref->function.origin, 0);
@ -39,102 +23,4 @@ void modReference(Variable_t* ref, u8 add) {
freeVariable(&ref); 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);
} }

View file

@ -1,9 +1,5 @@
#include "model.h" #include "model.h"
void initGarbageCollector();
//void addPendingReference(Variable_t* ref);
void processPendingReferences();
void exitGarbageCollector();
//void removePendingReference(Variable_t* ref); //void removePendingReference(Variable_t* ref);
void modReference(Variable_t* ref, u8 add); void modReference(Variable_t* ref, u8 add);