Digest #245 2023-12-25

Contributions

[324] 2023-12-24 03:10:07 lmr wrote:

requestClarification - control stack clearing?

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

[r1148] 2023-12-24 15:50:50 AntonErtl replies:

requestClarification - control stack clearing?

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.


[r1149] 2023-12-24 15:58:11 AntonErtl replies:

requestClarification - control stack clearing?

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.


[r1150] 2023-12-24 19:16:57 lmr replies:

requestClarification - control stack clearing?

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


[r1151] 2023-12-24 22:44:43 lmr replies:

requestClarification - control stack clearing?

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?