From 0004839f6f1cd1782be1e15d1e4ade31c2c212fd Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:15:26 +0300 Subject: [PATCH] fix: realloc for declarations after each iteration --- .../me/topchetoeu/jscript/compilation/control/ForNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/me/topchetoeu/jscript/compilation/control/ForNode.java b/src/main/java/me/topchetoeu/jscript/compilation/control/ForNode.java index 8e9651a..e2181e2 100644 --- a/src/main/java/me/topchetoeu/jscript/compilation/control/ForNode.java +++ b/src/main/java/me/topchetoeu/jscript/compilation/control/ForNode.java @@ -25,6 +25,7 @@ public class ForNode extends Node { } @Override public void compile(CompileResult target, boolean pollute) { var subtarget = target.subtarget(); + subtarget.scope.singleEntry = false; subtarget.add(i -> Instruction.stackAlloc(subtarget.scope.allocCount())); declaration.compile(subtarget, false, BreakpointType.STEP_OVER); @@ -39,8 +40,11 @@ public class ForNode extends Node { CompoundNode.compileMultiEntry(body, subtarget, false, BreakpointType.STEP_OVER); LabelContext.popLoop(subtarget.env, label); + subtarget.add(_i -> Instruction.stackRealloc(subtarget.scope.allocCount())); + CompoundNode.compileMultiEntry(assignment, subtarget, false, BreakpointType.STEP_OVER); int endI = subtarget.size(); + end.set(endI); subtarget.add(Instruction.jmp(start - endI));