Sujet : Locals revisited
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forthDate : 25. Mar 2025, 15:01:37
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$6218682b$184a5797@0b341edb9d03c6de>
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In hindsight my locals definition is not convincing,
because carnal knowledge about the behaviour of
the return stack is required.
"
: local R> SWAP DUP >R @ >R >R CO R> R> ! ;
VARIABLE A
VARIABLE B
: divide
A local
B local
B ! A ! A @ B @ /
. CR
;
15 3 divide
"
Imagine a RiscV processor. Every low level word, doesn't use
the return stack, but uses a link register, so the above
probably doesn't work on a riscV.
To abstract of this you need an extra stack, for example
the "system stack" from Marcel Hendrix.
In the above it is necessary to temporarily store the return
information
: local
R> \ Return address
SWAP DUP >R @ >R \ Abuse return stack for extra storage
>R \ Restore return address
CO
R> R> ! \ Further abuse
;
With the "system stack" it becomes :
"
: local DUP >S @ >S CO S> S> ! ;
VARIABLE A
VARIABLE B
: divide
A local
B local
B ! A ! A @ B @ /
. CR
;
15 3 divide
"
Don't ask me these questions:
If you have an extra stack, why not use a locals stack?
R R> R@ 2R> etc. are a poor mans tool. Isn't it time to
replace them with >S S> S@ 2S> etc. and terminate all worries
these facilities interfere with other stuff?
(I get 30 registers in RISCV that can serve as a stack pointer.)
Groetjes Albert.
-- Temu exploits Christians: (Disclaimer, only 10 apostles)Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style WallArt For Home, Office And Garden Decor - Perfect For Windows, Bars,And Gifts For Friends Family And Colleagues.