Next: Starting Out
Up: The Project
Previous: Pascal as Source
This section summarizes the major problems encountered when compiling Pascal to
Java bytecode and their solutions. Full treatment is given in the subsequent
chapters.
- No call-by-reference in Java
To create references to variables, they are compiled into arrays of one
element. The reference to the array can then be passed in case the variable has
to be passed by reference. See section 9.1.
- No nesting in Java
Because there is no nesting in Java or in the bytecode, nested procedures and
functions have to be made global. This also means that local variables and
constants have to be compiled in such a way that nested procedures and
functions can still access the local variables and constants of the procedure
or function they are declared in. This has to be done by passing the local
variables as call-by-reference parameters to every nested procedure and
function. Local constants are made global, which saves passing them around.
See section 9.2.
- No symbolic labeling in the bytecode
All jumps in the bytecode jump to an offset. An algorithm is designed that sets
internal labels from which the offsets for the jump instructions are resolved
once they are known. See section 10.6.
- No non-local goto
In the bytecode the goto instruction can only jump inside a frame. This
causes a problem with a goto statement in Pascal that causes a non-local
jump. This problem is solved by using an exception to pass the target label and
letting the exception handler complete the jump. See section 11.3.
mark@bottom.xs4all.nl