Implementing VCODE in JavaTo use Java as an intermediate language in an existing compiler, the current intermediate language (assuming that one exists) either can be totally replaced by Java or it can be translated into Java by an additional stage of the compilation process. The first approach entails rewriting the front end of the compiler to generate Java. The second approach requires no changes to existing parts of the compiler. Moreover, the additional translation stage should be simple to implement because the current intermediate language was probably designed for easy compilation. Finally, the front end has already performed most of the error checking, and has reduced complex high-level constructs of the source language into more primitive operations that are easier to map into Java.
However, the second approach will probably generate less efficient Java code than the first, because semantic information is lost. In particular, the code produced will be Java ``in the style of'' the existing intermediate language, and probably will not take full advantage of Java language features (in the same way that Fortran written in the style of Lisp is unlikely to be efficient). These observations are not specific to Java; they apply to any intermediate language.
We chose the second approach, favoring ease of implementation over the efficiency of the generated code (we investigate the final impact on performance in Section 5). The design of our system is shown in Figure 2. The NESL compiler is unchanged. Below it, the vcodetojava phase converts VCODE into Java. A standard Java compiler is then used to compile the Java, which consists mainly of calls to vector methods, into portable Java bytecode. This, together with a VcodeEmulation library that implements the vector methods and associated vector stack, can be executed by any Java virtual machine. Note that we have effectively replaced the VCODE interpreter with a Java virtual machine.
Figure 2: Components (boxes) and languages (lines) of the new NESL-to-Java system. Solid arrows represent translation, and dotted lines represent linkage to Java libraries. New components are shown with heavy borders.
In the rest of this section we discuss the design and implementation of each of the major components of this system: the vector stack, the vector operations, and the vcodetojava program.