/jack

2 stage compiler for the Jack programming language

Primary LanguageElixir

Jack Compiler

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.

Usage

Compiling Jack source code to Jack VM 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

Translating Jack VM code to Hack assembly

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

Assembling Hack assembly to machine code

TODO

Building

To build the jack compiler from source

mix escript.build

Installation

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.