pete_lin wrote
When i hava not read the chapter-8 ,i just think it is not a good idea let 0xFFFF as true.
now,maybe i have some point to say that.
The specification for if-goto from chapter 8 is:
if-goto
label This command effects a
conditional goto operation. The stack’s
topmost value is popped; if the value
is not zero, execution
continues from the location marked by the
label; otherwise,
execution continues from the next command in the program.
The jump destination must be located in the same function.
Therefore, FALSE must be 0 and
all non-zero values must be treated as TRUE.
Because the
and,
or and
not VM commands are
bit-wise arithmetic, the binary value for TRUE must have all its bits set. This is the value 0xFFFF.
Consider what happens in this code if TRUE had been assigned the value 1.
push constant 123
push constant 123
eq returns 0x0001
not returns 0xFFFE
if-goto not_equal jumps to not_equal !!!
If TRUE is 0xFFFF then the result of the
not will be 0x0000, and the
if-goto will function as desired.
this is my if-go command translate result write in python :
def write_if(label):
"""
if-goto
if D > 0 ,go
:param label:
:return:
"""
...
You need to change this to test for not equal instead of greater than.
--Mark