CS520
Fall 2016
Program 3
Due Wednesday October 12


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:

Put initializeVM in the file vm.c and put the above functions in class.c. Put any associated helper functions in these two files as well. Lab 5 will require you to do unit testing of these functions.

Next, implement the heap:

Put these functions, and any associated helper functions, in heap.c. You can just use malloc to allocate space. (In Program 4 you will implement a garbage collector.)

Next, implement the support for frames and the frame stack:

You can assume that both the frame stack and the operand stack within a frame will have a maximum stack depth of 1000. Put these functions, and any associated helper functions, in frame.c.

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:

Put this code in mvm.c.

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:

It is important that you implement the instructions in the above order in order to let us coherently test your code.

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!


Last modified on August 19, 2016.

Comments and questions should be directed to pjh@cs.unh.edu