home bbs files messages ]

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

   comp.arch      Apparently more than just beeps & boops      131,241 messages   

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

   Message 129,543 of 131,241   
   Waldek Hebisch to Stefan Monnier   
   Re: Register windows   
   30 Aug 25 15:36:46   
   
   From: antispam@fricas.org   
      
   Stefan Monnier  wrote:   
   >> There is one additional, quite thorny issue:  How to maintain   
   >> state for nested functions to be invoked via pointers, which   
   >> have to have access local variables in the outer scope.   
   >> gcc does so by default by making the stack executable, but   
   >> that is problematic.  An alternative is to make some sort of   
   >> executable heap.  This is now becoming a real problem, see   
   >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117455 .   
   >   
   > AFAIK this is a problem only in those rare languages where a function   
   > value is expected to take up the same space as any other pointer while   
   > at the same time supporting nested functions.   
   >   
   > In most cases you have either one of the other but not both.  E.g. in   
   > C we don't have nested functions, and in Javascript functions are   
   > heap-allocated objects.   
   >   
   > Other than GNU C (with its support for nested functions), which other   
   > language has this weird combination of features?   
      
   Well, more precisely:   
   - function pointer is supposed to take the same space as a single   
     machine address   
   - function pointer is supposed to be directly invokable, that is   
     point to machine code of the function   
   - one wants to support nested functions   
   - there is no garbage collector, one does not want to introduce extra   
     stack and one does not want to leak storage allocated to nested   
     functions.   
      
   To explain more:   
   - arguably in "safe" C data pointers should consist   
     of 3 machine words, such pointer have place for extra data needed   
     for nested functions.   
   - some calling conventions introduce extra indirection, that is   
     function pointer point to a data structure containing address   
     of machine code and extra data needed by nested functions.   
     Function call puts extra data in dedicated machine register and   
     then transfers control via address contained in function data   
     structure.  IIUC IBM AIX uses such approach.   
   - one could create trampolines in a separate area of memory.  In   
     such case there is trouble with dealocating no longer needed   
     trampolines.  This trouble can be resolved by using GC.  Or   
     by using a parallel stack dedicated to trampolines.   
      
   Concerning languages, any language which has nested functions and   
   wants seamless cooperation with C needs to resolve the problem.   
   That affects Pascal, Ada, PL/I.  That is basicaly most classic   
   non-C languages.  IIUC several "higher level" languages resolve   
   the trouble by combination of parallel stack and/or GC.  But   
   when language want to compete with efficiency of C and does not   
   want GC, then trampolines allocated on machine stack may be the   
   only choice (on register starved machine parallel stack may be   
   too expensive).  AFAIK GNU Ada uses (or used) trampolines   
   allocated on machine stack.   
      
   --   
                                 Waldek Hebisch   
      
   --- 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