[comp.lang.forth] interpreted control structures

rob@idacom.uucp (Rob Chapman) (09/27/90)

>Michael Saari writes:
>
>Many of my examples used interactive "compile-only" words, such as:
>ok  begin  4000 c@ .   key? until
>11 11 11 11 11 11 11 11 11 11 11 11 11
>ok
>which is allowed in our versions of Forth (but not in the 83-Standard).
>Personally, I consider this a deficiency in the Standard.

Also to others who have used or created interpreted control structures:

Would the following work:

	CREATE crc-table  255 0 DO  I CRC-LOOKUP ,  LOOP

If I have interpreted control structures, I would like to use them at compile
time to initialize tables.  Are there systems that allow this?  And what are
the complexities/tradeoffs involved?

Interested,
Rob

wmb@MITCH.ENG.SUN.COM (09/27/90)

> Also to others who have used or created interpreted control structures:
>
> Would the following work:
>
>       CREATE crc-table  255 0 DO  I CRC-LOOKUP ,  LOOP
>
> If I have interpreted control structures, I would like to use them at compile
> time to initialize tables.  Are there systems that allow this?  And what are
> the complexities/tradeoffs involved?

The code that I published in the FORML proceedings did not allow this,
but my current implementation allows it, and the code the John Hayes
published in a recent Forth Dimensions allows it also.

To make it work, you have to switch the dictionary pointer to a separate
area (usually called a "compile buffer") while compiling the temporary
definition, and then switch the DP back to its original place just before
executing the temporary definition.

The tradeoffs are:

  1) The size of the compile buffer limits the maximum size of a temporary
     definition.

  2) You have to be careful that your ABORT mechanism puts the DP back to
     the right place if an ABORT happens during temporary compilation.
     (This is a good idea even if you don't use a separate compile buffer).

The compile buffer idea is very old.

Mitch Bradley, wmb@Eng.Sun.COM