From 9260cdb2e85d2660efaea97186739d18eaa804b6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 21 Jun 2018 00:40:45 +0000 Subject: [PATCH] compiler: support conversion of list to bytearray and bytes. Fixes #1077. --- artiq/compiler/transforms/artiq_ir_generator.py | 3 ++- artiq/test/coredevice/test_embedding.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 970803454..07967dcbb 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -1637,7 +1637,7 @@ class ARTIQIRGenerator(algorithm.Visitor): else: assert False elif (types.is_builtin(typ, "list") or types.is_builtin(typ, "array") or - types.is_builtin(typ, "bytearray")): + types.is_builtin(typ, "bytearray") or types.is_builtin(typ, "bytes")): if len(node.args) == 0 and len(node.keywords) == 0: length = ir.Constant(0, builtins.TInt32()) return self.append(ir.Alloc([length], node.type)) @@ -1648,6 +1648,7 @@ class ARTIQIRGenerator(algorithm.Visitor): def body_gen(index): elt = self.iterable_get(arg, index) + elt = self.append(ir.Coerce(elt, builtins.get_iterable_elt(node.type))) self.append(ir.SetElem(result, index, elt)) return self.append(ir.Arith(ast.Add(loc=None), index, ir.Constant(1, length.type))) diff --git a/artiq/test/coredevice/test_embedding.py b/artiq/test/coredevice/test_embedding.py index b0bcbbed3..8d0e64aba 100644 --- a/artiq/test/coredevice/test_embedding.py +++ b/artiq/test/coredevice/test_embedding.py @@ -140,6 +140,8 @@ class _RPCTypes(EnvExperiment): self.accept("foo") self.accept(b"foo") self.accept(bytearray(b"foo")) + self.accept(bytes([1, 2])) + self.accept(bytearray([1, 2])) self.accept((2, 3)) self.accept([1, 2]) self.accept(range(10))