From 37f113c3ea5173d218a582a74037b61a6c94692b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 10 Nov 2012 15:26:13 +0100 Subject: [PATCH] pytholite/compiler: support range(constants) in for loops --- migen/pytholite/compiler.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/migen/pytholite/compiler.py b/migen/pytholite/compiler.py index 6d5b3280..11694091 100644 --- a/migen/pytholite/compiler.py +++ b/migen/pytholite/compiler.py @@ -128,7 +128,7 @@ class _Compiler: 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) + it = self.visit_iterator(statement.iter) last_exit_states = [] for iteration in it: self.symdict[target] = iteration @@ -143,6 +143,19 @@ class _Compiler: raise NotImplementedError return states, exit_states + def visit_iterator(self, node): + if isinstance(node, ast.List): + return ast.literal_eval(node) + elif isinstance(node, ast.Call) and isinstance(node.func, ast.Name): + funcname = node.func.id + args = map(ast.literal_eval, node.args) + if funcname == "range": + return range(*args) + else: + raise NotImplementedError + else: + raise NotImplementedError + def visit_assign(self, node): if isinstance(node.targets[0], ast.Name): self.targetname = node.targets[0].id -- 2.30.2