Re: Implementing Closures

"Armel" <armelasselin@hotmail.com>
Fri, 24 Apr 2009 17:47:08 +0200

          From comp.compilers

Related articles
Implementing Closures andrew@tomazos.com (Andrew Tomazos) (2009-04-24)
Re: Implementing Closures armelasselin@hotmail.com (Armel) (2009-04-24)
Re: Implementing Closures dot@dotat.at (Tony Finch) (2009-04-26)
Re: Implementing Closures barry.j.kelly@gmail.com (Barry Kelly) (2009-04-26)
Re: Implementing Closures cr88192@hotmail.com (cr88192) (2009-04-26)
Re: Implementing Closures torbenm@pc-003.diku.dk (2009-04-28)
Re: Implementing Closures pertti.kellomaki@tut.fi (Pertti Kellomaki) (2009-04-29)
Re: Implementing Closures torbenm@pc-003.diku.dk (2009-04-29)
[4 later articles]
| List of all articles for this month |
From: "Armel" <armelasselin@hotmail.com>
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" <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...


Regards
Armel



Post a followup to this message

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