Skip to content

Commit eeb09ab

Browse files
committed
fix: run tests
1 parent 74b7a6e commit eeb09ab

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,22 +1184,26 @@ def init(self, index: Lvalue, func: Expression, iterable: Expression) -> None:
11841184
)
11851185

11861186
def gen_condition(self) -> None:
1187-
builder = self.builder
1188-
line = self.line
1189-
# First, get the next item from the sub-generator
11901187
self.gen.gen_condition()
1191-
# Now, filter: only enter the body if func(item) is truthy
1192-
filter_block = BasicBlock()
1193-
builder.activate_block(filter_block)
1188+
1189+
def begin_body(self) -> None:
1190+
# 1. Assign the next item to the loop variable
11941191
self.gen.begin_body()
1192+
1193+
# 2. Call the filter function
1194+
builder = self.builder
1195+
line = self.line
11951196
item = builder.read(builder.get_assignment_target(self.index), line)
11961197
# TODO: implement logic to handle c calls of native functions
11971198
result = builder.py_call(self.filter_func, [item], line)
1198-
builder.add_bool_branch(result, self.body_block, self.loop_exit)
11991199

1200-
def begin_body(self) -> None:
1201-
# The item is already assigned to self.index by the sub-generator.
1202-
pass
1200+
# Now, filter: only enter the body if func(item) is truthy
1201+
cont_block, rest_block = BasicBlock(), BasicBlock()
1202+
builder.add_bool_branch(result, rest_block, cont_block)
1203+
builder.activate_block(cont_block)
1204+
builder.nonlocal_control[-1].gen_continue(builder, line)
1205+
builder.goto_and_activate(rest_block)
1206+
# At this point, the rest of the loop body (user code) will be emitted
12031207

12041208
def gen_step(self) -> None:
12051209
self.gen.gen_step()

mypyc/test-data/irbuild-basic.test

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ L0:
35913591
L1:
35923592
r4 = var_object_size a
35933593
r5 = r3 < r4 :: signed
3594-
if r5 goto L3 else goto L5 :: bool
3594+
if r5 goto L2 else goto L6 :: bool
35953595
L2:
35963596
r6 = list_get_item_unsafe a, r3
35973597
r7 = unbox(int, r6)
@@ -3604,14 +3604,16 @@ L2:
36043604
r12 = PyObject_IsTrue(r11)
36053605
r13 = r12 >= 0 :: signed
36063606
r14 = truncate r12: i32 to builtins.bool
3607-
if r14 goto L3 else goto L5 :: bool
3607+
if r14 goto L4 else goto L3 :: bool
36083608
L3:
3609+
goto L5
3610+
L4:
36093611
r15 = CPyTagged_Add(s, x)
36103612
s = r15
3611-
L4:
3613+
L5:
36123614
r16 = r3 + 1
36133615
r3 = r16
36143616
goto L1
3615-
L5:
36163617
L6:
3618+
L7:
36173619
return s

mypyc/test-data/run-loops.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ def f(a: list[int]) -> int:
579579
s += x
580580
return s
581581

582+
[file driver.py]
583+
from native import f
582584
print(f([1, 2, 3, 4, 5, 6]))
583585
print(f([1, 3, 5]))
584586
print(f([]))
@@ -595,6 +597,8 @@ def f(a: list[int]) -> int:
595597
s += x
596598
return s
597599

600+
[file driver.py]
601+
from native import f
598602
print(f([5, 15, 25]))
599603
print(f([]))
600604

0 commit comments

Comments
 (0)