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

Re: An "alias" for a location defined by VALUE

From: Richard Owlett <rowlett_at_atlascomm.net>
Date: Fri, 11 Jan 2002 09:22:40 -0600

Mike Ghan wrote:
>
> Richard, I'm not sure what my_strange_pointer is for so I may be
> missing something.

Essentially a dummy, but defining it helped to visualize my memory map.

address contents
CELL 0 Parameter Field of my_pointer
                 ( by analogy to fig 10 p 138 of _Forth Programmer's
Handbook_ )
CELL 1 - n space ALLOTed for my string

>
> While ' my_pointer >BODY ... CONSTANT currently works, it may get
> you into trouble. It definitely will break if you make a DLL.

Would ' my_pointer >BODY ... VALUE be any better?

> Why not code as follows?
>
> 0 VALUE my_pointer
>
> CREATE my_storage 10000 CELL+ /ALLOT
>
> : my_buffer my_storage CELL+ ;
>
> :ONSYSLOAD my_buffer TO my_pointer ;
>
> If you need to reference my_pointer's data, the address should be
> resolved at runtime:
>
> : my_pointer_address ( -- addr ) ['] my_pointer >BODY ;
>
>

It would not allow me to pass only one item on the stack to a routine
which needed to manipulate the data in CELL 0 and the string beginning
at CELL 1 .

e.g. routine such as

: my_append ( c-addr u a_buffer_address -- )
  DUP 1 CELLS - >R OVER >R SWAP MOVE R> R> OVER @ + SWAP ! ;

My "kluge sensor" is beginning to blink caution ;}

> -----Original Message-----
> From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On
> Behalf
> Of Richard Owlett
> Sent: Thursday, January 10, 2002 12:38 PM
> To: sftalk_at_forth.com
> Subject: [sftalk] An "alias" for a location defined by VALUE
>
> I am working on a problem which manipulates several VERY long strings
> -- typically 1K to 10K with a weird case that may approach 300K.
>
> It logical to consider a contiguous portion of the string either as a
> single string or as a concatenation of random length records ( the
> offset of each record is known/knowable). A combination of factors
> makes
> it convenient to describe strings with a "start address", "end address
> +
> 1" instead of the typical address, count format.
>
> I'm experimenting with a structure created with the following code
> fragment:
>
> 0 VALUE my_pointer
> ' my_pointer >BODY
> 10000 1 CELLS + /ALLOT
> DUP CONSTANT my_strange_pointer
> 1 CELLS + CONSTANT my_buffer
> my_buffer TO my_pointer
>
> This allows me to use "my_pointer" | "TO my_pointer" to conveniently
> access the next available memory location.
> It also allows me to place only one parameter ( my_buffer ) on the
> stack
> prior to executing a word which needs to manipulate both my_pointer
> and
> my_buffer.
>
> That is
>
> 1234 TO my_pointer would be equivalent to 1234 my_buffer 1
> CELLS - !
>
> or
>
> my_pointer would be equivalent to
> my_strange_pointer
> @
>
> The format would depend on which is easier to read. ( A subjective
> judgment as compiled code size and execution speed are irrelevant. )
>
> Am I missing any "gotcha's" ?
>
>
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" 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/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Fri Jan 11 2002 - 07:30:09 PST

This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:21 PST