ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 16988e8 was
971d9f2,
checked in by Peter A. Buhr <pabuhr@…>, 7 years ago
|
add "with" clause to test programs
|
-
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 -- |
---|
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 5 22:27:54 2017 |
---|
13 | // Update Count : 14 |
---|
14 | // |
---|
15 | |
---|
16 | #include <fstream> |
---|
17 | #include <coroutine> |
---|
18 | |
---|
19 | coroutine Fibonacci { int fn; }; // used for communication |
---|
20 | |
---|
21 | void ?{}( Fibonacci & fib ) with( fib ) { fn = 0; } |
---|
22 | |
---|
23 | void main( Fibonacci & fib ) with( fib ) { |
---|
24 | int fn1, fn2; // retained between resumes |
---|
25 | |
---|
26 | fn = 0; fn1 = fn; // 1st case |
---|
27 | suspend(); // restart last resume |
---|
28 | |
---|
29 | fn = 1; fn2 = fn1; fn1 = fn; // 2nd case |
---|
30 | suspend(); // restart last resume |
---|
31 | |
---|
32 | for ( ;; ) { |
---|
33 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case |
---|
34 | suspend(); // restart last resume |
---|
35 | } // for |
---|
36 | } |
---|
37 | |
---|
38 | int next( Fibonacci & fib ) with( fib ) { |
---|
39 | resume( fib ); // restart last suspend |
---|
40 | return fn; |
---|
41 | } |
---|
42 | |
---|
43 | int main() { |
---|
44 | Fibonacci f1, f2; |
---|
45 | for ( int i = 1; i <= 10; i += 1 ) { |
---|
46 | sout | next( f1 ) | next( f2 ) | endl; |
---|
47 | } // for |
---|
48 | } |
---|
49 | |
---|
50 | // Local Variables: // |
---|
51 | // tab-width: 4 // |
---|
52 | // compile-command: "cfa fibonacci.c" // |
---|
53 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.