forked from M-Labs/artiq
1
0
Fork 0

compiler: share eval_ast

This commit is contained in:
Sebastien Bourdeauducq 2014-06-10 15:16:28 +02:00
parent d7f9e6b228
commit 7eb9641905
2 changed files with 8 additions and 6 deletions

7
artiq/compiler/tools.py Normal file
View File

@ -0,0 +1,7 @@
import ast
def eval_ast(expr, symdict=dict()):
if not isinstance(expr, ast.Expression):
expr = ast.Expression(expr)
code = compile(expr, "<ast>", "eval")
return eval(code, symdict)#

View File

@ -2,6 +2,7 @@ import inspect, textwrap, ast, types
from artiq.language import units from artiq.language import units
from artiq.compiler import unparse from artiq.compiler import unparse
from artiq.compiler.tools import eval_ast
def find_kernel_body(node): def find_kernel_body(node):
while True: while True:
@ -14,12 +15,6 @@ def find_kernel_body(node):
else: else:
raise TypeError raise TypeError
def eval_ast(expr, symdict=dict()):
if not isinstance(expr, ast.Expression):
expr = ast.Expression(expr)
code = compile(expr, "<ast>", "eval")
return eval(code, symdict)
def _try_eval_with_units(node): def _try_eval_with_units(node):
try: try:
r = eval_ast(node, units.__dict__) r = eval_ast(node, units.__dict__)