ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
with_gc
Last change
on this file since ca54499 was 71b50f36, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago |
formatting
|
-
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 | //
|
---|
10 | // Author : Thierry Delisle
|
---|
11 | // Created On : Thu Jun 8 07:29:37 2017
|
---|
12 | // Last Modified By : Peter A. Buhr
|
---|
13 | // Last Modified On : Fri Apr 27 08:55:31 2018
|
---|
14 | // Update Count : 19
|
---|
15 | //
|
---|
16 |
|
---|
17 | #include <fstream>
|
---|
18 | #include <coroutine>
|
---|
19 |
|
---|
20 | coroutine Fibonacci { int fn; }; // used for communication
|
---|
21 |
|
---|
22 | void main( Fibonacci & fib ) with( fib ) { // called on first resume
|
---|
23 | int fn1, fn2; // retained between resumes
|
---|
24 | fn = 0; fn1 = fn; // 1st case
|
---|
25 | suspend(); // restart last resume
|
---|
26 | fn = 1; fn2 = fn1; fn1 = fn; // 2nd case
|
---|
27 | suspend(); // restart last resume
|
---|
28 | for ( ;; ) {
|
---|
29 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case
|
---|
30 | suspend(); // restart last resume
|
---|
31 | } // for
|
---|
32 | }
|
---|
33 |
|
---|
34 | int next( Fibonacci & fib ) with( fib ) {
|
---|
35 | resume( fib ); // restart last suspend
|
---|
36 | return fn;
|
---|
37 | }
|
---|
38 |
|
---|
39 | int main() {
|
---|
40 | Fibonacci f1, f2;
|
---|
41 | for ( int i = 1; i <= 10; i += 1 ) {
|
---|
42 | sout | next( f1 ) | next( f2 ) | endl;
|
---|
43 | } // for
|
---|
44 | }
|
---|
45 |
|
---|
46 | // Local Variables: //
|
---|
47 | // tab-width: 4 //
|
---|
48 | // compile-command: "cfa fibonacci.c" //
|
---|
49 | // End: //
|
---|
Note:
See
TracBrowser
for help on using the repository browser.