mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 19:28:26 +08:00
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:
|
else:
|
||||||
assert False
|
assert False
|
||||||
elif (types.is_builtin(typ, "list") or types.is_builtin(typ, "array") or
|
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:
|
if len(node.args) == 0 and len(node.keywords) == 0:
|
||||||
length = ir.Constant(0, builtins.TInt32())
|
length = ir.Constant(0, builtins.TInt32())
|
||||||
return self.append(ir.Alloc([length], node.type))
|
return self.append(ir.Alloc([length], node.type))
|
||||||
@ -1648,6 +1648,7 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
|||||||
|
|
||||||
def body_gen(index):
|
def body_gen(index):
|
||||||
elt = self.iterable_get(arg, 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))
|
self.append(ir.SetElem(result, index, elt))
|
||||||
return self.append(ir.Arith(ast.Add(loc=None), index,
|
return self.append(ir.Arith(ast.Add(loc=None), index,
|
||||||
ir.Constant(1, length.type)))
|
ir.Constant(1, length.type)))
|
||||||
|
@ -140,6 +140,8 @@ class _RPCTypes(EnvExperiment):
|
|||||||
self.accept("foo")
|
self.accept("foo")
|
||||||
self.accept(b"foo")
|
self.accept(b"foo")
|
||||||
self.accept(bytearray(b"foo"))
|
self.accept(bytearray(b"foo"))
|
||||||
|
self.accept(bytes([1, 2]))
|
||||||
|
self.accept(bytearray([1, 2]))
|
||||||
self.accept((2, 3))
|
self.accept((2, 3))
|
||||||
self.accept([1, 2])
|
self.accept([1, 2])
|
||||||
self.accept(range(10))
|
self.accept(range(10))
|
||||||
|
Loading…
Reference in New Issue
Block a user