[Sablevm-developer] Continuations
Brought to you by:
egagnon
From: Etienne M. G. <eg...@j-...> - 2000-07-20 05:05:27
|
For the record. -------- Original Message -------- Date: Wed, 19 Jul 2000 21:29:12 -0700 From: Brent Fulgham <bfu...@de...> To: "Etienne M. Gagnon" <eg...@j-...> ... On another subject: Continuations. I was thinking that it would probably be possible to simulate continuations at the JVM level by using the same mechanisms that are used for the exception handling. I'm not sure if this is an efficient way to go about this, but in theory it should work. I'm not really sure how I could even pseudo-code this in Java, but in a pseudo-code: ... 1. Execute some statements 2. Source code calls for a "call-with-current-continuation" 3. JVM creates an exception that holds the current state of this routine (i.e., must make a copy of the current variables) 4. JVM starts a "Try" block 4. Execution continues 5. Eventually, a condition is reached where we want to jump back to the continuation. So the JVM "Throws" that exception 6. We unwind until we hit the top of the "Try" block. This is also coded as the "Catch", which restores state to where we were when we hit the start of the continuation. In fact, I'm not sure how much of this might be automatic with respect to the stack unwinding features. Is it possible we might find ourselves back where we started with the 'stack' in the proper state just automatically? I suppose it's too much to hope for... The nice thing about this idea is that, again, we don't have to do anything new -- we make use of existing JVM features. The Scheme (or whatever) compiler that targets the JVM would just have to know how to generate the code that starts / ends the continuation... What do you think? Terrible idea? :-) Regards, -Brent |