mirror of https://github.com/m-labs/artiq.git
compiler/fold_constants: fix int/round
This commit is contained in:
parent
24544f2758
commit
b3b61d8b6b
|
@ -61,12 +61,18 @@ class _ConstantFolder(ast.NodeTransformer):
|
||||||
def visit_Call(self, node):
|
def visit_Call(self, node):
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
fn = node.func.id
|
fn = node.func.id
|
||||||
if fn in ("int", "int64", "round", "round64"):
|
constant_ops = {
|
||||||
|
"int": int,
|
||||||
|
"int64": int64,
|
||||||
|
"round": round,
|
||||||
|
"round64": round64
|
||||||
|
}
|
||||||
|
if fn in constant_ops:
|
||||||
try:
|
try:
|
||||||
arg = eval_constant(node.args[0])
|
arg = eval_constant(node.args[0])
|
||||||
except NotConstant:
|
except NotConstant:
|
||||||
return node
|
return node
|
||||||
result = value_to_ast(globals()[fn](arg))
|
result = value_to_ast(constant_ops[fn](arg))
|
||||||
return ast.copy_location(result, node)
|
return ast.copy_location(result, node)
|
||||||
else:
|
else:
|
||||||
return node
|
return node
|
||||||
|
|
Loading…
Reference in New Issue