Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!nerds-end From: George Neuner Newsgroups: comp.compilers Subject: Re: How to handle qualified identifiers such as x.y in a Pascal-like language Date: Fri, 24 Jun 2011 18:13:45 -0400 Organization: A noiseless patient Spider Lines: 29 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <11-06-045@comp.compilers> References: <11-06-037@comp.compilers> <11-06-039@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: gal.iecc.com 1308963647 52327 64.57.183.58 (25 Jun 2011 01:00:47 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 25 Jun 2011 01:00:47 +0000 (UTC) Keywords: storage, symbols Posted-Date: 24 Jun 2011 21:00:47 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: x330-a1.tempe.blueboxinc.net comp.compilers:171 On Wed, 22 Jun 2011 11:47:19 +0100, Hans-Peter Diettrich wrote: >noitalmost schrieb: >> What I don't quite understand is how to parse access to a variable in >> an outer stack frame. And I think this is similar to the problem of >> nested procedures (which I also don't quite know how to handle). > >First of all: local procedures using local variables in an *outer* >stackframe are problematic. Such a language feature deserves much >work, in detail when you also want to allow to use local procedures as >callbacks (procedure pointers). I'd drop that from my language. But doing so sacrifices quite a bit of power. In a Pascal-like language having strict stack semantics, the best way to handle non-local variables is to identify and move them all into a defined structure in the stack frame of the outermost enclosing function, then add a hidden pointer argument to all the inner functions and pass the address of the structure down the call chain. The same analysis allows for creating persistent closures by allocating the non-local variable structure on the heap instead of on the stack. [Of course, then you need other mechanisms to invoke the closures and clean up after them when they are no longer needed ... mechanisms which are beyond the scope of this discussion.] George