programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: How to make 2Value?

From: Charles Melice <3d_at_forthcad.com>
Date: Wed, 7 Feb 2007 14:52:28 +0100

To answers your exact question:

I think the next definition is evident...

    : 2value ( a b "name" -- )
        create
        , ,
      does> ( addr -- a b )
        2@ ;

2TO have to be a "state smart word": its running action
is not the same when it is in "compile time" and when it
is in "interpret time" ==> "state smart":

When interpreting, I think the next 2TO behavior is easy
to anderstand:

: 2TO-INTERPRET-VERSION ( a b -- )
    ' >body 2! ;

When compiling, the next definition will translates the
parsed "2value-name" into a variable address :

: [2TO-COMPILE-VERSION] ( "2value-name" -- )
    ' >body \ compute address of the next 2value
    postpone literal \ compile the address as a literal
    postpone 2! \ compile 2! behavior
; immediate

This last definition have to be immediate, because what we
want is to compile {address 2!} inside the definition when
2TO will be executed.

Now, the unified, "state-smart" definition :

    : 2TO ( a b "name" -- )
        ' >body
        state @ IF
            postpone literal
            postpone 2!
        ELSE
            2!
        THEN ; immediate

Notice that you can replace 2TO with TO, because TO
is initially designed to be polymorphic: TO can
check its target (a VALUE, a 2VALUE, ...), and take
the right decision. But that's another story.

Charles

----- Original Message -----
From: "Morten A. Steien" <morten.steien_at_chello.no>
To: <sftalk_at_forth.com>
Sent: Wednesday, February 07, 2007 1:59 PM
Subject: [sftalk] How to make 2Value?

>I would like to make a double version of VALUE and TO.

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Wed Feb 07 2007 - 05:53:28 PST

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:41 PST