Skip to content

Commit ba88a8a

Browse files
committed
Fix 'continue' statement
There was an error in some C++ compilers: "jump bypasses variable initialization", caused by a 'goto' to a label at the end of a loop (added in #2).
1 parent 32df51b commit ba88a8a

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/transpiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ def loop(self, stmt_callback, label):
892892

893893
body = c.Block()
894894
with self.block(body):
895+
self.output(c.If(v.false, c.Block(c.Label(labels['continue']), c.Statement('continue'))))
895896
yield
896-
self.output(c.Label(labels['continue']))
897897

898898
self.output(stmt_callback(body))
899899
self.output(c.Label(labels['break']))

test/good/loops/continue04.out

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
2
3+
3
4+
6

test/good/loops/continue04.px

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
i = 0
3+
while i < 3 label l do
4+
i += 1
5+
while true do
6+
print i
7+
if i < 3 do
8+
continue l
9+
else do
10+
break
11+
x = i * 2
12+
print x

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.10.0.dev
1+
0.11.0

0 commit comments

Comments
 (0)