8 ms·
As scandox I did not mean to be dismissive, just to highlight the technique has been used in the past, as a reference for discussion and evaluation. It is hard
by enqk 10y ago
As scandox I did not mean to be dismissive, just to highlight the technique has been used in the past, as a reference for discussion and evaluation.
It is hard to imagine how one could preserve local variables w/o knowledge about the precise compiler + architecture. You would also have to communicate to the compiler that these locals should not be re-arranged nor merged in every context where the function is being used.
So the pragmatic solution thus far has been to keep track of variables in a separate block of memory, passed in in every invocation of a coroutine.
- codr4life 10y agoPreservation of stack data is done by comparing addresses of stack allocated values and using memcpy to copy the space in between. That's the most straight forward solution I could come up with. I'm still working on a way to track the variables automagically, which is why the optimization level is set to 0 for now; looks like I might end up having to add a third macro for preserved vars.