6.1.1240 DO CORE

Interpretation:

Interpretation semantics for this word are undefined.

Compilation:

( C: -- do-sys )

Place do-sys onto the control-flow stack. Append the run-time semantics given below to the current definition. The semantics are incomplete until resolved by a consumer of do-sys such as LOOP.

Run-time:

( n1 | u1 n2 | u2 -- ) ( R: -- loop-sys )

Set up loop control parameters with index n2 | u2 and limit n1 | u1. An ambiguous condition exists if n1 | u1 and n2 | u2 are not both the same type. Anything already on the return stack becomes unavailable until the loop-control parameters are discarded.

See:

Rationale:

Typical use:

   : X ... limit first DO ... LOOP ;

or

   : X ... limit first DO ... step +LOOP ;

Testing:

ContributeContributions

lmravatar of lmr [331] loopsys in data?Request for clarification2024-01-08 06:17:40

Would it be conforming for an implementation to generate a new loopsys in data space for every DO ever compiled (and keep track of which loopsys is current during compilation, for example using the control or return stack)? This would of course (permanently) waste data space, compared to the "normal" way of (temporarily) consuming return-stack space.

AntonErtlavatar of AntonErtl

Such an implementation would be standard.

Conceptually system-internal data generated during compilation is not part of data space even if it is interleaved with data space data (at least parts of the standard handle it this way; not sure if the standard is consistent here).

Closed

ruvavatar of ruv

Would it be conforming for an implementation to generate a new loopsys in data space for every DO ever compiled

Usually, a loop-sys is created in run-time.

An implementation may allocate data space while performing the compilation semantics for DO, but it is not allowed to allocate data space while performing the run-time semantics for DO.

If you allocate a slot for loop-sys at compile time, it will not work correctly in run-time when recursion occurs (directly or indirectly) — the slot will be overwritten and not restored.

lmravatar of lmr

If you allocate a slot for loop-sys at compile time, it will not work correctly in run-time when recursion occurs (directly or indirectly) — the slot will be overwritten and not restored.

That's it. This means DO introduces the equivalent of subroutine-local variables, which must be stored on the "call stack" (return stack in Forth) for recursion to work, just like in other languages.

Reply New Version