Re: ADDRESSABLE: value-flavoured words

Liste des GroupesRevenir à cl forth 
Sujet : Re: ADDRESSABLE: value-flavoured words
De : ruvim.pinka (at) *nospam* gmail.com (Ruvim)
Groupes : comp.lang.forth
Date : 13. May 2025, 20:36:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <10006vg$1rk75$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 2025-05-12 11:40, Anton Ertl wrote:
Programmers use value-flavoured words for various reasons.  In some
cases they want to have the address of the data otherwise accessed by
calling the value-flavoured word V or by using TO V.  Popular systems
have ADDR V or &OF V for taking the address.
 However, taking the address of the data means that (in the absence of
complicated, expensive, and unreliable alias analysis) any memory
access can access the data, so we are very limited in
register-allocating the data and/or in reordering the accesses to the
data.
 We want to avoid imposing such optimization obstacles when not
necessary.  Taking the address of data accessed through
value-flavoured words is rare: E.g., in the source of Gforth, there
are 130 uses of TO, but the only use of ADDR is for defining a synonym
(the SwiftForth name &OF), i.e., not to take the address of data.
Therefore we do not want to impose the optimization obstacles on all
value-flavoured words by supporting ADDR on all of them.
I searched GitHub for
   language:forth /^[^(\]*\s&OF\s+\S+/
`&of` is used in about 15 files (out of 39700 files), mostly from the Win32Forth project, and 3 files in other two projects (count only Forth code).
The request
   language:forth /^[^(\]*\sADDR\s+\S+/
returns about 900 results, and it's hard to find those few cases where `addr` is a counterpart to `to`. In most cases `addr` is a local variable.
This shows that `addr` is not a good name. Probably, `address-of` (following the form of `action-of`) is a better name than both `addr` and `&of`.
Overall, I'm not sure that using `address-of` (regardless of its name) is a good practice.

In the past, we introduced alternative defining words (VARUE etc.) for
defining value-flavoured words that support ADDR.  But we now have
around 20 words for defining VALUE-flavoured words that do not support
ADDR, and duplicating them for supporting ADDR seems excessive.  So
during the last days we implemented an alternative: If you want to
define a value-flavoured word which you can use with ADDR, you precede
the defining word with ADDRESSABLE:.  E.g.,
 5 addressable: value foo
7 addr foo +!
foo . \ prints 12
Why does this name end with a colon?
Just `addressable` (without a colon) looks better.

 or
 : bar {: addressable: x -- y :}
   5 addr x +! x ;
This declaration of `x` does not look good regardless of the colon.
--
Ruvim

Date Sujet#  Auteur
12 May 25 * ADDRESSABLE: value-flavoured words8Anton Ertl
12 May 25 +* Re: ADDRESSABLE: value-flavoured words2Stephen Pelc
12 May 25 i`- Re: ADDRESSABLE: value-flavoured words1Anton Ertl
13 May 25 +- Re: ADDRESSABLE: value-flavoured words1dxf
13 May 25 `* Re: ADDRESSABLE: value-flavoured words4Ruvim
13 May 25  +- Re: ADDRESSABLE: value-flavoured words1minforth
13 May 25  `* Re: ADDRESSABLE: value-flavoured words2Anton Ertl
14 May 25   `- Re: ADDRESSABLE: value-flavoured words1Ruvim

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal