From 8af03011853fd712a2e93b2650453acc37f6e5ac Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 17 Dec 2014 22:22:44 +0800 Subject: [PATCH] transforms/tools/value_to_ast: list support --- artiq/test/full_stack.py | 5 +++++ artiq/transforms/tools.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/artiq/test/full_stack.py b/artiq/test/full_stack.py index 679162cb0..8ef013f59 100644 --- a/artiq/test/full_stack.py +++ b/artiq/test/full_stack.py @@ -50,6 +50,7 @@ class _Misc(AutoContext): def build(self): self.input = 84 self.inhomogeneous_units = [] + self.al = [1, 2, 3, 4, 5] @kernel def run(self): @@ -59,6 +60,9 @@ class _Misc(AutoContext): self.decimal_fraction_d = int(decimal_fraction.denominator) self.inhomogeneous_units.append(Quantity(1000, "Hz")) self.inhomogeneous_units.append(Quantity(10, "s")) + self.acc = 0 + for i in range(5): + self.acc += self.al[i] @kernel def dimension_error1(self): @@ -185,6 +189,7 @@ class ExecutionCase(unittest.TestCase): Fraction("1.2")) self.assertEqual(uut.inhomogeneous_units, [ Quantity(1000, "Hz"), Quantity(10, "s")]) + self.assertEqual(uut.acc, sum(uut.al)) with self.assertRaises(DimensionError): uut.dimension_error1() with self.assertRaises(DimensionError): diff --git a/artiq/transforms/tools.py b/artiq/transforms/tools.py index e796490a4..ddf69457c 100644 --- a/artiq/transforms/tools.py +++ b/artiq/transforms/tools.py @@ -54,6 +54,9 @@ def value_to_ast(value): keywords=[], starargs=None, kwargs=None) elif isinstance(value, str): return ast.Str(value) + elif isinstance(value, list): + elts = [value_to_ast(elt) for elt in value] + return ast.List(elts, ast.Load()) else: for kg in core_language.kernel_globals: if value is getattr(core_language, kg):