Skip to content

Commit

Permalink
py2llvm: len() support on lists
Browse files Browse the repository at this point in the history
sbourdeauducq committed Dec 18, 2014
1 parent 8af0301 commit f31386d
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions artiq/py2llvm/ast_body.py
Original file line number Diff line number Diff line change
@@ -167,9 +167,9 @@ def _visit_expr_Compare(self, node):

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)
return getattr(value, "o_" + fn)(self.builder)
elif fn == "Fraction":
r = fractions.VFraction()
if self.builder is not None:
10 changes: 10 additions & 0 deletions artiq/py2llvm/lists.py
Original file line number Diff line number Diff line change
@@ -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 @@ def set_count(self, builder, count):
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:
2 changes: 1 addition & 1 deletion artiq/test/full_stack.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ def run(self):
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
2 changes: 1 addition & 1 deletion artiq/transforms/tools.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
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
)

0 comments on commit f31386d

Please sign in to comment.