diff options
| author | Tyge Løvset <[email protected]> | 2023-02-23 12:38:38 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-02-23 12:38:38 +0100 |
| commit | 01f09f3c2f34ae960b091f6d4063750bccd3e777 (patch) | |
| tree | 4ead1e1a6c89e74997283c5899285929a3c030be /misc | |
| parent | 4ff4c8d352f76b658214029988eab7ce1d69efe8 (diff) | |
| download | STC-modified-01f09f3c2f34ae960b091f6d4063750bccd3e777.tar.gz STC-modified-01f09f3c2f34ae960b091f6d4063750bccd3e777.zip | |
Renamed cco.h to coroutine.h
Diffstat (limited to 'misc')
| -rw-r--r-- | misc/examples/cofib.c | 24 | ||||
| -rw-r--r-- | misc/examples/coread.c | 8 |
2 files changed, 16 insertions, 16 deletions
diff --git a/misc/examples/cofib.c b/misc/examples/cofib.c index 2363989a..ea37669a 100644 --- a/misc/examples/cofib.c +++ b/misc/examples/cofib.c @@ -1,4 +1,4 @@ -#include <stc/algo/cco.h> +#include <stc/algo/coroutine.h> #include <stdio.h> #include <stdint.h> @@ -12,19 +12,19 @@ llong fibonacci_sequence(cco_handle* z, unsigned n) { cco_context(z, llong a, b, idx; ); - - cco_routine(u, - u->a = 0; - u->b = 1; - for (u->idx = 2; u->idx < n; u->idx++) { - llong sum = u->a + u->b; // NB! locals only lasts until a cco_yield! - u->a = u->b; - u->b = sum; - cco_yield (sum); + cco_routine(U, + U->a = 0; + U->b = 1; + for (U->idx = 0; U->idx < n; U->idx++) { + cco_yield (U->a); + llong sum = U->a + U->b; // NB! locals only lasts until next cco_yield! + U->a = U->b; + U->b = sum; } cco_finish: ); - return 0; + + return -1; } @@ -32,7 +32,7 @@ int main(void) { cco_handle z = 0; printf("Fibonacci numbers:\n"); for (;;) { - llong x = fibonacci_sequence(&z, 30); + llong x = fibonacci_sequence(&z, 14); if (!z) break; printf(" %lld", x); } diff --git a/misc/examples/coread.c b/misc/examples/coread.c index 55e4bf21..e65ab533 100644 --- a/misc/examples/coread.c +++ b/misc/examples/coread.c @@ -1,5 +1,5 @@ #include <stc/cstr.h> -#include <stc/algo/cco.h> +#include <stc/algo/coroutine.h> #include <errno.h> // Read file line by line using coroutines: @@ -10,7 +10,6 @@ cstr file_nextline(cco_handle* z, const char* name) FILE* fp; cstr line; ); - cco_routine(U, U->fp = fopen(name, "r"); U->line = cstr_NULL; @@ -23,6 +22,7 @@ cstr file_nextline(cco_handle* z, const char* name) cstr_drop(&U->line); fclose(U->fp); ); + return cstr_NULL; } @@ -34,8 +34,8 @@ int main(void) { c_with (cstr line = file_nextline(&z, __FILE__), z, cstr_drop(&line)) { printf("%3d %s\n", ++n, cstr_str(&line)); - // stop after 10 lines: - if (n == 10) file_nextline(cco_stop(&z), __FILE__); + // stop after 15 lines: + if (n == 15) file_nextline(cco_stop(&z), __FILE__); } } while (z); } |
