forked from M-Labs/artiq
compiler: share eval_ast
This commit is contained in:
parent
d7f9e6b228
commit
7eb9641905
|
@ -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)#
|
|
@ -2,6 +2,7 @@ import inspect, textwrap, ast, types
|
|||
|
||||
from artiq.language import units
|
||||
from artiq.compiler import unparse
|
||||
from artiq.compiler.tools import eval_ast
|
||||
|
||||
def find_kernel_body(node):
|
||||
while True:
|
||||
|
@ -14,12 +15,6 @@ def find_kernel_body(node):
|
|||
else:
|
||||
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):
|
||||
try:
|
||||
r = eval_ast(node, units.__dict__)
|
||||
|
|
Loading…
Reference in New Issue