Ignore:
Timestamp:
Mar 22, 2019, 3:28:14 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f8cd310
Parents:
17c6c1c3
Message:

refactor to look more like python

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/coroutine/fibonacci_1.cfa

    r17c6c1c3 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.