"Andrew Tomazos" <andrew@tomazos.com> 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...