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

From: Mike Ghan <mikeghan_at_logix-controls.com>
Date: Thu, 10 Jan 2002 20:56:46 -0800

Richard, I'm not sure what my_strange_pointer is for so I may be
missing something.

While ' my_pointer >BODY ... CONSTANT currently works, it may get
you into trouble. It definitely will break if you make a DLL. 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 ;

Hope this helps,
Mike

-----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.

----------------------------------------------------------------------
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 Thu Jan 10 2002 - 20:58:22 PST


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 08-Feb-2012. Archive updated nightly.