From 70fbc6ad56c0668c818e1f4275d8ee6cdbefb63c Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 13 Aug 2014 17:58:06 +0800 Subject: [PATCH] compiler/interleave: use eval_constant from tools --- artiq/compiler/interleave.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/artiq/compiler/interleave.py b/artiq/compiler/interleave.py index a71790d47..dcf6ba384 100644 --- a/artiq/compiler/interleave.py +++ b/artiq/compiler/interleave.py @@ -1,12 +1,12 @@ import ast, types from artiq.language import units -from artiq.compiler.tools import eval_ast +from artiq.compiler.tools import * # -1 statement duration could not be pre-determined # 0 statement has no effect on timeline # >0 statement is a static delay that advances the timeline -# by the given amount (in base_s_unit) +# by the given amount (in seconds) def _get_duration(stmt): if isinstance(stmt, (ast.Expr, ast.Assign)): return _get_duration(stmt.value) @@ -18,16 +18,13 @@ def _get_duration(stmt): elif isinstance(stmt, ast.Call) and isinstance(stmt.func, ast.Name): name = stmt.func.id if name == "delay": - da = stmt.args[0] - if isinstance(da, ast.Call) \ - and isinstance(da.func, ast.Name) \ - and da.func.id == "Quantity" \ - and isinstance(da.args[0], ast.Num): - if not isinstance(da.args[1], ast.Name) or da.args[1].id != "base_s_unit": - raise units.DimensionError("Delay not expressed in seconds") - return da.args[0].n - else: + try: + da = eval_constant(stmt.args[0]) + except NotConstant: return -1 + if da.unit != units.s_unit: + raise units.DimensionError("Delay not expressed in seconds") + return da.amount else: return 0 else: