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 116,325 of 117,927   
   Hans Bezemer to Stephen Pelc   
   Re: VALUE - the good, the bad and the ug   
   20 Mar 24 14:19:19   
   
   From: the.beez.speaks@gmail.com   
      
   On 20-03-2024 12:37, Stephen Pelc wrote:   
   > VFX Forth defines the operators such as TO and -> as immediate words that   
   just   
   > set   
   > a variable. The child of value just inspects the variable. No parsing needed   
   > and it   
   > fits the "as if parsing" requirement of ANS/Forth2012. IMHO it also leads to   
   > simpler   
   > implementation and allows for reuse of operators.   
   In 4tH, VALUE is considered to be a dereferenced VARIABLE. As you all   
   know, VARIABLE returns an address and ! and @ act on that address.   
      
   TO "knows" it has to act on a dereferenced VARIABLE - and has its own   
   opcode. VALUE has its own opcode too (with a "builtin" @).   
      
   4tH's optimizer does strength reduction in that regard. When compiling   
      
   	VARIABLE a 10 a !   
      
   It actually compiles a "TO":   
      
      Addr| Opcode                        Operand   
         0| literal                            10   
         1| to                                  0   
      
   Since the address of the VARIABLE is known at runtime. Same for fetching   
   the value of a VARIABLE - it is treated as a VALUE.   
      
   On the other hand, the extension +TO is expanded as an +! expression:   
      
      Addr| Opcode                        Operand   
      
         0| literal                            10   
         1| to                                  0 ( 10 a !)   
         2| value                               0 ( a @)   
         3| literal                            20   
         4| to                                  1 ( 20 value b)   
         5| literal                            10   
         6| variable                            1   
         7| +!                                  0 ( 10 +to b)   
      
   In short - in 4tH there is hardly any difference between VALUE and   
   VARIABLE. They can be used interchangeably. The actual code that is   
   generated is decided under the hood.   
      
   Hans Bezemer   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

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


(c) 1994,  bbs@darkrealms.ca