Implement the maTe virtual machine, mvm.
This is a very lengthy assignment. Be sure to start early!
mvm should take a single command-line argument, the name of a maTe class file.
Your implementation of mwm must follow the design given in the header file available on agate in ~cs520/public/prog3/src/vm.h. Implementing this design will allow you to utilize the implementation of the native methods found in the file native.c in the same directory on agate. The directory also contains files with stubs for all the functions discussed below, as well as a Makefile.
Start by implementing initializeVM to read the class file into memory and then implement the functions for retrieving information from the class file:
bool isValidClass(Class class);
Class getObjectClass(void);
Class getIntegerClass(void);
Class getStringClass(void);
Class getTableClass(void);
Class getIthClass(int i);
bool isObjectClass(Class class);
bool isIntegerClass(Class class);
bool isStringClass(Class class);
bool isTableClass(Class class);
Class getSuper(Class class);
Count getNumFields(Class class);
Count getNumMethods(Class class);
Address getMethodAddress(Class class, Index index);
Count getMethodNumLocals(Class class, Index index);
int getWordFromCode(Address addr);
Address getMainBlockAddress(void);
Count getMainBlockNumLocals(void);
Next, implement the heap:
Reference allocateObject(Class class);
Reference allocateString(const char *initialValue);
Class getClass(Reference ref);
const char *getStringValue(Reference ref);
int getIntegerValue(Reference ref);
void putIntegerValue(Reference ref, int value);
Reference getField(Reference ref, Index index);
void putField(Reference objectRef, Index index, Reference newFieldValue);
Next, implement the support for frames and the frame stack:
Frame createFrame(Count localsLength, Address pc);
void deleteFrame(Frame frame);
bool isEmptyOperandStack(Frame frame);
void pushOperandStack(Frame frame, Reference ref);
Reference popOperandStack(Frame frame);
Reference peekOperandStack(Frame frame, Index i);
Count lengthLocals(Frame frame);
Reference getLocals(Frame frame, Index index);
void putLocals(Frame frame, Index index, Reference ref);
Address getPC(Frame frame);
void putPC(Frame frame, Address pc);
bool isEmptyFrameStack(void);
void pushFrame(Frame frame);
Frame popFrame(void);
Frame getTopFrame(void);
Lab 6 will require you to do unit testing of the heap and frame functions, but will assume that the code written for Lab 5 is working.
Finally, implement the fetch-execute cycle and then implement the maTe instructions:
Test using the class files that are available in ~cs520/public/prog3/test. You should write a main function that calls initializeVM and then starts the fetch-execute cycle. Note: the fetch-execute cycle should only be started after initalizeVM has returned.
You may also create your own tests by running the maTe compiler (~cs520/bin/mc) and the maTe assembler (~cs520/bin/mas). While testing, you can also utilize the "official" implementation of the maTe virtual machine, ~cs520/bin/mvm. The goal for this assignment is to duplicate the behavior of the official implementation.
Points will be assigned in the following way:
As part of good programming practice, you should insert checks into your code to handle malformed class files or programs. However, we do not plan to extensively test this aspect of your solution. We plan to evaluate how well you did this by just spot-checking your code when we are checking its documentation and structure.
Remember, you may lose points if your program is not properly structured or adequately documented. Coding guidelines are given on the course overview webpage.
Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment. Your programs will be compiled using these gcc flags: -g -Wall -std=c99.
You will submit mvm.c, vm.c, heap.c, class.c, and frame.c. Put all of your code in these files. And, as noted above, helper functions for the functions in class.c should be in class.c, helper functions for the functions in heap.c should be in heap.c, and helper functions for the functions in frame.c should be in frame.c. This will allow us to do unit testing of these files for partial credit.
Your programs should be submitted for grading from
agate.cs.unh.edu.
To turn in this assignment, type:
~cs520/bin/submit prog3 mvm.c vm.c heap.c class.c frame.c
Submissions can be checked by typing:
~cs520/bin/scheck prog3
This assignment is due Wednesday October 12. The standard policy concerning late submissions will be in effect. See the course overview webpage.
Remember: as always you are expected to do your own work on this assignment. Copying code from another student or from sites on the internet is explicitly forbidden!
Comments and questions should be directed to pjh@cs.unh.edu