compiler: the len builtin is not polymorphic, coerce the result.

Fixes #659.
This commit is contained in:
whitequark 2017-01-31 21:28:20 +00:00
parent 6acdcbb82a
commit ab71c9a0ba
3 changed files with 34 additions and 2 deletions

View File

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

View 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])

View 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}
}
}