forked from M-Labs/artiq
compiler: the len builtin is not polymorphic, coerce the result.
Fixes #659.
This commit is contained in:
parent
6acdcbb82a
commit
ab71c9a0ba
@ -482,8 +482,9 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
||||
name = None
|
||||
else:
|
||||
name = "{}.len".format(value.name)
|
||||
return self.append(ir.Builtin("len", [value], typ,
|
||||
name=name))
|
||||
len = self.append(ir.Builtin("len", [value], builtins.TInt32(),
|
||||
name=name))
|
||||
return self.append(ir.Coerce(len, typ))
|
||||
elif builtins.is_range(value.type):
|
||||
start = self.append(ir.GetAttr(value, "start"))
|
||||
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