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