Due Date: 2015-3-22, 11:59pm
This assignment is designed to get you more familiar with the Jack programming language (before we start disecting it with the compiler). The first part is open-ended, in which you write a program of your choice. The second part is to implement some of the Jack "OS" by filling out some of the available libraries.
Part I: Open Ended Jack
What the program does is up to you, but it must contain these elements.
- Two or more classes (Main.jack and at least one more)
- Capacity to take input from the keyboard.
- Visualizations on the screen, in both text and graphics.
Your code should be put in the MyCode directory of the 08 folder. You should describe the intended effect of your program in a README.txt. Your grade for the first part will be mostly for whether your program does what you said it would, but 10% of your final grade for this assignment will be based on polish/ambition. You are expected to make an actual application, and not just do some bare minimum of coding. Make something cool. Have fun with it. And along the way, hopefully you'll become more familiar with the language.
Note you can use all of the OS/standard libraries without having implemented them.
Part II: Jack OS
Write Jack code that implements the following four operating system/standard libraries.
Each class will be compiled and tested in isolation. Note that Array and Math come with a standard tst and cmp file so that you can check your output precisely. String and Keyboard need to be tested interactively/by comparing your implementation's output to the provided screenshot gif. When you run into an error condition, you should call Sys.error
with the appropriate error code.
- To get you started, here is a demo Jack program.
- Also, if you'd like, here's a Pseudo-random number class for you.
- Jack API
- After you write your code, you can compile it with the built-in JackCompiler into vm files, which you can then run in the VMEmulator.
- Array - The reason the "constructor" is a function and not a constructor is because you need to call Memory.alloc manually. All the other constructors will allocate space automatically. Also note that we will implement the bracket notation in the language, not the class. Array really is as simple as calling the two appropriate methods from Memory.
- Math - The pseudo-code for multiply/divide will only work for positive numbers, which is why it's called divideP. To make the actual functions, you will need to flip the signs in a couple places in some cases. Also, if you multiply y by 2 too many times, you will get some overflow, making y negative, so make sure that y > 0. The same goes for (y+2^j)^2 in sqrt.
- String - If you do not check to make sure your maximum string length is greater than 0, the first test in Main.jack will lead to a stack overflow, since Array.new requires the size to be positive.