mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 11:56:42 +00:00
remove old gc code
This commit is contained in:
parent
3cd78d6efd
commit
2311c52ebf
4 changed files with 1 additions and 125 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue