ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 2e041e27 was
107b01a,
checked in by Thierry Delisle <tdelisle@…>, 6 years ago
|
Several changes to the makefiles
- change .c tests to .cfa
- add require for libtool in configure
- libtoolize to fix some warnings
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[69efc321] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // fibonacci_1.c -- 1-state finite-state machine: precomputed first two states returning f(n - 2) |
---|
| 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Thu Apr 26 23:20:08 2018 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[200fcb3] | 12 | // Last Modified On : Tue Dec 11 21:57:54 2018 |
---|
| 13 | // Update Count : 14 |
---|
[69efc321] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream.hfa> |
---|
| 17 | #include <coroutine.hfa> |
---|
| 18 | |
---|
| 19 | coroutine Fibonacci { int ret; }; // used for communication |
---|
| 20 | |
---|
| 21 | void main( Fibonacci & fib ) with( fib ) { // called on first resume |
---|
| 22 | int fn, fn1 = 1, fn2 = 0; // precompute first two states |
---|
| 23 | for () { |
---|
| 24 | ret = fn2; |
---|
| 25 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case |
---|
| 26 | suspend(); // restart last resume |
---|
| 27 | } // for |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | int next( Fibonacci & fib ) with( fib ) { |
---|
| 31 | resume( fib ); // restart last suspend |
---|
| 32 | return ret; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | int main() { |
---|
| 36 | Fibonacci f1, f2; |
---|
| 37 | for ( 10 ) { // print N Fibonacci values |
---|
[200fcb3] | 38 | sout | next( f1 ) | next( f2 ); |
---|
[69efc321] | 39 | } // for |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | // Local Variables: // |
---|
| 43 | // tab-width: 4 // |
---|
| 44 | // compile-command: "cfa fibonacci_1.c" // |
---|
| 45 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.