mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
pythloite/ExprCompiler: attempt compile-time evaluation first
This commit is contained in:
parent
f62eff0309
commit
04ec60541c
1 changed files with 8 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue