Re: [Sablevm-user] About closures...
Brought to you by:
egagnon
|
From: Brent F. <bfu...@de...> - 2000-07-18 03:51:26
|
On Mon, Jul 17, 2000 at 05:52:27PM -0400, Etienne M. Gagnon wrote:
> Hi Brent.
>
> If memory serves me right, in fact what you want is to be able to "save"
> a snapshot of the stack, then, at a later time, be able to resume
> computation starting with this snapshot.
>
I think that is termed a 'continuation', which in Scheme you would
signal starting as 'letcc'. This is one critical piece of the system.
Closure refers to variables being bound inside function definitions,
such, e.g.:
(define test
(lambda (a)
(lambda (b)
(+ a b))))
(define foo1 (test 10))
(define foo2 (test 20))
Now if we do:
>(foo1 20)
30
>(foo2 20)
40
We say 'foo1 has closure on "a"' because it remembers that
it's internal a=10, while foo2 has an internal a=20. I think this
is relatively easy to simulate in a JVM (Kawa does it with inner
classes I believe). The problem is that because the JVM memory
management is so bad, it's very costly when compared to a dedicated
Scheme bytecode interpreter.
The harder part is the 'continuation' concept, which you describe
further below.
> Do you really need to open the access to the internal VM representation
> to implement this? I mean: would simply providing two new bytecodes,
> say NewClosure/UseClosure, be enough? As I said before, I am not very
> knowledgeable about FP runtime systems. e.g. I do not know tha answer to
> questions like: Does the closure only include the current thread's
> stack, or does it need a full copy of the overall VM state? How do you
> resume a closure: on a new thread? If not, what happens with the current
> stack? etc.
I think this sounds like a great idea.
>
> I think that, in general, providing new bytecodes, for extended
> functionality, is better than opening up the internal state, in that it
> helps shielding away applications from any specific VM implementation.
>
> Just some thoughts;-)
These sound like excellent ideas. The only other thing that might be
useful would be a "UseSameFrame" bytecode for help with tail-recursive
situations. I.e., a Scheme compiler for SableVM would be able to provide
the JVM with the "UseSameFrame" for a tail-recursive functions to
save stack space and convert the 'recursive' function into an interation.
Great ideas!
-Brent
|