forked from M-Labs/artiq
1
0
Fork 0

transforms/tools/value_to_ast: list support

This commit is contained in:
Sebastien Bourdeauducq 2014-12-17 22:22:44 +08:00
parent f3b727b59d
commit 8af0301185
2 changed files with 8 additions and 0 deletions

View File

@ -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):

View File

@ -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):