|Implementing Closures firstname.lastname@example.org (Andrew Tomazos) (2009-04-24)|
|Re: Implementing Closures email@example.com (Armel) (2009-04-24)|
|Re: Implementing Closures firstname.lastname@example.org (Tony Finch) (2009-04-26)|
|Re: Implementing Closures email@example.com (Barry Kelly) (2009-04-26)|
|Re: Implementing Closures firstname.lastname@example.org (cr88192) (2009-04-26)|
|Re: Implementing Closures email@example.com (2009-04-28)|
|Re: Implementing Closures firstname.lastname@example.org (Pertti Kellomaki) (2009-04-29)|
|Re: Implementing Closures email@example.com (2009-04-29)|
|[4 later articles]|
|Date:||Fri, 24 Apr 2009 17:47:08 +0200|
|Organization:||les newsgroups par Orange|
|Posted-Date:||25 Apr 2009 14:51:08 EDT|
"Andrew Tomazos" <firstname.lastname@example.org> a icrit dans le message de news:
> What are some of the approaches a compiler author could use to
> implement such a language feature?
The approach we used for our ECMAScript engine is to consider that a
function is an object built around two things: the text to execute and the
scope for it.
during the compiling phase, a map is built of the outer automatic variables
referenced inside each function.
during the execution phase, an automatic variable is built from the current
scope/refined through the above map + the pointer to the text to execute,
which bares the name of the function.
thus when executing "return my_local_function" you actually return the
complex object 'scope+text pointer'.
I read the C++0x specification in the wikipedia (next generation of c++
build specified) some time ago, there are interesting things about closures
there, although I don't remember anything specific from a low-level
implementation point of view. e.g. there are notations about what to import,
what to copy/what to reference...
Return to the
Search the comp.compilers archives again.