From 04ec60541c63ab704fe9d8869add008dc3b36a7d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 27 Jul 2013 15:38:29 +0200 Subject: [PATCH] pythloite/ExprCompiler: attempt compile-time evaluation first --- migen/pytholite/expr.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/migen/pytholite/expr.py b/migen/pytholite/expr.py index 186c8854f..b59013c19 100644 --- a/migen/pytholite/expr.py +++ b/migen/pytholite/expr.py @@ -11,6 +11,14 @@ class ExprCompiler: self.symdict = symdict def visit_expr(self, node): + # Attempt compile-time evaluation first + try: + result = eval_ast(node, self.symdict) + except: + result = None + if isinstance(result, int): + return result + if isinstance(node, ast.Call): return self.visit_expr_call(node) elif isinstance(node, ast.BinOp):