Skip to content

Commit

Permalink
Merge pull request #609 from RevengerWizard/develop
Browse files Browse the repository at this point in the history
Close upvalues after `continue` and `break` statements
  • Loading branch information
Jason2605 committed Mar 7, 2023
2 parents 6bb92ba + 7a84bd3 commit 1eae67a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/vm/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,14 @@ static void breakStatement(Compiler *compiler) {
for (int i = compiler->localCount - 1;
i >= 0 && compiler->locals[i].depth > compiler->loop->scopeDepth;
i--) {
emitByte(compiler, OP_POP);
if(compiler->locals[i].isUpvalue)
{
emitByte(compiler, OP_CLOSE_UPVALUE);
}
else
{
emitByte(compiler, OP_POP);
}
}

emitJump(compiler, OP_BREAK);
Expand All @@ -2276,7 +2283,14 @@ static void continueStatement(Compiler *compiler) {
for (int i = compiler->localCount - 1;
i >= 0 && compiler->locals[i].depth > compiler->loop->scopeDepth;
i--) {
emitByte(compiler, OP_POP);
if(compiler->locals[i].isUpvalue)
{
emitByte(compiler, OP_CLOSE_UPVALUE);
}
else
{
emitByte(compiler, OP_POP);
}
}

// Jump to top of current innermost loop.
Expand Down

0 comments on commit 1eae67a

Please sign in to comment.