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

Re: EQU Inside Colon Definitions

From: Elizabeth D. Rather <erather_at_forth.com>
Date: Wed, 21 Mar 2001 12:17:44 -0800

At 01:09 PM 3/21/01 -0600, Dennis W. Bulgrien wrote:

>It does help, a lot more than the SwiftX Reference Manual, 3.4 DEFINING
>WORDS. The word I was really trying to understand was a
>little more removed but works the same as ACE:.
> INTERPRETER : +DATA ( n1 n2 -- n3 ) SWAP DUP ( n2 n1 n1 ) EQU (
> n2 n1 ) + ;
>I didn't think about it looking forward beyond the actual call of the word
>containing it. Although familiarizing myself with
>cross-compiler principles is a very good idea, I don't think it would have
>taught me this. Perhaps a little explanation and
>example like you gave me added to the manual would benefit others as well.

Defining words are no different from most Forth words, in that when you use
them inside a colon definition they're executed when the definition is
executed. Therefore, when you use them inside a colon definition you make
that into a defining word itself The only exception to the rule that words
invoked in a definition are executed when the definition is executed is a
small class of "IMMEDIATE" words, which include the flow-of-control
structure words such as IF, DO, LOOP, BEGIN, etc., and a few others such as
(, ,(, etc.

You are correct that the discussion in the SwiftX Reference Manual assumes
that you already understand the use and creation of defining words, and
focuses on differences in the Cross Compiler. Basic principles of defining
words are discussed in the Forth Programmer's Handbook, Section 4.2 (in
general) and 4.2.6 (custom defining words) in particular. In 4.2.6,
there's discussion of DOES>, which allows you to assign a custom instance
behavior to new defining words you make. In the example you give, the
instance behavior of EQU (return the value if interpreting, compile a
literal if compiling) is acceptable, so DOES> isn't needed.

Cheers,
Elizabeth

>-----Original Message-----
>From: swiftx-bounce_at_forth.com [mailto:swiftx-bounce_at_forth.com]On Behalf
>Of Rick VanNorman
>Sent: Wednesday, March 21, 2001 11:50 AM
>To: swiftx_at_forth.com
>Subject: [swiftx] Re: EQU Inside Colon Definitions
>
>
>
>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!
>
>----------------------------------------------------------------------
>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!

================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310-491-3356
5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454
Los Angeles, CA 90250
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
================================================

----------------------------------------------------------------------
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 - 12:21:00 PST

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