The file COMMON\LOCALCOM.FTH implements the compilation of the ANS Forth LOCALS| syntax for compilation on the host. 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.
: (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.
|