embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

Re: EQU Inside Colon Definitions

From: Rick VanNorman <rick_at_forth.com>
Date: Wed, 21 Mar 2001 09:49:51 -0800

Dennis,

The simplest way to explain EQU is that it gives you a free
way to name a constant. When you refer to a word defined by
EQU inside a colon definition, it is exactly like typing the
number. For instance:

14 EQU FOO
: BAR1 FOO 0 DO I . LOOP ;
: BAR2 14 0 DO I . LOOP ;

BAR1 and BAR2 compile exactly the same code.

The other way in which you have observed EQU being used is
as a word to help define other words -- extending the compiler.

The case you quote

>INTERPRETER
>: ACE: ( r -- ) 'ACE + EQU ;

Is where you want to define a set of constants by their offset
from a base address. For instance, if 'ACE is 128, then the following
definitions are equivalent:

0 ACE: FOO 128 0 + EQU FOO
1 ACE: BAR 128 1 + EQU BAR

etc.

Hope this helps.
Rick

*********** REPLY SEPARATOR ***********

On 3/21/2001 at 11:35 AM Dennis W. Bulgrien wrote:

>EQU help states "If ... referenced inside a target colon definition, its
>value will be compiled as a literal". Does this mean that
>if <name> or "EQU" is referenced? I found code with EQU inside an
>interpreter colon definition. I don't know what it does, other
>than popping a cell off the stack. Could someone explain it please?
>
>Example:
>--------
>\ ACE: defines registers in the TI dual ACE chip.
>\ 'ACE is the base address for the TI chip.
>
>Help:
>-----
>EQU <name>
>( x =97 )
>
>Define a one-cell constant in the host only, whose value is x. If an EQU
>is referenced inside a target colon definition, its value
>will be compiled as a literal. Execution of name returns x.
m

----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe swiftx" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/swiftx -- check them out!
Received on Wed Mar 21 2001 - 09:49:17 PST

This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:22 PST