From: Sebastien Bourdeauducq Date: Sat, 27 Jul 2013 13:38:29 +0000 (+0200) Subject: pythloite/ExprCompiler: attempt compile-time evaluation first X-Git-Tag: 24jan2021_ls180~2099^2~496 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=04ec60541c63ab704fe9d8869add008dc3b36a7d;p=litex.git pythloite/ExprCompiler: attempt compile-time evaluation first --- diff --git a/migen/pytholite/expr.py b/migen/pytholite/expr.py index 186c8854..b59013c1 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):