Locals revisited

Liste des GroupesRevenir à cl forth 
Sujet : Locals revisited
De : albert (at) *nospam* spenarnc.xs4all.nl
Groupes : comp.lang.forth
Date : 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 Wall
Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
And Gifts For Friends Family And Colleagues.

Date Sujet#  Auteur
25 Mar 25 * Locals revisited12albert
26 Mar 25 `* Re: Locals revisited11Paul Rubin
27 Mar 25  +* Re: Locals revisited2mhx
27 Mar 25  i`- Stacks (was: Locals revisited)1Anton Ertl
27 Mar 25  +* Re: Locals revisited4Anton Ertl
27 Mar 25  i+- Re: Locals revisited1albert
27 Mar 25  i`* Re: Locals revisited2Paul Rubin
28 Mar 25  i `- Re: Locals revisited1Anton Ertl
28 Mar 25  `* Re: Locals revisited4dxf
30 Mar 25   `* Re: Locals revisited3dxf
30 Mar 25    `* Re: Locals revisited2dxf
31 Mar 25     `- Re: Locals revisited1sjack

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal