pytholite/compiler: support while loops
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 10 Nov 2012 13:37:33 +0000 (14:37 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 10 Nov 2012 13:37:33 +0000 (14:37 +0100)
migen/pytholite/compiler.py

index 14fb248b59141667f2fc4e77ae621b5d10a2a82b..d526fa8e2d15665bb20cec65e3003abda20e4bec 100644 (file)
@@ -111,6 +111,17 @@ class _Compiler:
                        states.append(test_state)
                        states += states_t + states_f
                        exit_states += exit_states_t + exit_states_f
+               elif isinstance(statement, ast.While):
+                       test = self.visit_expr(statement.test)
+                       states_b, exit_states_b = self.visit_block(statement.body)
+
+                       test_state = [If(test, _AbstractNextState(states_b[0]))]
+                       for exit_state in exit_states_b:
+                               exit_state.insert(0, _AbstractNextState(test_state))
+                       
+                       exit_states.append(test_state)
+                       states += states_b
+                       states.append(test_state)
                else:
                        raise NotImplementedError
                return states, exit_states
@@ -224,6 +235,10 @@ class _Compiler:
                return r
        
        def visit_expr_name(self, node):
+               if node.id == "True":
+                       return Constant(1)
+               if node.id == "False":
+                       return Constant(0)
                r = self.symdict[node.id]
                if isinstance(r, _Register):
                        r = r.storage