The capstone project for my Computer Science degree is a virtual machine and compiler written from scratch.
The original requirements for the virtual machine was for it to read and execute assembly code. Framing function calls on the stack was hand written in assembly. The vm also had to support pseudo multi-processing.
The compiler (the second semester of the capstone project) takes c-like source code and compiles it down to assembly code which can execute on the vm.
Extending the Project
I wanted to do more with the original project, so I spoke with the Professor, and he’s working with me to do independent study to improve the original design of the vm. I’ve modified the compiler so that it writes byte code to a file, instead of stopping at assembly. I also completely rewrote the vm in C++. I originally wrote the vm in Python (for convenience), but the Python vm is super slow. I had to implement a loader in the rewritten vm, since my compiler now outputs byte code.
The big piece of the project I’m working on right now is implementing a mark and sweep garbage collector. I had to reorganize the frames and put all the pointers at the top of the frame (otherwise the gc algorithm can’t find the pointers inside the method call). I’ve also reorganized the heap allocation to put pointers at the front of every object.
My plan for implementing the gc algorithm in the vm is to use the list of pointers in the main method as the root of the tree during the mark phase. Any allocated memory that can’t be reached from the the pointers in the main method will be considered unused and will be freed.
I’ll post more as I get close to completing this project (sometime this August). Is anybody interested in seeing source code or more details? Post if you’re interested.