3 ms·
My understanding is that wasm doesn't allow for stack switching yet. How does koka implements effects in wasm? Heap allocated stack frames?
by gpderetta 3y ago
My understanding is that wasm doesn't allow for stack switching yet. How does koka implements effects in wasm? Heap allocated stack frames?
- miclill 3y agoI think the _magic_ here is emscripten: - https://emscripten.org/docs/porting/setjmp-longjmp.html https://emscripten.org/docs/porting/setjmp-longjmp.html - https://github.com/koka-lang/libmprompt/blob/main/src/mprompt/gstack.c https://github.com/koka-lang/libmprompt/blob/main/src/mpromp...
- whitim 3y agoKoka currently uses the same approach that it does for compiling to C. It essentially does a very efficient low level monadic translation of a delimited control monad. So basically it all just ends up as a tiny bit of thread local state, and building up continuations on returns from functions if they are yielding. See this paper for details, it gives a good high level overview before diving into the nitty gritty: https://www.microsoft.com/en-us/research/publication/generalized-evidence-passing-for-effect-handlers-or-efficient-compilation-of-effect-handlers-to-c/ https://www.microsoft.com/en-us/research/publication/general...
- gpderetta 3y agoThanks, I'm quite interested in this, so I'll certainly give the paper a read!