Stackless resumable functions
bitwise via Digitalmars-d
digitalmars-d at puremagic.com
Sat Feb 21 13:19:32 PST 2015
> They are waiting for your pull request :o)
Welll... I would like to try, but there is good reason behind the
noncommital phrasing of my question :)
I experimented with stackful coroutines in C++, but I think
stackless resumable functions will be more difficult. I assume I
can harvest most of what I need from other parts of D.
My initial thoughts on this is that I could have resumable
functions return a special range which contained 3 things:
-a pointer to the function
-all the stack variables from the function
-an integer index into a jump table at the beginning of the
resumable function
At compile time, each usage of yield in the resumable function
would be replace with:
-a command to update the jump table index, followed by
-a label, who's offset would be contained in the jump table
So initially calling a resumable function would return the range
in question which would repeatedly call into the resumable
function with a different index until the end of the resumable
function was reached.
Input on this would be appreciated.
More information about the Digitalmars-d
mailing list