Nice program.
Here are some general comments about Jack programming.
Main.jack:
The built in type is 'boolean'. 'bool' is an object class, but since Jack is untyped, it makes no difference. My code was full of 'bool's until I added a warning to my Jack compiler to complain about them.
do Output.printString("Celluar Automata demo:");
Every time this line executes, it allocates a String object in the heap that is never deallocated. You need to do something like
let s = "Celluar Automata demo:";
do Output.printString(s);
do s.dispose();
to deallocate the string constants. This is such a PITA that I wrote a helper class OutUtil with functions like
function void printStringConst(String s) {
do Output.printString(s);
do s.dispose();
return;
}
CA.jack
field int row_size, ruleset_size, row_size;
row_size is declared twice. JackCompiler doesn't complain about it, mine does.
Utils.jack
Multiplication and division can really slow thing down. The Hack platform doesn't do a good job with right shifting, as you saw. Many algorithms that traditionally use right-shifting can be modified to use left-shifting (aka addition).
For instance bitAt() can be written something like this (typos included free of charge)
function int bitAt(int number, int bitPosition) {
bitPosition = 15-bitPosition;
while (bitPosition > 0) {
let number += number;
let bitPosition = bitPosition-1;
}
if (number < 0) { // test sign bit
return 1; }
return 0;
}
(Or if you want more obscure code, "return -(number < 0);" instead of the if and returns.)
--Mark