1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-12-27 11:56:05 +00:00

make the garbage collector less terrible

This commit is contained in:
suchmememanyskill 2021-07-10 01:12:39 +02:00
parent 65a28d8ef6
commit 91af9b4437
6 changed files with 42 additions and 1 deletions

View file

@ -47,12 +47,23 @@ ClassFunction(getStringLength) {
return newIntVariablePtr(strlen(s1));
}
ClassFunction(stringBytes) {
Variable_t v = { 0 };
v.variableType = ByteArrayClass;
u32 len = strlen(caller->string.value);
v.solvedArray.vector = newVec(1, len);
v.solvedArray.vector.count = len;
memcpy(v.solvedArray.vector.data, caller->string.value, len);
return copyVariableToPtr(v);
}
u8 oneStringArg[] = { StringClass };
ClassFunctionTableEntry_t stringFunctions[] = {
{"print", printStringVariable, 0, 0},
{"+", addStringVariables, 1, oneStringArg },
{"len", getStringLength, 0, 0},
{"bytes", stringBytes, 0, 0},
};
Variable_t getStringMember(Variable_t* var, char* memberName) {

View file

@ -98,23 +98,28 @@ ClassFunction(arraySlice) {
return copyVariableToPtr(refSkip);
}
// TODO: arrayForEach does not like the new garbage collector
ClassFunction(arrayForEach) {
Vector_t* v = &caller->solvedArray.vector;
Callback_SetVar_t setVar = { .isTopLevel = 1, .varName = (*args)->string.value };
Variable_t* iter = NULL;
iter = copyVariableToPtr(newIntVariable(0));
iter->gcDoNotFree = 1;
runtimeVariableEdit(&setVar, iter);
for (int i = 0; i < v->count; i++) {
*iter = arrayClassGetIdx(caller, i);
iter->gcDoNotFree = 1;
Variable_t* res = genericCallDirect(args[1], NULL, 0);
if (res == NULL)
return NULL;
}
iter->reference = 1;
free(iter);
return &emptyClass;
}

View file

@ -69,6 +69,10 @@ Variable_t* opToVar(Operator_t* op, Callback_SetVar_t *setCallback) {
else if (op->variable.staticVariableType == 3) {
var = copyVariableToPtr(newFunctionVariable(createFunctionClass((Function_t) { 0 }, op->variable.staticFunction)));
var->reference = 1;
if (!strcmp(var->function.builtInPtr->name,"while")) {
var->function.firstArgAsFunction = 1;
}
}
}
else {

View file

@ -24,6 +24,23 @@ void modReference(Variable_t* ref, u8 add) {
if (ref == NULL || ref->gcDoNotFree)
return;
if (add) {
ref->tagCount++;
}
else {
ref->tagCount--;
if (ref->tagCount <= 0) {
if (ref->variableType == FunctionClass && ref->function.builtIn && ref->function.origin != NULL)
modReference(ref->function.origin, 0);
if (ref->variableType == SolvedArrayReferenceClass)
modReference(ref->solvedArray.arrayClassReference, 0);
freeVariable(&ref);
}
}
/*
ReferenceCounter_t* additionalFree = NULL;
vecForEach(ReferenceCounter_t*, references, (&storedReferences)) {
@ -59,6 +76,7 @@ void modReference(Variable_t* ref, u8 add) {
ReferenceCounter_t r = { .ref = ref, .refCount = 1 };
vecAdd(&storedReferences, r);
*/
}
/*
void addPendingReference(Variable_t* ref) {

View file

@ -17,6 +17,7 @@
Variable_t* copyVariableToPtr(Variable_t var) {
Variable_t* a = malloc(sizeof(Variable_t));
*a = var;
a->tagCount = 0;
addPendingReference(a);
return a;
}
@ -201,6 +202,7 @@ Variable_t getGenericFunctionMember(Variable_t* var, char* memberName, ClassFunc
}
}
printScriptError(SCRIPT_FATAL, "Could not find member of class");
return (Variable_t){ 0 };
}

View file

@ -185,6 +185,7 @@ typedef struct _Variable_t {
u8 gcDoNotFree : 1;
};
};
u8 tagCount;
} Variable_t;
typedef struct _CallArgs_t {