// // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // fibonacci_1.cfa -- 1-state finite-state machine: precomputed first two states returning f(n - 1) // // Author : Peter A. Buhr // Created On : Thu Apr 26 23:20:08 2018 // Last Modified By : Peter A. Buhr // Last Modified On : Fri Mar 22 17:26:41 2019 // Update Count : 28 // #include #include coroutine Fibonacci { int fn1; }; // used for communication void main( Fibonacci & fib ) with( fib ) { // called on first resume int fn; [fn1, fn] = [0, 1]; // precompute first two states for () { suspend(); // restart last resume [fn1, fn] = [fn, fn1 + fn]; // general case } // for } int ?()( Fibonacci & fib ) with( fib ) { // function call operator resume( fib ); // restart last suspend return fn1; } int main() { Fibonacci f1, f2; for ( 10 ) { // print N Fibonacci values sout | f1() | f2(); } // for } // Local Variables: // // tab-width: 4 // // compile-command: "cfa fibonacci_1.cfa" // // End: //