|
In answering my own question, I believe that it can't be done. The reason I asked was to determine when to write the instruction 'pop temp 0' to ignore the void return value.
The conclusion I am coming to is that you handle this by only having the 'do' statements write 'pop temp 0' after making any subroutine call. The exception is Memory.alloc() which must pop to pointer 0 in the constructor. (I'm guessing outside of the constructor, if you use 'do Memory.alloc()' it will pop to temp 0 as well, but this command would be pretty useless because then you're throwing away the pointer to your block of memory).
And for 'let' statements, you would pop it to the variable that you are setting the right side to. But what about cases where you have 'let x = Xxx.yyy()' where Xxx.yyy() is a void subroutine? Should there ever be such a command like this? Because if it were allowed, wouldn't that mess up what's on the stack because you have an extra 0 on it the void return is pushed?
Would appreciate any feedback.
|