ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since d3b95f1 was
600d7be,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
example updates
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
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.cfa -- 1-state finite-state machine: precomputed first two states returning f(n - 1) |
---|
8 | // |
---|
9 | // Author : Peter A. Buhr |
---|
10 | // Created On : Thu Apr 26 23:20:08 2018 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sat May 18 08:55:59 2019 |
---|
13 | // Update Count : 36 |
---|
14 | // |
---|
15 | |
---|
16 | #include <fstream.hfa> |
---|
17 | #include <coroutine.hfa> |
---|
18 | |
---|
19 | coroutine Fibonacci { int fn1, fn; }; // used for communication |
---|
20 | |
---|
21 | void main( Fibonacci & fib ) with( fib ) { // called on first resume |
---|
22 | [fn1, fn] = [1, 0]; // precompute first two states |
---|
23 | for () { |
---|
24 | suspend(); // restart last resume |
---|
25 | [fn1, fn] = [fn, fn1 + fn]; // general case |
---|
26 | } // for |
---|
27 | } |
---|
28 | |
---|
29 | int ?()( Fibonacci & fib ) with( fib ) { // function call operator |
---|
30 | return resume( fib ).fn1; // restart last suspend |
---|
31 | } |
---|
32 | |
---|
33 | int main() { |
---|
34 | Fibonacci f1, f2; |
---|
35 | for ( 10 ) { // print N Fibonacci values |
---|
36 | sout | resume( f1 ).fn | resume( f2 ).fn; |
---|
37 | } // for |
---|
38 | } |
---|
39 | |
---|
40 | // Local Variables: // |
---|
41 | // tab-width: 4 // |
---|
42 | // compile-command: "cfa Fib2.cfa" // |
---|
43 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.