From: | George Neuner <gneuner2@comcast.net> |
Newsgroups: | comp.compilers |
Date: | Fri, 24 Jun 2011 18:13:45 -0400 |
Organization: | A noiseless patient Spider |
References: | 11-06-037 11-06-039 |
Keywords: | storage, symbols |
Posted-Date: | 24 Jun 2011 21:00:47 EDT |
On Wed, 22 Jun 2011 11:47:19 +0100, Hans-Peter Diettrich
<DrDiettrich1@aol.com> 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
Return to the
comp.compilers page.
Search the
comp.compilers archives again.