Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/coroutine/fibonacci_1.cfa

    r107b01a r386e710  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // fibonacci_1.c -- 1-state finite-state machine: precomputed first two states returning f(n - 2)
     7// fibonacci_1.cfa -- 1-state finite-state machine: precomputed first two states returning f(n - 1)
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Apr 26 23:20:08 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 11 21:57:54 2018
    13 // Update Count     : 14
     12// Last Modified On : Thu Mar 21 08:10:45 2019
     13// Update Count     : 25
    1414//
    1515
     
    1717#include <coroutine.hfa>
    1818
    19 coroutine Fibonacci { int ret; };                                               // used for communication
     19coroutine Fibonacci { int fn1; };                                               // used for communication
    2020
    2121void main( Fibonacci & fib ) with( fib ) {                              // called on first resume
    22         int fn, fn1 = 1, fn2 = 0;                                                       // precompute first two states
     22        int fn;
     23        [fn1, fn] = [0, 1];                                                                     // precompute first two states
    2324        for () {
    24                 ret = fn2;
    25                 fn = fn1 + fn2;  fn2 = fn1;  fn1 = fn;                  // general case
    2625                suspend();                                                                              // restart last resume
     26                [fn1, fn] = [fn, fn1 + fn];                                             // general case
    2727        } // for
    2828}
     
    3030int next( Fibonacci & fib ) with( fib ) {
    3131        resume( fib );                                                                          // restart last suspend
    32         return ret;
     32        return fn1;
    3333}
    3434
     
    4242// Local Variables: //
    4343// tab-width: 4 //
    44 // compile-command: "cfa fibonacci_1.c" //
     44// compile-command: "cfa fibonacci_1.cfa" //
    4545// End: //
Note: See TracChangeset for help on using the changeset viewer.