Sujet : Re: ADDRESSABLE: value-flavoured words
De : stephen (at) *nospam* vfxforth.com (Stephen Pelc)
Groupes : comp.lang.forthDate : 12. May 2025, 11:55:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vvsk2k$127bb$1@dont-email.me>
References : 1
User-Agent : Usenapp for MacOS
On 12 May 2025 at 09:40:32 CEST, "Anton Ertl" <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.
VFX Forth and other MPE/W&P Forths have had ADDR for decades.
I think that there two flaws in the argument above
1) The use of ADDR or &OF is quite rare and often specialised,
2) All uses that require ADDR can be satisfied using a buffer.
My use of ADDR has significantly reduced over the last ten years.
I would propose that a more satidfying solution is to add local
buffers, which are decades old in MPE/W&P Forths. MPE uses
a notation that others object to for local buffers, but AFAIR someone
had a good notation and implementation that was published. Here
are two examples of local buffer use. Both are taken from the VFX Forth
kernel and demonstrate convenience for operating system
Interfacing.
Local buffers are defined using a trailing '[' character at the end of
local variable name, e.g.
IOBUFF[ cell ]
followed by the buffer size and a trailing '] '
NXCALLx is a call to a shared library function:
px ... p1 address NXCALLx \ x=#parameters, address = function entry
NXCALL is a low level integer function used before the EXTERN:
interface has been compiled.
\ int chmod(const char *path, mode_t mode);
: (OS_Chmod) { c-addr u mode | zaddr[ #1024 ] -- ior }
c-addr u zaddr[ zplace
zaddr[ mode dll_chmod @ nxcall2
0=
;
: (OS_Key) \ -- key
{ | iobuff[ cell ] -- char }
?PrepTerm
stdin @ iobuff[ 1 dll_ReadFile @ nxcall3 drop
iobuff[ c@
;
All VFX Forth downloads include the source code.
Stephen