Community
Participate
Working Groups
For the following EGL code: program pgm1 type BasicProgram {} myInt int = 4; function main() aaa boolean; index int; for (index from 1 to f3(aaa) by 5) SysLib.writeStdout("inside loop"); end end function f3(p1 boolean inout) returns(int) SysLib.writeStdout("myint = " + myint); myint = myint + 1; return (myInt); end end The for statement produced by java gen looks like this: boolean eze$Temp1 = false; AnyBoxedObject<Boolean> eze$Temp3; eze$Temp3 = EAny.ezeWrap(aaa); int eze$Temp2; eze$Temp2 = f3(eze$Temp3); aaa = eze$Temp3.ezeUnbox(); for (index = (short) 1; index <= eze$Temp2; index += (short) 5) { if (eze$Temp1) { AnyBoxedObject<Boolean> eze$Temp6; eze$Temp6 = EAny.ezeWrap(aaa); eze$Temp2 = f3(eze$Temp6); aaa = eze$Temp6.ezeUnbox(); } else { eze$Temp1 = true; } SysLib.writeStdout("inside loop"); } However, this is not right. With this logic, F3 will be invoked before the first entry into the loop (which is fine), but F3 will not be invoked again until AFTER the loop in entered the 2nd time. I have set up this scenerio to show that F3 is only invoked 1 time, when in fact it should be invoked 3 times. Attached is the hand written java equivalent to the EGL program. When it runs, it produces: myint = 4 inside loop myint = 5 inside loop myint = 6 But the generated EGL only produces: myint = 4 inside loop The generated java should look more like this: AnyBoxedObject<Boolean> eze$Temp3; eze$Temp3 = EAny.ezeWrap(aaa); int eze$Temp2; eze$Temp2 = f3(eze$Temp3); aaa = eze$Temp3.ezeUnbox(); for (index = (short) 1; index <= eze$Temp2; index += (short) 5) { SysLib.writeStdout("inside loop"); AnyBoxedObject<Boolean> eze$Temp6; eze$Temp6 = EAny.ezeWrap(aaa); eze$Temp2 = f3(eze$Temp6); aaa = eze$Temp6.ezeUnbox(); } The problem is in the IRs produced by ReorganizeCode
Created attachment 205342 [details] Java equavalent to EGL source
As a side note, if you change the for statement in my EGL source to: for (index from 1 to 10 by f3(aaa)) The resulting IRs produced by ReorganizeCode contains a boolean temporary variable this is not really needed. This temporary variable would normally be used for the TO expression, but since it does not need to be expanded, the temporary variable is not needed in this case.
I agree with what you are saying Paul, however, your example is flawed as well. If the user codes a "continue for" statement, then the call to the function f3 (done in your example after the writestdout) will not get executed, but would in my case. It seems there is no solution to a for statement, other than breaking the whole thing up into a while(true) and imbedded if statements.
fixed
Test works now