ForthHub / standard-evolution

Evolving of the Forth Standard, sketches, issues and discussions
0 stars 0 forks source link

Control-flow stack for `i`, `j`, `leave`, `unloop` #7

Open ruv opened 11 months ago

ruv commented 11 months ago

When the compilation semantics for the words i, j, leave, unloop are performed, at least one do-sys must be present on the control-flow stack (and two do-sys in the case of j).

But currently a system cannot check this fact and cannot throw an exception if these words are used not within do...loop, because the control-flow stack diagram is not specified for compilation semantics. A system may only check in run-time if loop-sys is present on the top of the return stack and throw an exception if not — since loop-sys is specified in the stack diagrams.

We should specify compilation semantics for these words, with control-flow stack diagrams like: ( C: do-sys i*x -- do-sys i*x ), or ( C: do-sys2 i*x do-sys1 j*x -- do-sys2 i*x do-sys1 j*x ) for the word j.

It will allow a system to formally check do-sys at compile-time and throw an exception if these words are used incorrectly in compile-time (according to 3.1, which says: "An ambiguous condition exists if an incorrectly typed data object is encountered").

See also

ruv commented 4 months ago

A similar issue exists for the of word. Currently the spec says:

Compilation: ( C: -- of-sys )

But it should say:

Compilation: ( C: case-sys -- case-sys of-sys )