diff options
Diffstat (limited to 'stackless_coroutine.c')
-rwxr-xr-x | stackless_coroutine.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/stackless_coroutine.c b/stackless_coroutine.c index 705d11c..d819f35 100755 --- a/stackless_coroutine.c +++ b/stackless_coroutine.c @@ -246,9 +246,9 @@ static void stackless_coroutine_dispatch(void *promise) { promise_ = (Promise_Of(coro_)) { CORO_INITIAL_(0, coro_), __VA_ARGS__ }; \ } while (0) -#define CORO_INIT_ID(promise_, id_, ...) \ - do { \ - promise_ = (Promise_Of(coro_)) { CORO_INITIAL_CORO_INITIAL_(id_), coro_), __VA_ARGS__ }; \ +#define CORO_INIT_ID(promise_, id_, ...) \ + do { \ + promise_ = (Promise_Of(coro_)) { CORO_INITIAL_(id_, coro_), __VA_ARGS__ }; \ } while (0) #define coro_finished(promise_) ((promise_)._index == -1) @@ -291,37 +291,6 @@ CORO_IMPL(test_foo) { async_return(42); } CORO_END -CORO_DECL_STATIC(int, test_bar, ); - -CORO_IMPL(test_bar) { - yield_void; - async_return(42); -} CORO_END - -CORO_STATIC(int, test_gen, int i; int min; int max;) { - for (self->i = self->min; self->i < self->max; self->i++) - yield(self->i); - async_return(self->max); -} CORO_END - -CORO_STATIC_VOID(test_task, ) { - yield_void; - yield_void; - async_return_void; -} CORO_END - -CORO_STATIC_VOID(test_nest_task, Promise_Of(test_task) promise;) { - CORO_INIT(self->promise, test_task, ); - await(self->promise); - await(self->promise); - await(self->promise); -} CORO_END - -CORO_STATIC(int, test_nest_generator, Promise_Of(test_gen) promise;) { - CORO_INIT(self->promise, test_gen, .min = 1, .max = 3); - yield_await(self->promise); -} CORO_END - TEST("coroutine init") { Promise_Of(test_foo) promise; CORO_INIT(promise, test_foo, ); @@ -342,6 +311,13 @@ TEST("coroutine execute and return") { REQUIRE(coro_finished(promise)); } +CORO_DECL_STATIC(int, test_bar, ); + +CORO_IMPL(test_bar) { + yield_void; + async_return(42); +} CORO_END + TEST("coroutine execute two steps") { Promise_Of(test_bar) promise; CORO_INIT(promise, test_bar, .return_value = 0); @@ -351,6 +327,12 @@ TEST("coroutine execute two steps") { REQUIRE(promise.return_value == 42); } +CORO_STATIC(int, test_gen, int i; int min; int max;) { + for (self->i = self->min; self->i < self->max; self->i++) + yield(self->i); + async_return(self->max); +} CORO_END + TEST("coroutine generator") { int i; Promise_Of(test_gen) promise; @@ -368,6 +350,12 @@ TEST("coroutine status finished") { REQUIRE(coro_finished(promise)); } +CORO_STATIC_VOID(test_task, ) { + yield_void; + yield_void; + async_return_void; +} CORO_END + TEST("coroutine task") { Promise_Of(test_task) promise; CORO_INIT(promise, test_task, ); @@ -379,6 +367,13 @@ TEST("coroutine task") { REQUIRE(coro_finished(promise)); } +CORO_STATIC_VOID(test_nest_task, Promise_Of(test_task) promise;) { + CORO_INIT(self->promise, test_task, ); + await(self->promise); + await(self->promise); + await(self->promise); +} CORO_END + TEST("coroutine nested task") { Promise_Of(test_nest_task) promise; CORO_INIT(promise, test_nest_task, ); @@ -390,6 +385,11 @@ TEST("coroutine nested task") { REQUIRE(coro_finished(promise)); } +CORO_STATIC(int, test_nest_generator, Promise_Of(test_gen) promise;) { + CORO_INIT(self->promise, test_gen, .min = 1, .max = 3); + yield_await(self->promise); +} CORO_END + TEST("coroutine nested generator") { Promise_Of(test_nest_generator) promise; CORO_INIT(promise, test_nest_generator, ); |