mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 19:28:26 +08:00
compiler: the len builtin is not polymorphic, coerce the result.
Fixes #659.
This commit is contained in:
parent
7516e6d800
commit
31dd99e8bd
@ -482,8 +482,9 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
|||||||
name = None
|
name = None
|
||||||
else:
|
else:
|
||||||
name = "{}.len".format(value.name)
|
name = "{}.len".format(value.name)
|
||||||
return self.append(ir.Builtin("len", [value], typ,
|
len = self.append(ir.Builtin("len", [value], builtins.TInt32(),
|
||||||
name=name))
|
name=name))
|
||||||
|
return self.append(ir.Coerce(len, typ))
|
||||||
elif builtins.is_range(value.type):
|
elif builtins.is_range(value.type):
|
||||||
start = self.append(ir.GetAttr(value, "start"))
|
start = self.append(ir.GetAttr(value, "start"))
|
||||||
stop = self.append(ir.GetAttr(value, "stop"))
|
stop = self.append(ir.GetAttr(value, "stop"))
|
||||||
|
17
artiq/test/lit/regression/bug_659.py
Normal file
17
artiq/test/lit/regression/bug_659.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# RUN: %python -m artiq.compiler.testbench.embedding %s
|
||||||
|
|
||||||
|
from artiq.language.core import *
|
||||||
|
from artiq.language.types import *
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def rotate(array):
|
||||||
|
'''Rotates an array, deleting the oldest value'''
|
||||||
|
length = len(array)
|
||||||
|
for i in range(np.int64(len(array)) - 1):
|
||||||
|
array[length - i - 1] = array[length - i - 2]
|
||||||
|
array[0] = 0
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def entrypoint():
|
||||||
|
rotate([1,2,3,4])
|
14
artiq/test/lit/regression/device_db.pyon
Normal file
14
artiq/test/lit/regression/device_db.pyon
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"comm": {
|
||||||
|
"type": "local",
|
||||||
|
"module": "artiq.coredevice.comm_dummy",
|
||||||
|
"class": "Comm",
|
||||||
|
"arguments": {}
|
||||||
|
},
|
||||||
|
"core": {
|
||||||
|
"type": "local",
|
||||||
|
"module": "artiq.coredevice.core",
|
||||||
|
"class": "Core",
|
||||||
|
"arguments": {"ref_period": 1e-9}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user