peterxu422 wrote
Why is it that the VM translation is:
VM code for computing ~(cond) //Why not compute cond?
if-goto L1
VM code for executing s1
goto L2
label L1
&nvsp;Vm Code for executing s2
label L2
....
The
else clause is optional. If it's not there, then the generated code only requires one jump:
VM code for computing ~(cond)
if-goto L1
VM code for executing s1
goto L2
label L1
Vm Code for executing s2
label L2
...
If the general if/then/else code generator tested for the true
cond value you'd need an extra jump in the "no else" case.
VM code for computing cond
if-goto L1
VM code for executing s2
goto L2
label L1
VM code for executing s1
label L2
...
Also note that if the generated code for s1 comes after the code for s2, the code for the entire s1, which may be a multi-statement block, will need to be cached in memory until after the code for s2 is emitted.
--Mark