forked from M-Labs/artiq
1
0
Fork 0

compiler: coerce `while` condition to bool.

Fixes #768.
This commit is contained in:
whitequark 2017-07-01 18:59:07 +00:00
parent 911ee4a959
commit ea7549cfa4
3 changed files with 14 additions and 0 deletions

View File

@ -451,6 +451,7 @@ class ARTIQIRGenerator(algorithm.Visitor):
self.current_block = head self.current_block = head
old_continue, self.continue_target = self.continue_target, head old_continue, self.continue_target = self.continue_target, head
cond = self.visit(node.test) cond = self.visit(node.test)
cond = self.coerce_to_bool(cond)
post_head = self.current_block post_head = self.current_block
break_block = self.add_block("while.break") break_block = self.add_block("while.break")

View File

@ -19,3 +19,9 @@ else:
assert (0 if True else 1) == 0 assert (0 if True else 1) == 0
assert (0 if False else 1) == 1 assert (0 if False else 1) == 1
if 0:
assert True
if 1:
assert True

View File

@ -53,3 +53,10 @@ while True:
assert False assert False
else: else:
assert False assert False
while 0:
assert False
while 1:
assert True
break