2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 19:28:26 +08:00

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): def build(self):
self.input = 84 self.input = 84
self.inhomogeneous_units = [] self.inhomogeneous_units = []
self.al = [1, 2, 3, 4, 5]
@kernel @kernel
def run(self): def run(self):
@ -59,6 +60,9 @@ class _Misc(AutoContext):
self.decimal_fraction_d = int(decimal_fraction.denominator) self.decimal_fraction_d = int(decimal_fraction.denominator)
self.inhomogeneous_units.append(Quantity(1000, "Hz")) self.inhomogeneous_units.append(Quantity(1000, "Hz"))
self.inhomogeneous_units.append(Quantity(10, "s")) self.inhomogeneous_units.append(Quantity(10, "s"))
self.acc = 0
for i in range(5):
self.acc += self.al[i]
@kernel @kernel
def dimension_error1(self): def dimension_error1(self):
@ -185,6 +189,7 @@ class ExecutionCase(unittest.TestCase):
Fraction("1.2")) Fraction("1.2"))
self.assertEqual(uut.inhomogeneous_units, [ self.assertEqual(uut.inhomogeneous_units, [
Quantity(1000, "Hz"), Quantity(10, "s")]) Quantity(1000, "Hz"), Quantity(10, "s")])
self.assertEqual(uut.acc, sum(uut.al))
with self.assertRaises(DimensionError): with self.assertRaises(DimensionError):
uut.dimension_error1() uut.dimension_error1()
with self.assertRaises(DimensionError): with self.assertRaises(DimensionError):

View File

@ -54,6 +54,9 @@ def value_to_ast(value):
keywords=[], starargs=None, kwargs=None) keywords=[], starargs=None, kwargs=None)
elif isinstance(value, str): elif isinstance(value, str):
return ast.Str(value) return ast.Str(value)
elif isinstance(value, list):
elts = [value_to_ast(elt) for elt in value]
return ast.List(elts, ast.Load())
else: else:
for kg in core_language.kernel_globals: for kg in core_language.kernel_globals:
if value is getattr(core_language, kg): if value is getattr(core_language, kg):