I worked at IronLua in my free time. Lexing and parsing are currently performed. I somehow stopped working on this because of disappointment, since the implementation of Lua coroutines in .NET, without resorting to dirty streaming hacks, is not easy. This is due to the way I compile Lua functions, and this is a problem that I have to solve early when developing the compiler.
I study the implementation of coroutine, and it turns out that my initial feelings about the continuation were correct.
Since creating coroutine, yield, and other operations are not language keywords, but functions in the "coroutine" table, I cannot statically switch to CPS-style compilation, since the coprocessor table could be overwritten by the previous script. Although I understand that scripts rewriting a coroutine table are rare, I would like to be safe and approach the problem as clean as possible.
My plan is to use a continuation style for each expression, regardless of whether we are in a coroutine or not. It will be followed by a sequel.
Besides the obvious difficulty of writing a compiler in the first place and adding a CPS transformation on top of it, I am concerned about this design decision and its performance implications.
I am looking for advice on implementing Lua coroutine in .NET.
Thank you for your time.
Raine source share