pythloite/ExprCompiler: attempt compile-time evaluation first

This commit is contained in:
Sebastien Bourdeauducq 2013-07-27 15:38:29 +02:00
parent f62eff0309
commit 04ec60541c
1 changed files with 8 additions and 0 deletions

View File

@ -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):