fix: realloc for declarations after each iteration

This commit is contained in:
TopchetoEU 2024-09-05 17:15:26 +03:00
parent 07411f62c8
commit 0004839f6f
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4

View File

@ -25,6 +25,7 @@ public class ForNode extends Node {
} }
@Override public void compile(CompileResult target, boolean pollute) { @Override public void compile(CompileResult target, boolean pollute) {
var subtarget = target.subtarget(); var subtarget = target.subtarget();
subtarget.scope.singleEntry = false;
subtarget.add(i -> Instruction.stackAlloc(subtarget.scope.allocCount())); subtarget.add(i -> Instruction.stackAlloc(subtarget.scope.allocCount()));
declaration.compile(subtarget, false, BreakpointType.STEP_OVER); declaration.compile(subtarget, false, BreakpointType.STEP_OVER);
@ -39,8 +40,11 @@ public class ForNode extends Node {
CompoundNode.compileMultiEntry(body, subtarget, false, BreakpointType.STEP_OVER); CompoundNode.compileMultiEntry(body, subtarget, false, BreakpointType.STEP_OVER);
LabelContext.popLoop(subtarget.env, label); LabelContext.popLoop(subtarget.env, label);
subtarget.add(_i -> Instruction.stackRealloc(subtarget.scope.allocCount()));
CompoundNode.compileMultiEntry(assignment, subtarget, false, BreakpointType.STEP_OVER); CompoundNode.compileMultiEntry(assignment, subtarget, false, BreakpointType.STEP_OVER);
int endI = subtarget.size(); int endI = subtarget.size();
end.set(endI); end.set(endI);
subtarget.add(Instruction.jmp(start - endI)); subtarget.add(Instruction.jmp(start - endI));