Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: George Neuner Newsgroups: comp.compilers Subject: Re: Add nested-function support in a language the based on a stack-machine Date: Tue, 13 Feb 2018 22:37:42 -0500 Organization: A noiseless patient Spider Lines: 33 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <18-02-020@comp.compilers> References: <18-02-009@comp.compilers> <18-02-012@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="14853"; mail-complaints-to="abuse@iecc.com" Keywords: code Posted-Date: 13 Feb 2018 23:12:05 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1956 On Tue, 13 Feb 2018 00:42:00 -0700, Louis Krupp wrote: >On Mon, 12 Feb 2018 11:25:36 -0800 (PST), dror.openu@gmail.com wrote: > >>Suppose I have a simple C-like programming language: ... >>Like you can see, it supports nested functions. > >gcc supports nested functions as an extension to C. Compiling this >program with -O0 -fdump-tree-all and looking at the generated files >might give you an idea of one way to do it: ... >The alternative, a display vector, seems like it would be easier to >implement unless you're doing this for a real machine with a real (and >therefore limited) set of registers. The display doesn't need to be in registers [though the pointer to the display itself should be]. Since every non-leaf function will touch some part of the display, it will tend to stay in cache close to the CPU. And a display doesn't need to be large to be effective. Lexical definition hierarchies tend to be quite shallow. Studies of nested functions done back in the days of Pascal showed that 16 entries sufficed for all but a tiny percentage of code. Also remember that OO is an orthogonal dimension: the depth of an object hierarchy will not be limited by using a display. However if you mix objects and display nested functions, I *think* it would be necessary to maintain a separate display instance per object type. George