# here is a simple test program for coroutines # I was going to write it in C++, but then would have to use pointers to member # functions, which are a mess, so I'll write it in C, and change to use "with" # later. # I think there is a g++ extension that allows generic calls to pointers to # member functions, which might be useful. Stick to C for now! # coro 1 joins lines together if they end in \ # coro 2 splits lines apart if they contain ; # (doesn't handle quoting) # need to have a "channels" idea use stdio.h int count_to_three(int pc) switch pc 0 printf("1\n") return 1 1 printf("2\n") return 2 2 printf("3\n") return 3 3 . return -1 struct count_to_n_data int n int c int count_to_n(int pc, void *data) count_to_n_data *d = (count_to_n_data *)data switch pc 0 d->c = 1 while d->c <= d->n printf("%d\n", d->c) ++ (d->c) return 1 1 . return -1 int main() # while pc != -1 # pc = count_to_three(pc) count_to_n_data d1, d2 d1.n = 10 d2.n = 15 int pc1 = 0 int pc2 = 0 while pc1 != -1 || pc2 != -1 if pc1 != -1 pc1 = count_to_n(pc1, &d1) if pc2 != -1 pc2 = count_to_n(pc2, &d2) return 0