Re: Implementing Closures

"Armel" <>
Fri, 24 Apr 2009 17:47:08 +0200

          From comp.compilers

Related articles
Implementing Closures (Andrew Tomazos) (2009-04-24)
Re: Implementing Closures (Armel) (2009-04-24)
Re: Implementing Closures (Tony Finch) (2009-04-26)
Re: Implementing Closures (Barry Kelly) (2009-04-26)
Re: Implementing Closures (cr88192) (2009-04-26)
Re: Implementing Closures (2009-04-28)
Re: Implementing Closures (Pertti Kellomaki) (2009-04-29)
Re: Implementing Closures (2009-04-29)
[4 later articles]
| List of all articles for this month |

From: "Armel" <>
Newsgroups: comp.compilers
Date: Fri, 24 Apr 2009 17:47:08 +0200
Organization: les newsgroups par Orange
References: 09-04-056
Keywords: storage, design
Posted-Date: 25 Apr 2009 14:51:08 EDT

"Andrew Tomazos" <> 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...


Post a followup to this message

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