forked from M-Labs/artiq
compiler: support conversion of list to bytearray and bytes.
Fixes #1077.
This commit is contained in:
parent
5a91f820fd
commit
9260cdb2e8
@ -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)))
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user