From 39c7dc7d63c061aa17655967e7f96b2a245a082a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 10 Nov 2012 15:02:55 +0100 Subject: [PATCH] pytholite/compiler: support for loops (iterating on lists only) --- migen/pytholite/compiler.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/migen/pytholite/compiler.py b/migen/pytholite/compiler.py index d526fa8e..c735876a 100644 --- a/migen/pytholite/compiler.py +++ b/migen/pytholite/compiler.py @@ -122,6 +122,23 @@ class _Compiler: exit_states.append(test_state) states += states_b states.append(test_state) + elif isinstance(statement, ast.For): + if not isinstance(statement.target, ast.Name): + raise NotImplementedError + target = statement.target.id + if target in self.symdict: + raise NotImplementedError("For loop target must use an available name") + it = ast.literal_eval(statement.iter) + last_exit_states = [] + for iteration in it: + self.symdict[target] = iteration + states_b, exit_states_b = self.visit_block(statement.body) + for exit_state in last_exit_states: + exit_state.insert(0, _AbstractNextState(states_b[0])) + last_exit_states = exit_states_b + states += states_b + exit_states += last_exit_states + del self.symdict[target] else: raise NotImplementedError return states, exit_states @@ -242,6 +259,8 @@ class _Compiler: r = self.symdict[node.id] if isinstance(r, _Register): r = r.storage + if isinstance(r, int): + r = Constant(r) return r def visit_expr_num(self, node): -- 2.30.2