ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change
on this file since 80a9898 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.3 KB
|
Line | |
---|
1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2017 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.c -- 3-state finite-state machine |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Thu Jun 8 07:29:37 2017 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Tue Dec 11 21:57:33 2018 |
---|
13 | // Update Count : 25 |
---|
14 | // |
---|
15 | |
---|
16 | #include <fstream.hfa> |
---|
17 | #include <coroutine.hfa> |
---|
18 | |
---|
19 | coroutine Fibonacci { int fn; }; // used for communication |
---|
20 | |
---|
21 | void main( Fibonacci & fib ) with( fib ) { // called on first resume |
---|
22 | int fn1, fn2; // retained between resumes |
---|
23 | fn = 0; fn1 = fn; // 1st case |
---|
24 | suspend(); // restart last resume |
---|
25 | fn = 1; fn2 = fn1; fn1 = fn; // 2nd case |
---|
26 | suspend(); // restart last resume |
---|
27 | for () { |
---|
28 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case |
---|
29 | suspend(); // restart last resume |
---|
30 | } // for |
---|
31 | } |
---|
32 | |
---|
33 | int next( Fibonacci & fib ) with( fib ) { |
---|
34 | resume( fib ); // restart last suspend |
---|
35 | return fn; |
---|
36 | } |
---|
37 | |
---|
38 | int main() { |
---|
39 | Fibonacci f1, f2; |
---|
40 | for ( 10 ) { // print N Fibonacci values |
---|
41 | sout | next( f1 ) | next( f2 ); |
---|
42 | } // for |
---|
43 | } |
---|
44 | |
---|
45 | // Local Variables: // |
---|
46 | // tab-width: 4 // |
---|
47 | // compile-command: "cfa fibonacci.c" // |
---|
48 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.