Subject: | Buggy interpretation of stack underflows. |
Date: | Wed, 3 Oct 2007 20:42:12 -0600 |
To: | bug-Piet-Interpreter [...] rt.cpan.org |
From: | coppro <coppro [...] users.sourceforge.net> |
According to the Piet standard, if there is insufficient stack elements for
an operation to be performed, then the operation should not be performed.
Currently, this interpreter will pop all values off of the stack, and
nothing will happen. This is incorrect behavior (I suspect that the roll
operation has a similar, more insidious bug, but I'm far too lazy to check).
As an example:
+--+--+--+--+
| R|dR|dY|lR|
+--+--+--+--+
Disregarding that the program will get stuck in an infinite back-and-forth
loop, this will run the following three operations:
push (value of 1)
add
output as number.
This should, according to the standard, output a 1. But this implementation
will not output anything.
This can be implemented with simple checks for stack size in each of the
functions, or, even better, have a hash map of the minimal stack size for a
command.