You will complete your code generator for a subset of Java.
In this lab, you continue your work from your solution
to Lab 11.
So you can continue with the files you have or copy them into a new project
and go from there.
- You are not provided with a course solution for the final code generator.
Continue working with your Lab 11 code generator and work
toward a solution that handles the test files and any extra credit you wish
- The build.xml file will run every test that you place
in the TestFiles folder. The test files for the final project
can be found in the FinalProjectTestFiles folder.
When you are ready to test a given feature,
just move the corresponding test file from the
FinalProjectTestFiles folder into the TestFiles folder.
- You will no doubt notice some strange notation in the test files
for the final project.
The method calls and field acccesses
are annotated so that you don't have to look in any other source or class
files to determine types.
Java overloads the period symbol in references to methods, statics, and fields. Given
we can't tell whether this is some static field z in a class w.x.y,
or perhaps y is a static field in class w.x and z is a field
of the instance Y
To simplify matters, the notation for fields and methods is as follows:
- The period symbol is used only within a class reference. Thus,
w.x.y.z is class z in package w.x.y.
- To reference a static field or method of a class, use two colons (::), so that
java.lang.System::out is the System.out output stream.
- To reference a field of an instance, use ->. Thus,
(obj)->a references field a using the reference obj
- Methods work the same way. To call a static method, use:
- All references and methods also include the return type of the result, which appears
after a single colon. Thus,
the reference above for System.out is really
java.lang.System::out : java.io.PrintStream
and to print something using println
(java.lang.System::out : java.io.PrintStream) -> println : void ("hello")
and the absolute value method would be
java.lang.Math :: abs : int (num)
- Documentation on the JVM instruction set and Jasmin can
be found on the Lab 10 page.
- Unless you are attempting extra credit,
CodeGenVisitor.java is the only file you should submit.
- Any extra credit must be arranged with your
- Your assignment must generate correct object code for the
constructs found in the project test files as directed by your instructor.
expressions, assignment statements, if, while, return,
"short-circuiting and", "short-circuiting or", "and", "or", method
invocations and declarations.
- One issue you will have to confront is how to handle Boolean-valued
expressions. The Java interperter does not have a built-in notion of
what a Boolean value is nor how it should be represented.
- Some ideas for extra credit extensions to the compiler are as follows:
- Pre/post increment/decrement
- Floating point primitive types
- Semantic analysis: widening
- Semantic analysis: coercion to general type
- Compile == and != into .equals method calls
- Extendable primitive types
- Checking for assignment to "this" -- it's illegal
- Processing of field declarations -- the .field directive for Jasmin
- Processing of constructors
- Accurate declaration for .locals
- Emitting "short" forms for iload and aload, so that they take
- Handling "new" and constructor calls
one byte instead of two. For example, iload_1 instead of iload 1.
Submitting your project
Turn in your work as directed by your instructor.