ivant wrote
Sounds interesting. How is it [dup] helping with that [switch/case statement]?
Source:
switch (i+j) {
case 1:
do Output.printString("one");
break;
case TWO:
do Output.printString("two");
break;
(more cases)
...
break;
}
do Output.println();
Code generated by my compiler:
/// 11: switch (i+j) {
push local 0 // i <===== evaluate control expression
push local 3 // j
add
/// 12: case 1:
pop temp 0 <===== dup top of stack
push temp 0 <
push temp 0 <
push constant 1
eq
not
if-goto L5
/// 13: do Output.printString("one");
push constant 3
call String.new 1
...
call Output.printString 1
pop temp 0
/// 14: break;
goto L4
/// 15: case TWO:
label L5
pop temp 0
push temp 0
push temp 0
push local 1 // TWO
eq
not
if-goto L6
/// 16: do Output.printString("two");
...
/// 35: break;
goto L12
label L14
goto L4
/// 36: }
/// 37:
label L4
pop temp 0 <===== discard control value
/// 38: do Output.println();
call Output.println 0