Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!zurich.ai.mit.edu!jinx From: jinx@zurich.ai.mit.edu (Guillermo J. Rozas) Newsgroups: comp.lang.lisp Subject: Re: compiling lambda-CLOSUREs Message-ID: Date: 5 Apr 91 01:36:22 GMT References: <14172@medusa.cs.purdue.edu> <1991Apr3.095336.29725@hellgate.utah.edu> <1991Apr5.001438.26057@Think.COM> Sender: news@ai.mit.edu Reply-To: jinx@zurich.ai.mit.edu Organization: M.I.T. Artificial Intelligence Lab. Lines: 49 In-reply-to: barmar@think.com's message of 5 Apr 91 00:14:38 GMT In article <1991Apr5.001438.26057@Think.COM> barmar@think.com (Barry Margolin) writes: Path: ai-lab!mintaka!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.lisp Date: 5 Apr 91 00:14:38 GMT References: <14172@medusa.cs.purdue.edu> <1991Apr3.095336.29725@hellgate.utah.edu> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 23 In article jinx@zurich.ai.mit.edu writes: >Since MIT Scheme has first-class environments, we had to deal with the >situation of mutable environments being shared between interpreted and >compiled code, and directly manipulated by programs, and it is not >hard to solve, but requires some care. No, it's not hard to do, but few CL implementations actually do it, so we decided not to require it. Basically, all it requires is that the compiler generate code that emulates the way the interpreter searches lexical environments, rather than turning lexical references into constant offsets into the lexical environment. Also, the compilation of GO and RETURN-FROM must call into the interpreter if they are transfering out of the lambda expression. As I said in my previous message, I understand why CL did not do it. I was just trying to say that it is not hard. I'm not sure that I disagree with the decision for CL. BTW, as an aside, your solution works but is not very good, since it makes compiled code access to these variables slow. There are alternatives which make compiled code run faster. What MIT Scheme does by default is as follows (in rough lines): The runtime library provides a way for compiled code to request a cell for a pair. It can then cache the cell, and reference (and assign) the variable by indirecting through the cell. The runtime library maintains a table of where such cells have been provided, and replaces them when incremental definition shadows previous definitions. The interpreter has been taught (trivially) to handle such cells. Thus when compiling any code, the way that top-level free variables are handled is by requesting cells for all of them at link-time, caching them in the compiled code object, and forgetting where they came from.