Project 12: Jack OS

  • Description: Complete Project 12 on nand2tetris.org by implementing the Jack OS. Note that this is really two projects, 12A and 12B.

  • What to turn in:
    • For Part A, you should turn in Sys.jack, Array.jack, String.jack, Keyboard.jack, and Math.jack.

    • For Part B, you should turn in Screen.jack, Output.jack, and Memory.jack.

  • Specification: To get credit for each part, your .jack files must pass the relevant tests. For each file Foo.jack, there is a corresponding test in the provided FooTest directory. Note that a few of these tests are automated, with a .tst file that can be loaded in the VM emulator, but most you will need to test manually. In general, to test Foo.jack, you should

    • Copy your Foo.jack file into the FooTest folder.
    • Run a Jack compiler on the FooTest folder to generate Main.vm and Foo.vm (you can use your own Jack compiler if you wish, but you are also welcome to use the JackCompiler provided with the nand2tetris materials).
    • If there is a .tst file in the folder, load it in the VM emulator. Otherwise, simply load the FooTest folder itself. In either case, the VM emulator will use built-in implementations of all OS functions except that it will use your functions from Foo.jack. This way you can test each file in isolation.
    • Make sure the test works as required (see the comments and code in each Main.jack file for information on what to expect).

    Finally, to get credit for Part B (or whichever part you happen to do second), it must also be possible to compile and run the Pong game using your complete OS implementation in place of the built-in one.

  • Jack error codes (for reference)
Code OS API Source Meaning
1 Sys.wait Duration must be positive
2 Array.new Array size must be positive
3 Math.divide Division by zero
4 Math.sqrt Cannot compute square root of a negative number
5 Memory.alloc Allocated memory size must be positive
6 Memory.alloc Heap overflow
7 Screen.drawPixel Illegal pixel coordinates
8 Screen.drawLine Illegal line coordinates
9 Screen.drawRectangle Illegal rectangle coordinates
12 Screen.drawCircle Illegal center coordinates
13 Screen.drawCircle Illegal radius
14 String.new Maximum length must be non-negative
15 String.charAt String index out of bounds
16 String.setCharAt String index out of bounds
17 String.appendChar String is full
18 String.eraseLastChar String is empty
19 String.setInt Insufficient string capacity
20 Output.moveCursor Illegal cursor location