Changeset 386e710
- Timestamp:
- Mar 22, 2019, 3:28:14 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f8cd310
- Parents:
- 17c6c1c3
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/coroutine/fibonacci_1.cfa
r17c6c1c3 r386e710 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fibonacci_1.c -- 1-state finite-state machine: precomputed first two states returning f(n - 2)7 // fibonacci_1.cfa -- 1-state finite-state machine: precomputed first two states returning f(n - 1) 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Apr 26 23:20:08 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 11 21:57:54 201813 // Update Count : 1412 // Last Modified On : Thu Mar 21 08:10:45 2019 13 // Update Count : 25 14 14 // 15 15 … … 17 17 #include <coroutine.hfa> 18 18 19 coroutine Fibonacci { int ret; }; // used for communication19 coroutine Fibonacci { int fn1; }; // used for communication 20 20 21 21 void main( Fibonacci & fib ) with( fib ) { // called on first resume 22 int fn, fn1 = 1, fn2 = 0; // precompute first two states 22 int fn; 23 [fn1, fn] = [0, 1]; // precompute first two states 23 24 for () { 24 ret = fn2;25 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case26 25 suspend(); // restart last resume 26 [fn1, fn] = [fn, fn1 + fn]; // general case 27 27 } // for 28 28 } … … 30 30 int next( Fibonacci & fib ) with( fib ) { 31 31 resume( fib ); // restart last suspend 32 return ret;32 return fn1; 33 33 } 34 34 … … 42 42 // Local Variables: // 43 43 // tab-width: 4 // 44 // compile-command: "cfa fibonacci_1.c " //44 // compile-command: "cfa fibonacci_1.cfa" // 45 45 // End: //
Note: See TracChangeset
for help on using the changeset viewer.