summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-22 18:39:53 +0100
committerTyge Løvset <[email protected]>2023-02-22 18:39:53 +0100
commit95f0b246cedc2d3669575ed2bfb398e6fbcb2b2f (patch)
treeacc1d8e237915baaef4504540eb3d030728f3953
parentb63df794ee2bda2c33856a646ca6e1386f5ab782 (diff)
downloadSTC-modified-95f0b246cedc2d3669575ed2bfb398e6fbcb2b2f.tar.gz
STC-modified-95f0b246cedc2d3669575ed2bfb398e6fbcb2b2f.zip
Renamed ccontext => cco_handle
-rw-r--r--include/stc/algo/cco.h14
-rw-r--r--misc/examples/cofib.c10
-rw-r--r--misc/examples/coread.c6
3 files changed, 15 insertions, 15 deletions
diff --git a/include/stc/algo/cco.h b/include/stc/algo/cco.h
index f7ed7ff1..fdb8ece3 100644
--- a/include/stc/algo/cco.h
+++ b/include/stc/algo/cco.h
@@ -33,7 +33,7 @@
*
* [Re-entrant version using an explicit context structure]
*
- * int ascending(ccontext* ctx) {
+ * int ascending(cco_handle* ctx) {
* cco_context(ctx,
* int idx;
* );
@@ -48,8 +48,8 @@
* }
*
* In the re-entrant version, you need to declare your persistent
- * variables by the `cco_context' macro. This macro takes the base
- * ccontext as first parameter.
+ * variables by the `cco_context' macro. This macro takes the
+ * cco_handle as first parameter.
*
* Note that the context variable is set back to zero when the
* coroutine terminates (by cco_stop, or by control reaching
@@ -69,8 +69,8 @@
* coroutine with `cco_stop(&ctx)' as parameter instead of &ctx alone.
*
* Ground rules:
- * - never put `c_yield' within an explicit `switch'.
- * - never put two `c_yield' statements on the same source line.
+ * - never put `cco_yield' within an explicit `switch'.
+ * - never put two `cco_yield' statements on the same source line.
* - add `cco_finish:' label at the end of the coroutine, before
* any cleanup code. Required to support cco_stop(ctx) argument.
*
@@ -78,7 +78,7 @@
* variable:
*
* void main(void) {
- * ccontext z = 0;
+ * cco_handle z = 0;
* for (;;) {
* int x = ascending(&z);
* if (!z) break;
@@ -100,7 +100,7 @@
*/
typedef struct {
int _ccoline;
-} *ccontext;
+} *cco_handle;
#define cco_context(cref, ...) \
struct ccoContext { \
diff --git a/misc/examples/cofib.c b/misc/examples/cofib.c
index d0e4ac2a..2363989a 100644
--- a/misc/examples/cofib.c
+++ b/misc/examples/cofib.c
@@ -6,10 +6,10 @@
typedef long long llong;
-llong fibonacci_sequence(ccontext* ctx, unsigned n) {
+llong fibonacci_sequence(cco_handle* z, unsigned n) {
assert (n < 95);
- cco_context(ctx,
+ cco_context(z,
llong a, b, idx;
);
@@ -17,10 +17,10 @@ llong fibonacci_sequence(ccontext* ctx, unsigned n) {
u->a = 0;
u->b = 1;
for (u->idx = 2; u->idx < n; u->idx++) {
- llong sum = u->a + u->b;
- cco_yield(sum);
+ 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_finish:
);
@@ -29,7 +29,7 @@ llong fibonacci_sequence(ccontext* ctx, unsigned n) {
int main(void) {
- ccontext z = 0;
+ cco_handle z = 0;
printf("Fibonacci numbers:\n");
for (;;) {
llong x = fibonacci_sequence(&z, 30);
diff --git a/misc/examples/coread.c b/misc/examples/coread.c
index 9181401d..55e4bf21 100644
--- a/misc/examples/coread.c
+++ b/misc/examples/coread.c
@@ -4,9 +4,9 @@
// Read file line by line using coroutines:
-cstr file_nextline(ccontext* ccx, const char* name)
+cstr file_nextline(cco_handle* z, const char* name)
{
- cco_context(ccx,
+ cco_context(z,
FILE* fp;
cstr line;
);
@@ -28,7 +28,7 @@ cstr file_nextline(ccontext* ccx, const char* name)
int main(void) {
- ccontext z = 0;
+ cco_handle z = 0;
int n = 0;
do {
c_with (cstr line = file_nextline(&z, __FILE__), z, cstr_drop(&line)) {