Re: How to implement lexical closures?

grom <grom358@gmail.com>
Tue, 11 May 2010 18:38:22 -0700 (PDT)

          From comp.compilers

Related articles
How to implement lexical closures? grom358@gmail.com (grom) (2010-05-06)
Re: How to implement lexical closures? sleepdev@gmail.com (andy johnson) (2010-05-09)
Re: How to implement lexical closures? gneuner2@comcast.net (George Neuner) (2010-05-09)
Re: How to implement lexical closures? cr88192@hotmail.com (BGB / cr88192) (2010-05-09)
Re: How to implement lexical closures? torbenm@diku.dk (2010-05-10)
Re: How to implement lexical closures? grom358@gmail.com (grom) (2010-05-11)
Re: How to implement lexical closures? cr88192@hotmail.com (BGB / cr88192) (2010-05-12)
Re: How to implement lexical closures? gene.ressler@gmail.com (Gene) (2010-05-12)
Re: How to implement lexical closures? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-05-13)
Re: How to implement lexical closures? gneuner2@comcast.net (George Neuner) (2010-05-15)
Re: How to implement lexical closures? gneuner2@comcast.net (George Neuner) (2010-05-15)
Re: How to implement lexical closures? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-05-16)
[4 later articles]
| List of all articles for this month |

From: grom <grom358@gmail.com>
Newsgroups: comp.compilers
Date: Tue, 11 May 2010 18:38:22 -0700 (PDT)
Organization: Compilers Central
References: 10-05-031 10-05-052
Keywords: storage, symbols
Posted-Date: 12 May 2010 00:59:25 EDT

Thanks for all the replies. The solution that I am currently using is
a linked list of symbol tables. Each time a new scope is entered (ie.
a function) a new symbol table is created that is linked to the outer
scope symbol table. Then when a variable is referenced it searches the
linked list of symbol tables starting from the local symbol table and
working out to the top level symbol table (ie. global symbol table).


As Torben said this can result in memory leaks as all variables are
preserved in scope. Eg:
memoryLeak = function() {
        largeObject = // some large data structure
        return function() {
                // some code that does not use largeObject
        };
};
f = memoryLeak();
// The function f has preserved the variable largeObject even though
it is not in use


My next step will be to try using indirect references to variables in
the outer scope and only bringing in references that are used.



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.