Jack is a toy, java-like, object oriented language as presented in Nand2Tetris. This project is a 2 stage compiler written for the Jack language. The compiler generates code for a stack-based virtual machine, then translates it to Hack assembly which can be executed on the Nand2Tetris CPU emulator.
A Hack assembler is also included for completeness but is not strictly necessary since the cpu emulator understands both assembly code and machine code.
To compile a directory containing *.jack
classes
jack myProgram/
To compile a jack source file
jack myProgram/Main.jack
To dump the token list produced by the parser
jack -v -t MainT.xml myProgram/Main.jack
To dump the AST produced by the parser
jack -v -a Main.xml myProgram/Main.jack
To compile a directory containing *.vm
files
jack -o examples/FibonacciElement
To compile a single *.vm file
jack -o examples/BasicLoop/BasicLoop.vm
To specify the output filename
jack -o -f fib.asm examples/FibonacciElement
To dump debug info to STDOUT
jack -o -v -f fib.asm examples/FibonacciElement
TODO
To build the jack compiler from source
mix escript.build
If available in Hex, the package can be installed
by adding jack
to your list of dependencies in mix.exs
:
def deps do
[
{:jack, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/jack.