Closed robsimmons closed 11 years ago
I rewrote the bytecode compiler to directly use comparisons for conditionals and loops (bullet1).
Also, as in bullet2, cc0 -b will now generate negative small constants in the instruction stream, as argument to bipush. Not sure what "(negative) integer store variables" means.
I stuck to the design principle that code be layed out in the order in which it occurs in the source, and I was therefore reluctant to rotate loops. This means goto's can have a negative offset, but never conditionals. A rotated loop:
while (e) s;
goto loop: body: code for s loop: code for e if (true) goto body exit:
would be very easy to do, but invert e and s. Currently, the compiler produces:
loop: code for e if (true) goto body goto exit: body: code for s goto loop exit:
Thoughts?
Conditionals will always generate forward branches (conditional or unconditional).
Negative integer store variables meant storing -12512 instead of 12512 in the constant pool when "-12512" appears in the program - the only way to get negative values in the constant pool is to use 0x8####### notation.
What we have here seems sufficiently awesome: we can still do some by-hand tests to test negative conditional jumps and positive gotos, but all were checking for in that case is that students either abstracted correctly or cut-and-pasted consistently.
(Oh, we already have positive gotos.) Anyway, I like what the compiler currently produces, and the extra signed offsets are a nice touch. I'm happy closing at this point.
Just to clarify, I added the "negative integer store variables" in this pass. If you write x = -129, it will add the number -129 (0x FF FF FF 7F) to the constant pool. If you write x = -128, it will bipush -128 (0x80).
Ok. Sorry for using a wrong and ambiguous word, I was kind of free-associating there.
A couple of enhancements to the bytecode compiler would make it more student friendly: