Ask/suggestion about emscripten main loop

I have ported 7kaa onto emscripten. There’s some thinks that makes me frustrating, but I solve some of it.

I must ask for a way to enhancement of emscripten main loop. Currently JavaScript has a way to store/restore C stack, so:

  • Emscripten main loop should call application loop in try … catch(GoToLoop) block
  • Emscripten_set_main_loop should save C stack into special JS array (each stack will be next element, so this array will be stack itself), save callback pointer and data(argument) onto other C array, change main loop to given and throw GoToLoop
  • Add emscripten_cancel_loop, which pop old callback and data and set is as application loop, restore stack from highest element in JS array and return
  • Add emscripten_yield, which save stack, change variable indicated it was called to 1, set timemout to function restoring stack and throw GoToLoop(),
  • When emscripten_yield is called, but variable indicating it was called is 1, then emscripten only changes this variable value 0
    (If after reading next instruction JavaScript/WebAssembly interpreter points to instruction after currently read, then we can skip last point)

This will allow to:

  • Use multiple layers of application loop
  • Do code like
    emscripten_set_main_loop(…)
    rest_of_code

And rest_of_code wi,l be called in the same context, when loop call emscripten_cancel_loop,

What do you think about that? I don’t know it is possible to realize.