mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Tweak
This commit is contained in:
@@ -460,22 +460,23 @@ void initInterpreter(Interpreter* interpreter) {
|
|||||||
|
|
||||||
void freeInterpreter(Interpreter* interpreter) {
|
void freeInterpreter(Interpreter* interpreter) {
|
||||||
//BUGFIX: handle scopes of functions, which refer to the parent scope (leaking memory)
|
//BUGFIX: handle scopes of functions, which refer to the parent scope (leaking memory)
|
||||||
for (int i = 0; i < interpreter->scope->variables.capacity; i++) {
|
while(inner.scope != NULL) {
|
||||||
//handle keys, just in case
|
for (int i = 0; i < inner.scope->variables.capacity; i++) {
|
||||||
if (IS_FUNCTION(interpreter->scope->variables.entries[i].key)) {
|
//handle keys, just in case
|
||||||
popScope(AS_FUNCTION(interpreter->scope->variables.entries[i].key).scope);
|
if (IS_FUNCTION(inner.scope->variables.entries[i].key)) {
|
||||||
AS_FUNCTION(interpreter->scope->variables.entries[i].key).scope = NULL;
|
popScope(AS_FUNCTION(inner.scope->variables.entries[i].key).scope);
|
||||||
|
AS_FUNCTION(inner.scope->variables.entries[i].key).scope = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_FUNCTION(inner.scope->variables.entries[i].value)) {
|
||||||
|
popScope(AS_FUNCTION(inner.scope->variables.entries[i].value).scope);
|
||||||
|
AS_FUNCTION(inner.scope->variables.entries[i].value).scope = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_FUNCTION(interpreter->scope->variables.entries[i].value)) {
|
inner.scope = popScope(inner.scope);
|
||||||
popScope(AS_FUNCTION(interpreter->scope->variables.entries[i].value).scope);
|
|
||||||
AS_FUNCTION(interpreter->scope->variables.entries[i].value).scope = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
popScope(interpreter->scope);
|
|
||||||
interpreter->scope = NULL;
|
|
||||||
|
|
||||||
freeLiteralArray(&interpreter->literalCache);
|
freeLiteralArray(&interpreter->literalCache);
|
||||||
freeLiteralArray(&interpreter->stack);
|
freeLiteralArray(&interpreter->stack);
|
||||||
}
|
}
|
||||||
@@ -1516,23 +1517,26 @@ static bool execFnCall(Interpreter* interpreter) {
|
|||||||
|
|
||||||
//free
|
//free
|
||||||
//BUGFIX: handle scopes of functions, which refer to the parent scope (leaking memory)
|
//BUGFIX: handle scopes of functions, which refer to the parent scope (leaking memory)
|
||||||
for (int i = 0; i < inner.scope->variables.capacity; i++) {
|
while(inner.scope != AS_FUNCTION(func).scope) {
|
||||||
//handle keys, just in case
|
for (int i = 0; i < inner.scope->variables.capacity; i++) {
|
||||||
if (IS_FUNCTION(inner.scope->variables.entries[i].key)) {
|
//handle keys, just in case
|
||||||
popScope(AS_FUNCTION(inner.scope->variables.entries[i].key).scope);
|
if (IS_FUNCTION(inner.scope->variables.entries[i].key)) {
|
||||||
AS_FUNCTION(inner.scope->variables.entries[i].key).scope = NULL;
|
popScope(AS_FUNCTION(inner.scope->variables.entries[i].key).scope);
|
||||||
|
AS_FUNCTION(inner.scope->variables.entries[i].key).scope = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_FUNCTION(inner.scope->variables.entries[i].value)) {
|
||||||
|
popScope(AS_FUNCTION(inner.scope->variables.entries[i].value).scope);
|
||||||
|
AS_FUNCTION(inner.scope->variables.entries[i].value).scope = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_FUNCTION(inner.scope->variables.entries[i].value)) {
|
inner.scope = popScope(inner.scope);
|
||||||
popScope(AS_FUNCTION(inner.scope->variables.entries[i].value).scope);
|
|
||||||
AS_FUNCTION(inner.scope->variables.entries[i].value).scope = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
freeLiteralArray(&returns);
|
freeLiteralArray(&returns);
|
||||||
freeLiteralArray(&arguments);
|
freeLiteralArray(&arguments);
|
||||||
freeLiteralArray(&inner.stack);
|
freeLiteralArray(&inner.stack);
|
||||||
freeLiteralArray(&inner.literalCache);
|
freeLiteralArray(&inner.literalCache);
|
||||||
popScope(inner.scope);
|
|
||||||
freeLiteral(func);
|
freeLiteral(func);
|
||||||
|
|
||||||
//actual bytecode persists until next call
|
//actual bytecode persists until next call
|
||||||
|
|||||||
Reference in New Issue
Block a user