Skip to content
/ jack Public

2 stage compiler for the Jack programming language

Notifications You must be signed in to change notification settings

skryl/jack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

2 stage compiler for the Jack programming language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages