mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-26 05:42:07 +00:00
make the garbage collector less terrible
This commit is contained in:
parent
65a28d8ef6
commit
91af9b4437
6 changed files with 42 additions and 1 deletions
|
@ -47,12 +47,23 @@ ClassFunction(getStringLength) {
|
||||||
return newIntVariablePtr(strlen(s1));
|
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 };
|
u8 oneStringArg[] = { StringClass };
|
||||||
|
|
||||||
ClassFunctionTableEntry_t stringFunctions[] = {
|
ClassFunctionTableEntry_t stringFunctions[] = {
|
||||||
{"print", printStringVariable, 0, 0},
|
{"print", printStringVariable, 0, 0},
|
||||||
{"+", addStringVariables, 1, oneStringArg },
|
{"+", addStringVariables, 1, oneStringArg },
|
||||||
{"len", getStringLength, 0, 0},
|
{"len", getStringLength, 0, 0},
|
||||||
|
{"bytes", stringBytes, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
Variable_t getStringMember(Variable_t* var, char* memberName) {
|
Variable_t getStringMember(Variable_t* var, char* memberName) {
|
||||||
|
|
|
@ -98,23 +98,28 @@ ClassFunction(arraySlice) {
|
||||||
return copyVariableToPtr(refSkip);
|
return copyVariableToPtr(refSkip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: arrayForEach does not like the new garbage collector
|
||||||
ClassFunction(arrayForEach) {
|
ClassFunction(arrayForEach) {
|
||||||
Vector_t* v = &caller->solvedArray.vector;
|
Vector_t* v = &caller->solvedArray.vector;
|
||||||
|
|
||||||
Callback_SetVar_t setVar = { .isTopLevel = 1, .varName = (*args)->string.value };
|
Callback_SetVar_t setVar = { .isTopLevel = 1, .varName = (*args)->string.value };
|
||||||
Variable_t* iter = NULL;
|
Variable_t* iter = NULL;
|
||||||
iter = copyVariableToPtr(newIntVariable(0));
|
iter = copyVariableToPtr(newIntVariable(0));
|
||||||
|
iter->gcDoNotFree = 1;
|
||||||
runtimeVariableEdit(&setVar, iter);
|
runtimeVariableEdit(&setVar, iter);
|
||||||
|
|
||||||
for (int i = 0; i < v->count; i++) {
|
for (int i = 0; i < v->count; i++) {
|
||||||
*iter = arrayClassGetIdx(caller, i);
|
*iter = arrayClassGetIdx(caller, i);
|
||||||
|
iter->gcDoNotFree = 1;
|
||||||
|
|
||||||
Variable_t* res = genericCallDirect(args[1], NULL, 0);
|
Variable_t* res = genericCallDirect(args[1], NULL, 0);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iter->reference = 1;
|
||||||
|
free(iter);
|
||||||
|
|
||||||
return &emptyClass;
|
return &emptyClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,10 @@ Variable_t* opToVar(Operator_t* op, Callback_SetVar_t *setCallback) {
|
||||||
else if (op->variable.staticVariableType == 3) {
|
else if (op->variable.staticVariableType == 3) {
|
||||||
var = copyVariableToPtr(newFunctionVariable(createFunctionClass((Function_t) { 0 }, op->variable.staticFunction)));
|
var = copyVariableToPtr(newFunctionVariable(createFunctionClass((Function_t) { 0 }, op->variable.staticFunction)));
|
||||||
var->reference = 1;
|
var->reference = 1;
|
||||||
|
|
||||||
|
if (!strcmp(var->function.builtInPtr->name,"while")) {
|
||||||
|
var->function.firstArgAsFunction = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -24,6 +24,23 @@ void modReference(Variable_t* ref, u8 add) {
|
||||||
if (ref == NULL || ref->gcDoNotFree)
|
if (ref == NULL || ref->gcDoNotFree)
|
||||||
return;
|
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;
|
ReferenceCounter_t* additionalFree = NULL;
|
||||||
|
|
||||||
vecForEach(ReferenceCounter_t*, references, (&storedReferences)) {
|
vecForEach(ReferenceCounter_t*, references, (&storedReferences)) {
|
||||||
|
@ -59,6 +76,7 @@ void modReference(Variable_t* ref, u8 add) {
|
||||||
|
|
||||||
ReferenceCounter_t r = { .ref = ref, .refCount = 1 };
|
ReferenceCounter_t r = { .ref = ref, .refCount = 1 };
|
||||||
vecAdd(&storedReferences, r);
|
vecAdd(&storedReferences, r);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
void addPendingReference(Variable_t* ref) {
|
void addPendingReference(Variable_t* ref) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
Variable_t* copyVariableToPtr(Variable_t var) {
|
Variable_t* copyVariableToPtr(Variable_t var) {
|
||||||
Variable_t* a = malloc(sizeof(Variable_t));
|
Variable_t* a = malloc(sizeof(Variable_t));
|
||||||
*a = var;
|
*a = var;
|
||||||
|
a->tagCount = 0;
|
||||||
addPendingReference(a);
|
addPendingReference(a);
|
||||||
return 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 };
|
return (Variable_t){ 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,7 @@ typedef struct _Variable_t {
|
||||||
u8 gcDoNotFree : 1;
|
u8 gcDoNotFree : 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
u8 tagCount;
|
||||||
} Variable_t;
|
} Variable_t;
|
||||||
|
|
||||||
typedef struct _CallArgs_t {
|
typedef struct _CallArgs_t {
|
||||||
|
|
Loading…
Reference in a new issue