Closed tromp closed 10 months ago
I don't see how it would cause a problem. It would just harmlessly add zero to the memory location above the stack.
The memory location above the stack could be special memory that should not be read or written to.
It would be safer to zero the element to be dropped and add it to some byte read from a safe location and then written back there.
Sure, if this was some production C++ code then an out-of-bounds memory read would obviously be an issue. I think everybody can understand that.
In the context of a code-golfed assembly program I think it's safe to assume that the stack is in its explicitly-placed location.
That said, I suspect...
: drop sp@ ! ;
...would work fine too.
Oh; that's nice! Just overwrite the item to be dropped with itself first.
I like it.
: drop dup - + ;
implements (a b -- a) rather than (b -- ) it would fail on a stack containing only 1 element.