From 56ccd054eb49dc78e6ba909c8dd8b9cc8187bad4 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 18 Aug 2014 22:52:19 +0800 Subject: [PATCH] compiler/fold_constants: support int, int64, round and round64 --- artiq/compiler/fold_constants.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/artiq/compiler/fold_constants.py b/artiq/compiler/fold_constants.py index 191a1e95e..0e0507df5 100644 --- a/artiq/compiler/fold_constants.py +++ b/artiq/compiler/fold_constants.py @@ -1,6 +1,7 @@ import ast, operator from artiq.compiler.tools import * +from artiq.language.core import int64, round64 _ast_unops = { ast.Invert: operator.inv, @@ -57,5 +58,18 @@ class _ConstantFolder(ast.NodeTransformer): return node return ast.copy_location(result, node) + def visit_Call(self, node): + self.generic_visit(node) + fn = node.func.id + if fn in ("int", "int64", "round", "round64"): + try: + arg = eval_constant(node.args[0]) + except NotConstant: + return node + result = value_to_ast(globals()[fn](arg)) + return ast.copy_location(result, node) + else: + return node + def fold_constants(node): _ConstantFolder().visit(node)