jack compiler does not return result

classic Classic list List threaded Threaded
7 messages Options
JM
Reply | Threaded
Open this post in threaded view
|

jack compiler does not return result

JM
I'm making a tetris game for this project and slowly putting together its major components. Currently, I have code written for each type of game piece, as well as their player-controlled movements. I have all this functionality written as various methods inside a single class. Before I added methods to this class that allow for lateral and downward movement, the jack compiler compiled all my game files in just a few seconds. However, after these additions to my code the compiler doesn't return anything from the command line (It says "Compiling [file path]", which I assume means it's trying to do something, but it's not clear what). Anyone have an idea of what's happening? If you need to see my code I'll of course be happy to share it.

Thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: jack compiler does not return result

WBahn
Administrator
I'm a bit confused. You said that you have all this functionality in a single class but later refer to all of the game files. How many .jack files constitute your overall program?

What happens if you compile them individually? Are you able to get through them all, or does it hang on one of them?
JM
Reply | Threaded
Open this post in threaded view
|

Re: jack compiler does not return result

JM
Sorry, I realized I didn't make a few things clear in my original post above. To clarify:

1. My game currently consists of 3 .jack files. The first, titled "gamePiece," contains all the methods I need to generate and move the tetris game pieces. The second, titled "Testgame," contains methods to test the code in my gamePiece class--specifically, it's currently written to test whether the game pieces move as intended. The third is the Main class, which just implements the contrived test game I've written.

2. I think the compiler is getting hung up with the gamePiece file. I've noticed two things. First, if I deliberately include a syntax error in an early line of code (e.g., by removing a semicolon in one of the first twenty lines), the compiler will catch that and throw an error message. (However, it will not fully return; it seems to want to continue checking the rest of the code first.) Second, as soon as I run the compiler a gamePiece.vm file appears in the file folder, but it is empty.
JM
Reply | Threaded
Open this post in threaded view
|

Re: jack compiler does not return result

JM
So I think I realized what the problem was. I had lines like this in a couple of places in my code:

if(var = a or var = b) {

....code.....

}

Just as a warning to others working through this project, remember to read the documentation carefully! Jack does not recognize "or" as a boolean operator. I believe the correct syntax is if(var = a | var = b) { .... }

Also, and perhaps more importantly, the compiler will not always throw you an error when there's something wrong with your code. It might just get hung up somewhere.
Reply | Threaded
Open this post in threaded view
|

Re: jack compiler does not return result

WBahn
Administrator
In reply to this post by JM
JM wrote
Sorry, I realized I didn't make a few things clear in my original post above. To clarify:

1. My game currently consists of 3 .jack files. The first, titled "gamePiece," contains all the methods I need to generate and move the tetris game pieces. The second, titled "Testgame," contains methods to test the code in my gamePiece class--specifically, it's currently written to test whether the game pieces move as intended. The third is the Main class, which just implements the contrived test game I've written.

2. I think the compiler is getting hung up with the gamePiece file. I've noticed two things. First, if I deliberately include a syntax error in an early line of code (e.g., by removing a semicolon in one of the first twenty lines), the compiler will catch that and throw an error message. (However, it will not fully return; it seems to want to continue checking the rest of the code first.) Second, as soon as I run the compiler a gamePiece.vm file appears in the file folder, but it is empty.
So what you can do if focus on narrower and narrower pieces of your code.

Take you gamePiece.jack file remove the first half of the functions. If the compiler finishes then the problem is in that half, if not then the problem (or at least one of them) is in the second half. If it finishes, replace the functions you removed and get rid of all the others. Then continue by removing half of the remaining functions. Once you find the function that is causing the problem, proceed along similar lines by removing about half the code, keeping in mind that you need to remove entire statements or blocks of code at a time. You should be able to narrow things down to a specific statement pretty quickly this way.
Reply | Threaded
Open this post in threaded view
|

Re: jack compiler does not return result

WBahn
Administrator
In reply to this post by JM
JM wrote
So I think I realized what the problem was. I had lines like this in a couple of places in my code:

if(var = a or var = b) {

....code.....

}

Just as a warning to others working through this project, remember to read the documentation carefully! Jack does not recognize "or" as a boolean operator. I believe the correct syntax is if(var = a | var = b) { .... }

Also, and perhaps more importantly, the compiler will not always throw you an error when there's something wrong with your code. It might just get hung up somewhere.
Yes, like any language it expects you to constrain yourself to the defined operators. But you have some other issues.

First, 'var' is a keyword, so don't use it as a variable name.

Second, even after you "fix" the code you have an operator precedence issue.

The authors are very careful to point out (See Section 9.2.5) that operator precedence and order of evaluation is NOT defined beyond evaluating expressions within parentheses first.

So the code

if (varName1 = varName2 | varName1 = varName3)

could be evaluate in any one of six possible ways. The most likely is simply from left to right (with right to left being second most likely):

if (((varName1 = varName2) | varName1) = varName3)

This will not do what you want. You need to be extremely careful with Jack to put in sufficient parens in order to FORCE the compiler to evaluate expressions in the manner you want.

So you really, really, really need to write this as:

if ( (varName1 = varName2) | (varName1 = varName3) )


JM
Reply | Threaded
Open this post in threaded view
|

Re: jack compiler does not return result

JM
By "var" I meant "var_name" i.e., a stand-in for whatever the variable name actually is (I guess I need to work on making myself more clear!)

Your point about operator precedence/order of operations is well taken though. I've actually managed to avoid all this hassle by changing my if statements a bit (in some places by making nested if statements), but it's a good reminder nonetheless.

Thanks as always for taking the time to help those of us working through the book.