Skip to content

Commit 802a6dc

Browse files
committed
fix; zip
1 parent ae526b4 commit 802a6dc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,21 @@ def __init__(
891891
self.items = expr.items
892892
self.body_insts = body_insts
893893
self.item_types = [builder.node_type(item) for item in self.items]
894+
self.index_target = builder.maybe_spill_assignable(Integer(0, c_pyssize_t_rprimitive))
895+
896+
def gen_condition(self) -> None:
897+
# For unrolled loops, immediately jump to the body if there are items,
898+
# otherwise jump to the loop exit.
899+
# NOTE: this method is not used when the loop is fully unrolled, but is when the loop is a component of another loop, ie a ForZip
900+
builder = self.builder
901+
comparison = builder.binary_op(builder.read(self.index_target, self.line), Integer(len(self.items)), "<", self.line)
902+
builder.add_bool_branch(comparison, self.body_block, self.loop_exit)
903+
904+
def gen_step(self) -> None:
905+
# NOTE: this method is not used when the loop is fully unrolled, but is when the loop is a component of another loop, ie a ForZip
906+
builder = self.builder
907+
add = builder.builder.int_add(builder.read(self.index_target, self.line), 1)
908+
builder.assign(self.index_target, add, self.line)
894909

895910
def begin_body(self) -> None:
896911
builder = self.builder

0 commit comments

Comments
 (0)