Target VALUE and local variables

The file COMMON\METHODS.FTH implements the compilation of VALUEs and the ANS Forth LOCALS| syntax for compilation on the target. Compilation of this file requires CPU dependent support, usually called LOCAL.FTH in the %CpuDir% directory, and MPE standard control files will compile these files if the equate TARGET-LOCALS? is set non-zero in the control file.

Note that this file is only provided for full ANS compliance. The MPE extended local variable syntax is provided by the cross compiler, and is much more powerful and more readable.

Note also that compilation of %CpuDir%\LOCAL.FTH may be required if you cross compile words with more than four input arguments.

: OPERATOR      \ n -- ; define an operator in the cross compiler
An interpreter definition that build new operators such as "to" and "addr".

: VALUE         \ n -- ; --  n ; n VALUE <name>
Creates a variable of initial value n that returns its contents when referenced. To store to a child of VALUE use "n to <child>".

: (LOCAL)       \ Comp: c-addr u -- ; Exec: -- x ; define local var
When executed during compilation, defines a local variable whose name is given by c-addr/u. If u is zero, c-addr is ignored and compilation of local variables is assumed to finish. When the word containing the local variable executes, the local variable is initialised from the stack. When the local variable executes, its value is returned. The local variable may be written to by preceding its name with TO. This word is provided for the construction of user-defined local variable notations. This word is only provided for ANS compatibility, and locals created by it cannot be optimised by the VFX code generator.

: LOCALS|       \ "name...name |" --
Create named local variables <name1> to <namen>. At run time the stack effect is ( xn..x1 -- ), such that <name1> is initialised with x1 and <namen> is initialised with xn. Note that this means that the order of declaration is the reverse of the order used in stack comments! When referenced, a local variable returns its value. To write to a local, precede its name with TO.

In the example below, a and b are named inputs.


: foo      \ a b --
  locals| b a |
  a b +  cr .
  a b *  cr .
;