forked from M-Labs/artiq
py2llvm: len() support on lists
This commit is contained in:
parent
8af0301185
commit
f31386d15d
|
@ -167,7 +167,7 @@ class Visitor:
|
|||
|
||||
def _visit_expr_Call(self, node):
|
||||
fn = node.func.id
|
||||
if fn in {"bool", "int", "int64", "round", "round64", "float"}:
|
||||
if fn in {"bool", "int", "int64", "round", "round64", "float", "len"}:
|
||||
value = self.visit_expression(node.args[0])
|
||||
return getattr(value, "o_" + fn)(self.builder)
|
||||
elif fn == "Fraction":
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import llvmlite.ir as ll
|
||||
|
||||
from artiq.py2llvm.values import VGeneric
|
||||
from artiq.py2llvm.base_types import VInt
|
||||
|
||||
|
||||
class VList(VGeneric):
|
||||
|
@ -40,6 +41,15 @@ class VList(VGeneric):
|
|||
ll.Constant(ll.IntType(32), 0)])
|
||||
builder.store(ll.Constant(ll.IntType(32), count), count_ptr)
|
||||
|
||||
def o_len(self, builder):
|
||||
r = VInt()
|
||||
if builder is not None:
|
||||
count_ptr = builder.gep(self.llvm_value, [
|
||||
ll.Constant(ll.IntType(32), 0),
|
||||
ll.Constant(ll.IntType(32), 0)])
|
||||
r.auto_store(builder, builder.load(count_ptr))
|
||||
return r
|
||||
|
||||
def o_subscript(self, index, builder):
|
||||
r = self.el_type.new()
|
||||
if builder is not None:
|
||||
|
|
|
@ -61,7 +61,7 @@ class _Misc(AutoContext):
|
|||
self.inhomogeneous_units.append(Quantity(1000, "Hz"))
|
||||
self.inhomogeneous_units.append(Quantity(10, "s"))
|
||||
self.acc = 0
|
||||
for i in range(5):
|
||||
for i in range(len(self.al)):
|
||||
self.acc += self.al[i]
|
||||
|
||||
@kernel
|
||||
|
|
|
@ -9,7 +9,7 @@ embeddable_funcs = (
|
|||
core_language.delay, core_language.at, core_language.now,
|
||||
core_language.time_to_cycles, core_language.cycles_to_time,
|
||||
core_language.syscall,
|
||||
range, bool, int, float, round,
|
||||
range, bool, int, float, round, len,
|
||||
core_language.int64, core_language.round64,
|
||||
Fraction, units.Quantity, units.check_unit, core_language.EncodedException
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue