[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Coroutine protected calls (the return of)
- From: skaller <skaller@...>
- Date: 23 Jan 2005 07:24:34 +1100
On Sun, 2005-01-23 at 04:53, Mike Pall wrote:
> John Skaller wrote:
> > There's also a solution for Python (Stackless Python),
> > maybe it is worth looking at that (since it's also
> > a bytecode interpreter).
> Stackless Python does stack ripping for many core functions
What's stack ripping?
> plus C stack copying
It uses continuation passing AFAIK.. of course if you call
a C function which calls a callback, you have a stack
whether you like it or not. So even if you can 'resume/yield'
out of a callback, you'd have to get back in to return
to the caller...
> (a bit more portable than C stack switching, but slower). Ruby does
> stack copying, too.
Neither copying nor switching works properly in C++
due to exception handling stuff :(
> Alas, stack copying is problematic for Lua since we cannot assume an even
> C stack base for the caller of lua_resume().
> This could be solved by
> hardwiring a scheduler into the core. But I do not think this is the way
> to go for Lua.
This is probably right. However note that
the bytecode interpreter does actually schedule
execution of bytecodes.
If you re-enter it recursively (using loadfile or whatever),
you're screwed. But this can be fixed with a mechanical
transform to CPS (Continuation Passing Style) ..
pass the bytecode return address as an argument
instead of pushing it onto the stack.
This will change the C API though .. hmmm.. sorry just
rambling .. :)
John Skaller, mailto:email@example.com
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net