3 ms·
These are stackless coroutines, if you use longjump you have to create a stack for the coroutine. There are pros and cons for each style.
by dkjaudyeqooe 3y ago
These are stackless coroutines, if you use longjump you have to create a stack for the coroutine.
There are pros and cons for each style.
- trealira 3y agoIn theory (but only possible in assembly right now), there could be coroutines that shared the stack of their caller. As long as the caller (who's calling from a normal function) finishes calling the coroutine and doesn't expect to be able to call it after they return, then you could use it to implement iterators, e.g. over a binary tree or a hash table, like generators in Python. It could work as long as the caller used the stack frame base pointer to refer to their saved local variables, since the stack pointer could be changed between yields to the coroutine. I'm genuinely surprised there hasn't been a compiled programming language to do that other than Sather and CLU[0] (both of which are long dead by now). Graydon Hoare originally wanted them in Rust [1], but LLVM didn't support it, so it was scrapped. [0]: https://dl.acm.org/doi/pdf/10.1145/800127.804079 https://dl.acm.org/doi/pdf/10.1145/800127.804079 (the third PDF page, page 125) [1]: https://graydon2.dreamwidth.org/307291.html https://graydon2.dreamwidth.org/307291.html (search "non-escaping coroutine")