pythloite/ExprCompiler: attempt compile-time evaluation first
This commit is contained in:
parent
f62eff0309
commit
04ec60541c
|
@ -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 New Issue