lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hash: SHA1

David Kastrup wrote:
> As a note aside: there is an interesting native implementation of
> call/cc if I remember correctly: subroutines _never_ return.  Instead,
> the call stack is garbage-collected&compacted together with the heap.
> That way, the dynamic context stays alive as long as it is needed.

Indeed. I've actually been thinking about that example I posted; there are a
lot of possibilities. By moving the dynamic chain off the stack and onto the
heap, a whole bunch of things become possible. Firstly, it's no longer a
chain, it can be a graph; as you say, a dynamic context. Secondly, non-local
gotos become trivial. Thirdly, coroutines become trivial. Fourthly, replace
the 'goto' with a little function that adds the new 'address' to a queue and
instead pops off the bottom item and jumps to that, and you get preemptive
multitasking. Fifthly, all this is happening *on the same lua_State*.

And it's all so simple it might even be *fast*... calling a function will be
fairly expensive, as it requires creating a lot of closures, but it should
still be easy meat for LuaJIT.

Once I'm done with my current project I might try and make a working example
out of this, and see how it goes... but before then, I have a lot of reading
to do!

- --
┌── ─── ───────────────────
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla -