Hiya. My study group is finally on chapter 9 and I'm having a hard time figuring out if something is my fault or not. Normally, I'm not prone to blame my tools, but I'm running out of things to blame at this point. :)
I'm planning on writing something akin to asteroids and I'm doing a basic OO design and it looks like my debugging code is what is causing my crash. I'm using the java built-ins so that the program runs faster and after just a couple of seconds I get a crash. The stack trace looks like:
Sys.init
Main.main
Grid.go
Grid.debug
Ship.debug
String.new
Memory.alloc
Sys.error
... repeat last 3 ad-nauseum ...
Ship.debug looks like:
method void debug() {
do Output.moveCursor(0, 0);
do Output.printString("x = ");
do Output.printInt(x);
do Output.moveCursor(1, 0);
do Output.printString("y = ");
do Output.printInt(y);
return;
}
Looking at the compiled (via the supplied compiler) VM code you can see:
call String.new 1
push constant 120
call String.appendChar 2
push constant 32
call String.appendChar 2
push constant 61
call String.appendChar 2
push constant 32
call String.appendChar 2
call Output.printString 1
I'm not actually supposed to dealloc string literals, am I? I didn't see anything to that effect in the book. That would imply that Figures 9.2 and 9.3c have leaks in them. Right?
Obviously I'm going to turn off the debugging code at some point, but presumably I should be able to display the running score or level timer or something throughout a game.
Suggestions?