From 7aa2113799346a04c9c1f81e2d2cf2786ea04d04 Mon Sep 17 00:00:00 2001 From: benson1029 Date: Wed, 17 Apr 2024 18:23:16 +0800 Subject: [PATCH] Fix bug in for loop evaluation --- src/go/ece/microcode/for.ts | 6 +++--- src/go/ece/tests/control.test.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/go/ece/microcode/for.ts b/src/go/ece/microcode/for.ts index d175d59..3d30666 100644 --- a/src/go/ece/microcode/for.ts +++ b/src/go/ece/microcode/for.ts @@ -80,10 +80,10 @@ function evaluate_for_i(cmd: number, heap: Heap, C: ContextControl, S: ContextSt const name_cmd = heap.allocate_any({ tag: "name", name: (loopVar as ComplexString).get_string() }); C.push(name_cmd); heap.free_object(name_cmd); - const marker_cmd = heap.allocate_any({ tag: "marker_i" }); - C.push(marker_cmd); - heap.free_object(marker_cmd); } + const marker_cmd = heap.allocate_any({ tag: "marker_i" }); + C.push(marker_cmd); + heap.free_object(marker_cmd); C.push(body.address); } else { diff --git a/src/go/ece/tests/control.test.js b/src/go/ece/tests/control.test.js index f34c903..f270ff9 100644 --- a/src/go/ece/tests/control.test.js +++ b/src/go/ece/tests/control.test.js @@ -311,4 +311,22 @@ describe('Evaluating control structures', () => { fmt.Println(f()) `)).toBe("1\n3\n5\n7\n9\n9\n"); }) + + it("continue without a loop variable", () => { + expect(evaluateSequence(` + var i int32 + var f func() int32 + for i = 0; i < 10; i++ { + if i == 0 { + f = func() int32 { + return i + } + } + i++ + continue + fmt.Println("unreachable") + } + fmt.Println(f()) + `)).toBe("10\n") + }) })