We would like to keep the ability of using yield instead of creating iterator "objects". One way to implement it with llvm that we discussed is that
iter f() {
yield 1;
yield 2;
}
...
for I in f() }
if I == 1 {
ret 42;
}
}
...
Gets compiled to (pseudo code)
{act, i32} the_for_body (i32 I) {
if (I == 1)
ret ActRet, 42
ret ActContinue, undef
}
Act,i32 f(B) {
x1,v1 = B(1);
if x1 == ActRet {
ret x1,v1
} else if (x1 == ActBreak) {
ret ActBreak, undef
}
x2,v2 = B(2);
if x2 == ActRet {
ret x2,v2
} else if (x2 == ActBreak) {
ret ActBreak, undef
}
ret ActBreak, undef
}
and the for loop becomes a call:
x, y = f(the_for_body);
if x == ActRet {
ret x;
}
We would like to keep the ability of using yield instead of creating iterator "objects". One way to implement it with llvm that we discussed is that
iter f() {
yield 1;
yield 2;
}
...
for I in f() }
if I == 1 {
ret 42;
}
}
...
Gets compiled to (pseudo code)
{act, i32} the_for_body (i32 I) {
if (I == 1)
ret ActRet, 42
ret ActContinue, undef
}
Act,i32 f(B) {
x1,v1 = B(1);
if x1 == ActRet {
ret x1,v1
} else if (x1 == ActBreak) {
ret ActBreak, undef
}
x2,v2 = B(2);
if x2 == ActRet {
ret x2,v2
} else if (x2 == ActBreak) {
ret ActBreak, undef
}
ret ActBreak, undef
}
and the for loop becomes a call:
x, y = f(the_for_body);
if x == ActRet {
ret x;
}