(EDIT: Added line breaks to make the example look less ugly. hackvm.py seems to allow them when interpreting the code)
Code: Select all
12+
4+
8+
82*+
84*+
88*+
88*2*+
88*4*+
88*8*+
88*8*2*+
88*8*4*+
88*8*8*+
88*8*8*2*+
88*8*8*4*+
88*8*8*8*+
88*8*8*8*2*+
88*8*8*8*4*+
88*8*8*8*8*+
88*8*8*8*8*2*+
88*8*8*8*8*4*+
88*8*8*8*8*8*+
88*8*8*8*8*8*2*+
88*8*8*8*8*8*4*+
88*8*8*8*8*8*8*+
88*8*8*8*8*8*8*2*+
88*8*8*8*8*8*8*4*+
88*8*8*8*8*8*8*8*+
88*8*8*8*8*8*8*8*2*+
88*8*8*8*8*8*8*8*4*+
88*8*8*8*8*8*8*8*8*+p!
Now, what happens if I add 1 to that? The result printed is 2147483648. I don't know how this would be possible, since this number cannot be held in a signed 32-bit integer. I would either expect an error message ("integer overflow", this is what happens in the JavaScript implementation), or a "wrap around" to the number -2147483648, but neither of that happens using the official implementation (hackvm.py).
So, is my understanding of things wrong here, or is this an error in the Python implementation of the HVM? Or is the HVM working correctly, and it is rather the documentation which is erroneous?