From ea7549cfa4efd585a9d115aebb527f4ba097e095 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 1 Jul 2017 18:59:07 +0000 Subject: [PATCH] compiler: coerce `while` condition to bool. Fixes #768. --- artiq/compiler/transforms/artiq_ir_generator.py | 1 + artiq/test/lit/integration/if.py | 6 ++++++ artiq/test/lit/integration/while.py | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 9a580f6fb..d3e08df98 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -451,6 +451,7 @@ class ARTIQIRGenerator(algorithm.Visitor): self.current_block = head old_continue, self.continue_target = self.continue_target, head cond = self.visit(node.test) + cond = self.coerce_to_bool(cond) post_head = self.current_block break_block = self.add_block("while.break") diff --git a/artiq/test/lit/integration/if.py b/artiq/test/lit/integration/if.py index fab6c3df0..8d8eec4f2 100644 --- a/artiq/test/lit/integration/if.py +++ b/artiq/test/lit/integration/if.py @@ -19,3 +19,9 @@ else: assert (0 if True else 1) == 0 assert (0 if False else 1) == 1 + +if 0: + assert True + +if 1: + assert True diff --git a/artiq/test/lit/integration/while.py b/artiq/test/lit/integration/while.py index e7d03c0d7..397055c9a 100644 --- a/artiq/test/lit/integration/while.py +++ b/artiq/test/lit/integration/while.py @@ -53,3 +53,10 @@ while True: assert False else: assert False + +while 0: + assert False + +while 1: + assert True + break