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,137 of 117,927    |
|    Hans Bezemer to dxf    |
|    Re: Back & Forth - Co-routines    |
|    21 Mar 25 13:27:45    |
   
   From: the.beez.speaks@gmail.com   
      
   On 21-03-2025 08:45, dxf wrote:   
   > On 21/03/2025 11:38 am, dxf wrote:   
   >> On 20/03/2025 11:07 pm, Hans Bezemer wrote:   
   >>> ...   
   >>> But the major problem is that ' doesn't return an XT, but just a relative   
   address. Without applying >BODY I can't retrieve the original address. So, in   
   order to make this work, I have to redefine it to accommodate those   
   restrictions:   
   >>>   
   >>> : (local) ( x xt -- ) r> -rot >body dup @ over 2>r ! ;: 2r> ! ;   
   >>>   
   >>> Back ported to Gforth - it works!   
   >>> ...   
   >>   
   >> Slightly smaller (for me) and not less portable. Thanks!   
   >   
   > The run-time code can be reduced further by relocating >BODY ...   
   >   
   > : (local) ( x adr -- ) r> -rot dup @ over 2>r ! ;: 2r> ! ;   
   >   
   > : LOCAL ( x "name" -- )   
   > ' >body postpone literal postpone (local) ; immediate   
      
   That's essentially the trick I pulled when recreating the Forth-200x   
   LOCALS. Under the hood the 4tH preprocessor created the global VALUES   
   and then used this to transfer the address of the VALUES to LOCAL:   
      
   : local r> swap dup >r @ >r ;: r> r> ! ;   
      
   ( definition using locals)   
   [UNDEFINED] a [IF] 0 value a [THEN]   
   ['] a >BODY LOCAL   
   TO a   
      
   .. which has pretty much the same effect as your construct, but needs   
   the 4tH preprocessor to be more involved.   
      
   Nice test - I bet it wouldn't be too hard to implement at least part of   
   the Forth-200x implementation ;-)   
      
   Sometin' like define {:   
   1. Parse a word;   
   2. If not :} then create a (local);   
   3. Repeat.   
      
   Ok, this is horrible code, it needs the VALUES in reverse, but it works:   
      
   : :} ;   
   : {: begin ' dup ['] :} <> while >body postpone literal postpone (local)   
   repeat drop ; immediate   
      
   : test {: b a :} a b / ;   
      
   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