Skip to content

Commit

Permalink
Fix bug in for loop evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
benson1029 committed Apr 17, 2024
1 parent d03a0d8 commit 7aa2113
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/go/ece/microcode/for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions src/go/ece/tests/control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})

0 comments on commit 7aa2113

Please sign in to comment.