We built a full-scale VM translator capable of handling branching and function commands, as well as translating multi-file VM programs. This project completes the development of the VM translator, which serves as the backend for the Hack compiler.
Our goal was to develop a full-scale VM-to-Hack translator that:
- Handles branching commands (
label
,goto
,if-goto
). - Translates function commands (
function
,call
,return
). - Supports multi-file VM programs with proper bootstrap code.
-
Clone the Repository
Clone the repository from the provided URL. -
Run the VM Translator
Translate one or multiple.vm
files into a single.asm
file using our translator. -
Test the Output
Use the CPU Emulator to load and execute the generated.asm
files, verifying their correctness using the provided test scripts.
- Branching Commands: Supports commands like
label
,goto
, andif-goto
. - Function Handling: Implements commands such as
function
,call
, andreturn
. - Multi-File Translation: Combines multiple
.vm
files into a single.asm
file with bootstrap code. - Bootstrap Code: Initializes the stack pointer and invokes
Sys.init
to start the program.
We validated the translator's functionality using the following test programs:
- Branching Commands:
BasicLoop.vm
: Testslabel
andif-goto
.FibonacciSeries.vm
: Testslabel
,goto
, andif-goto
.
- Function Commands:
SimpleFunction.vm
: Testsfunction
andreturn
.NestedCall.vm
: Tests nested function calls.FibonacciElement.vm
: Tests recursive calls with multiple files and bootstrap code.StaticsTest.vm
: Verifies static variable handling across multiple files.