home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,140 of 117,927   
   Hans Bezemer to albert@spenarnc.xs4all.nl   
   Re: Locals revisited   
   26 Mar 25 14:13:42   
   
   From: the.beez.speaks@gmail.com   
      
   On 25-03-2025 15:01, albert@spenarnc.xs4all.nl wrote:   
   > 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.   
      
   This one https://theforth.net/package/co uses a circular buffer to   
   manage co-routines. It works - even on 4tH. I could implement your   
   proposal in high level Forth in a heartbeat, of course, but it seems   
   like Ouatu Bogdan Ionut had a similar idea. ;-)   
      
   Hans Bezemer   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca