In this project, you will complete a compiler for Jay (called
JaySea, inspired by javac
) which
produces Java VM assembly (which can then be used to
generate classfiles).
Take note that we are compiling plain old Jay, not any of the Jay extensions we've played with this semester.
Many other pieces are provided for you, and can be found in a tar file.
cp /cslab/class/cs365/proj10.tar .
The system works like this.
The script jaysea
feeds a Jay program into the
ML-written compiler, which produces a file in Java VM assembly.
For example,
./jaysea euclid.jay
will produce euclid.jj
.
Then the Java assembler Jasmin can be used to produce the classfile.
For example,
java -jar /cslab/java/classes/jasmin.jar euclid.jj
or, if jasmin.jar
is already in your classpath,
java Jasmin euclid.jj
will produce euclid.class
.
Now
java euclid
Will run the program.
Your task is finishing the compilation functions in
compile.sml
.
As in Friday's class, what you need to figure out is,
for all Jay statements and expressions, what series of
instructions needs to be emitted, and how does that
affect the stack?
Make use of these resources:
As you work, I recommend you have
both Jay and Java versions of your test files.
Compile the Java versions and disassemble them with
javap
to see what the result might look like.
Your output does not have to be identical to what javac
produces--often there is an equivalent series of instructions that
you'll find are easier to produce---but javac
can guide you through some of the knottier statements.
All you need is a compiler that produces programs that work
to get full credit.
But there are some optimizations you could perform for which
I will award extra credit.
For example, if (x > 0)...
would naively
be complied by loading x, pushing 0, generating the
sequence for >, and then ifne
,
but a more efficient version woul load x and use if_icmpgt
.
Also, x = x + 1;
could be done using the
iinc
instruction.
To turn in this project, please copy your compile.sml
to the turn=in directory I will prepare for you:
/cslab/class/cs365/turnin/proj10/xxxxx
where "xxxxx" is [andy|david|tyler|yelemis].
Due: May 2, 5:00 pm. You may not apply late days to this project; all projects must be turned in by this, the last day of classes.