# separate components into different files use stdio.h use sched use channel # TODO rationalize pointer / struct duality somehow # TODO simplify main() main() sched_init() ch(int) ch ch_init(ch) count_to_three c3 count_to_three_init(&c3, &ch) printer pr printer_init(&pr, &ch) print_dots pd print_dots_init(&pd, 20) start(c3) start(pr) start(pd) run() count_to_n cn count_to_n_init(&cn, &ch, 15) start(cn) run() coro count_to_three(ch(int) *out) wr(out, 1) wr(out, 2) wr(out, 3) coro printer(ch(int) *in) repeat int v rd(in, v) printf("%d\n", v) coro count_to_n(ch(int) *out, int n) state int i = 1 for ; i<=n; ++i wr(out, i) # this one is an example of normal yielding coro print_dots(int n) while n > 0 printf(".\n") -- n yield # TODO include this channel struct automatically, and change # brace_shuffle to remove redundant identical definitions. channel(int)