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,322 of 117,927   
   Stephen Pelc to All   
   Re: ADDRESSABLE: value-flavoured words   
   12 May 25 10:55:16   
   
   From: stephen@vfxforth.com   
      
   On 12 May 2025 at 09:40:32 CEST, "Anton Ertl"  wrote:   
      
   > Programmers use value-flavoured words for various reasons.  In some   
   > cases they want to have the address of the data otherwise accessed by   
   > calling the value-flavoured word V or by using TO V.  Popular systems   
   > have ADDR V or &OF V for taking the address.   
   >   
   > However, taking the address of the data means that (in the absence of   
   > complicated, expensive, and unreliable alias analysis) any memory   
   > access can access the data, so we are very limited in   
   > register-allocating the data and/or in reordering the accesses to the   
   > data.   
      
   VFX Forth and other MPE/W&P Forths have had ADDR for decades.   
      
   I think that there two flaws in the argument above   
   1) The use of ADDR or &OF is quite rare and often specialised,   
   2) All uses that require ADDR can be satisfied using a buffer.   
   My use of ADDR has significantly reduced over the last ten years.   
      
   I would propose that a more satidfying solution is to add local   
   buffers, which are decades old in MPE/W&P Forths. MPE uses   
   a notation that others object to for local buffers, but AFAIR someone   
   had a good notation and implementation that was published. Here   
   are two examples of local buffer use. Both are taken from the VFX Forth   
   kernel and demonstrate convenience for operating system   
   Interfacing.   
      
   Local buffers are defined using a trailing '[' character at the end of   
   local variable name, e.g.   
     IOBUFF[ cell ]   
   followed by the buffer size and a trailing '] '   
      
   NXCALLx is a call to a shared library function:   
   px ... p1 address NXCALLx  \ x=#parameters, address = function entry   
   NXCALL is a low level integer function used before the EXTERN:   
   interface has been compiled.   
      
   \ int chmod(const char *path, mode_t mode);   
   : (OS_Chmod)    { c-addr u mode | zaddr[ #1024 ] -- ior }   
     c-addr u zaddr[ zplace   
     zaddr[ mode  dll_chmod @ nxcall2   
     0=   
      
      
   : (OS_Key)    \ -- key   
     { | iobuff[ cell ] -- char }   
     ?PrepTerm   
     stdin @ iobuff[ 1  dll_ReadFile @ nxcall3 drop   
     iobuff[ c@   
      
      
   All VFX Forth downloads include the source code.   
      
   Stephen   
      
   --- 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