Your goal in this project is to build a Smalltalk interpreter for the Smalltalk bytecodes you generated in the previous compiler project. I have provided approximately 100 unit tests, starting with extremely simple tests in TestVMBasics.java that directly send in bytecodes; e.g.,
Other tests use the compiler and the full system. After you get things working to a good degree, you can start testing the Run class (included as an attachment). For example input (3+4) print yields the following output:
method doIt 0000: push_int 3 0005: push_int 4 0010: send 1, "+" 0015: send 0, "print" 0020: pop 0021: self 0022: return 00: "+" 01: "print" 7 a MainClass
The output is similar to the last project but the key difference here is that the MainClass>>doIt method actually executes (here, it prints out 7) and prints out the return value (a MainClass).
Compiler
I will be providing you the binary for my solution to the previous compiler project so that everyone can start from the same (hopefully stable) base.
Deliverables
Your interpreter needs a number of Java implementations for the core Smalltalk classes:
- BlockContext.java
- BlockDescriptor.java
- MethodContext.java
- Primitive.java
- PrimitiveMethod.java
- STArray.java
- STBoolean.java
- STCharacter.java
- STClass.java
- STInteger.java
- STObject.java
- STString.java
See Smalltalk VM objects for more information on the fields.
On page VM architecture, you will find the comments and field associated with the overall VirtualMachine.java and then the two key message send and block evaluation context objects, MethodContext.java and BlockContext.java. You will also need BlockDescriptor.java, which gets pushed onto the operand stack in response to the BLOCK instruction. So, you will also need to provide full implementations for
- VirtualMachine.java
- MethodContext.java
- BlockContext.java
- BlockDescriptor.java
Submission
You will create a jar file called smalltalk-interp.jar containing source, grammar, and *.class files and place in your build directory:
https://www/svn/userid/cs652/smalltalk-interp/build/smalltalk-interp.jar
I will run your code by executing the following:
$java -cp "smalltalk-interp.jar:antlr-3.3.jar:$CLASSPATH" smalltalk.tool.Run test.st
You can use the svn account for development of the software too if you would like, but I will only be looking at your jar file in the build directory.
For more information, see svn in CS601. Naturally you will have to substitute cs652 for cs601.