I used to work on IronLua in my spare time. Lexing and parsing is currently done. I kind of stopped working on it out of frustration since implementing Lua coroutines in .NET without resorting to dirty threading hacks is not easy. This is tied to how I compile Lua functions, and it's a problem I need to solve early while designing the compiler.
I've been researching coroutine implementations, and it turns out that my initial feelings about continuations were correct.
Since coroutine creation, yield and other operations are not language keywords, but functions in the "coroutine" table, I cannot statically switch to CPS-style compilation as the coroutine table might have been overwritten by a previous script. While I understand that scripts overwriting the coroutine table are a rare occurrence, I'd like to be on the safe side and approach the issue as cleanly as possible.
My plan is to use continuation-passing style for every expression, no matter if we're in a coroutine or not. Everything would be followed by a continuation.
Besides the obvious difficulty of writing a compiler in the first place, and adding CPS transform on top of it, I'm troubled by this design decision and its performance implications.
I'm looking for advice about Lua coroutine implementation in .NET.
Thanks for your time.