Changeset 971d9f2 for src/tests/coroutine/fibonacci.c
- Timestamp:
- Dec 6, 2017, 8:01:23 AM (7 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:
- 16988e8
- Parents:
- 65197c2
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/tests/coroutine/fibonacci.c
r65197c2 r971d9f2 10 10 // Created On : Thu Jun 8 07:29:37 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 17 21:38:15201713 // Update Count : 712 // Last Modified On : Tue Dec 5 22:27:54 2017 13 // Update Count : 14 14 14 // 15 15 … … 17 17 #include <coroutine> 18 18 19 coroutine Fibonacci { 20 int fn; // used for communication 21 }; 19 coroutine Fibonacci { int fn; }; // used for communication 22 20 23 void ?{}( Fibonacci & this ) { 24 this.fn = 0; 25 } 21 void ?{}( Fibonacci & fib ) with( fib ) { fn = 0; } 26 22 27 void main( Fibonacci & this) {23 void main( Fibonacci & fib ) with( fib ) { 28 24 int fn1, fn2; // retained between resumes 29 this.fn = 0; // case 0 30 fn 1 = this.fn;25 26 fn = 0; fn1 = fn; // 1st case 31 27 suspend(); // restart last resume 32 28 33 this.fn = 1; // case 1 34 fn2 = fn1; fn1 = this.fn; 29 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 35 30 suspend(); // restart last resume 36 31 37 for ( ;; ) { // general case 38 this.fn = fn1 + fn2; 39 fn2 = fn1; fn1 = this.fn; 32 for ( ;; ) { 33 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 40 34 suspend(); // restart last resume 41 35 } // for 42 36 } 43 37 44 int next( Fibonacci & this) {45 resume( this); // restart last suspend46 return this.fn;38 int next( Fibonacci & fib ) with( fib ) { 39 resume( fib ); // restart last suspend 40 return fn; 47 41 } 48 42
Note: See TracChangeset
for help on using the changeset viewer.