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