gcc -masm=intel -std=c11 -Wall coroutine.c call.s main.c
./a.out
void fuga(coroutine *frame)
{
// arguments can be accessed via frame->env
int piyo = *((int *)(frame->env)) + 10;
// call yield to yield a value.
yield(frame, &piyo);
// if NULL is yielded, the coroutine ends
// yield(frame, NULL);
// or just returning ends the coroutine as well.
}
coroutine *hoge = new_coroutine(function_to_call, (void *)&arguments);
while ((ret = call_coroutine(context)) != NULL)
{
printf("%d\n", *ret);
}
To be filled later.