CS520
Spring 2013
Programming Assignment 3
Due Sunday March 24


Implement the maTe virtual machine, mvm.

This is a very lengthy assignment. Be sure to start early! To be successful you will need to get a significant portion of the assignment done before Spring Break.

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 6 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. We will not be implementing a garbage collector this semester.

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.

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.

Lab 7 will require you to do unit testing of the heap and frame functions. However, waiting to complete the rest of the assignment (the implementation of the fetch-execute cycle and the instructions) until after Lab 7 is not wise. You really should aim to get the heap functions and the frame functions completed before Spring Break, and then work on the fetch-execute cycle and the instructions after Spring Break.

Your program will be graded primarily by testing it for correct functionality. In addition, however, you may lose points if your program is not properly structured and documented. Coding guidelines are given on the course overview webpage.

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.

Your programs will be graded using agate.cs.unh.edu so be sure to test in that environment.

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 Sunday March 24. The standard late 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.


Last modified on February 24, 2013.

Comments and questions should be directed to hatcher@unh.edu