compiler: support conversion of list to bytearray and bytes.

Fixes #1077.
This commit is contained in:
whitequark 2018-06-21 00:40:45 +00:00
parent 5a91f820fd
commit 9260cdb2e8
2 changed files with 4 additions and 1 deletions

View File

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

View File

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