-
Notifications
You must be signed in to change notification settings - Fork 170
Closed
Labels
Description
It seems this condition (if_unique_id.size() - loop_unique_id.size() == label_index - 1)
might not be perfect to determine to continue
or end
the loop
. Consider the following example where we have a loop
inside an if
construct:
def main0():
x: i32
x = (2+3)*5
j: i32 = 0
if True:
while x > 0:
j += 2
x -= 1
print(x)
print(j)
main0()
Output:
(lp) ubaid@ubaid-Lenovo-ideapad-330-15ARR:~/OpenSource/lpython$ lpython examples/expr2.py
0
50
(lp) ubaid@ubaid-Lenovo-ideapad-330-15ARR:~/OpenSource/lpython$ lpython examples/expr2.py --backend wasm_x86 -o loop
(lp) ubaid@ubaid-Lenovo-ideapad-330-15ARR:~/OpenSource/lpython$ ./loop
24
2
(lp) ubaid@ubaid-Lenovo-ideapad-330-15ARR:~/OpenSource/lpython$
The loop
in this case just executes once and then exits. This is because in this case (when visit_Br()
is visited) the if
count would be 2
and loop
count would be 1
. The label_index
would be 1
. The condition would be 2 - 1 == 1 - 1
, that is 1 == 0
, which is not true
and hence the loop
exits.
I think we might need to simulate how wasm
works in x86
. We might need to use same label indexes (or same label index space) for if
's and loop
's (just like wasm
does).
Originally posted by @Shaikh-Ubaid in #1290 (comment)
ubaidsk