Changeset 78b3f52 for src/examples
- Timestamp:
- Dec 2, 2016, 5:10:22 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d7bcbf5
- Parents:
- 4cb935e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/coroutine.c
r4cb935e r78b3f52 4 4 struct Fibonacci { 5 5 coroutine c; 6 coVtable v; 6 7 int fn; // used for communication 7 8 }; 8 9 10 coroutine* this_coroutine(Fibonacci* this); 11 void co_main(Fibonacci* this); 12 coVtable* vtable(Fibonacci* this); 13 14 void co_main_fib(void* this) { 15 co_main( (Fibonacci*) this ); 16 } 17 18 coroutine* this_coroutine_fib(void* this) { 19 return this_coroutine( (Fibonacci*) this); 20 } 21 9 22 void ?{}(Fibonacci* this) { 10 23 this->fn = 0; 11 } 12 13 coroutine* this_coroutine(Fibonacci* this) { 14 return &this->c; 24 this->v.main = co_main_fib; 25 this->v.this_coroutine = this_coroutine_fib; 26 start(this); 15 27 } 16 28 17 29 void co_main(Fibonacci* this) { 30 sout | "Starting main of coroutine " | this | endl; 31 sout | "Started from " | this_coroutine(this)->last | endl; 18 32 int fn1, fn2; // retained between resumes 19 33 this->fn = 0; … … 39 53 } 40 54 55 coroutine* this_coroutine(Fibonacci* this) { 56 return &this->c; 57 } 58 59 coVtable* vtable(Fibonacci* this) { 60 return &this->v; 61 } 62 41 63 int main() { 42 Fibonacci f1, f2; 64 Fibonacci f1; 65 sout | "User coroutine : " | &f1 | endl; 43 66 for ( int i = 1; i <= 10; i += 1 ) { 44 sout | next(&f1) | ' ' | next(&f2) |endl;67 sout | next(&f1) | endl; 45 68 } 46 69
Note: See TracChangeset
for help on using the changeset viewer.