Skip to content

Commit

Permalink
transforms/tools/value_to_ast: list support
Browse files Browse the repository at this point in the history
sbourdeauducq committed Dec 17, 2014
1 parent f3b727b commit 8af0301
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions artiq/test/full_stack.py
Original file line number Diff line number Diff line change
@@ -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 @@ def run(self):
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 @@ def test_misc(self):
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):
3 changes: 3 additions & 0 deletions artiq/transforms/tools.py
Original file line number Diff line number Diff line change
@@ -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):

0 comments on commit 8af0301

Please sign in to comment.