Digest #245 2023-12-25
Contributions
QUIT
must clear the return stack. But is there any part of the spec that mentions clearing the control stack? I don't see any mention of that in QUIT
, THROW
, ABORT
or :
.
Replies
The control-flow stack may be (and usually is) on the data stack, so the obvious intent is that QUIT preserves it, and that THROW and ABORT restore it to the depth it had at the CATCH that caches the ball. However, the exception wordset chapter mentions the control-flow stack only in the names of exceptions, not as something that THROW should restore. And I don't find any such requirement elsewhere. I think we should fix this in the document.
BTW, if you are thinking about "system-execution types" like nest-sys and loop-sys, they are specified to be conceptually on the return stack. If you place them elsewhere, they have to follow the changes on the return stack. In particular, they have to be restored on THROW, CATCH and eliminated at QUIT.
Recently a bug was found that hit two Forth systems that independently decided to keep the loop-control parameters in registers, and failed to restore them on THROW.
that QUIT preserves it, and that THROW and ABORT restore it to the depth it had at the CATCH that caches the ball
... and that (to be pedantic), subsequently, THROW
and ABORT
clear the data stack — that is specified
control-flow stack may be (and usually is) on the data stack
Actually I've never quite understood the rules for manipulating the data stack while STATE
= -1 (via [
]
or immediate words). Do not let pushed items cross control-flow primitive boundaries (IF
AHEAD
etc)? Is this clearly specified for "standard programs" anywhere?