Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/coroutine.c

    r83a071f9 rec95d11  
    1 //
     1// 
    22// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 //
    7 // fibonacci.c --
    8 //
     6// 
     7// fibonacci.c -- 
     8// 
    99// Author           : Thierry Delisle
    1010// Created On       : Thu Jun  8 07:29:37 2017
     
    1212// Last Modified On : Thu Jun  8 07:37:12 2017
    1313// Update Count     : 5
    14 //
     14// 
    1515
    1616#include <fstream>
     
    2121};
    2222
    23 void ?{}( Fibonacci & this ) {
    24         this.fn = 0;
     23void ?{}( Fibonacci * this ) {
     24        this->fn = 0;
    2525}
    2626
    27 void main( Fibonacci & this ) {
     27void main( Fibonacci * this ) {
    2828        int fn1, fn2;                                   // retained between resumes
    29         this.fn = 0;                                    // case 0
    30         fn1 = this.fn;
     29        this->fn = 0;                                   // case 0
     30        fn1 = this->fn;
    3131        suspend();                                              // return to last resume
    3232
    33         this.fn = 1;                                    // case 1
     33        this->fn = 1;                                   // case 1
    3434        fn2 = fn1;
    35         fn1 = this.fn;
     35        fn1 = this->fn;
    3636        suspend();                                              // return to last resume
    3737
    3838        for ( ;; ) {                                    // general case
    39                 this.fn = fn1 + fn2;
     39                this->fn = fn1 + fn2;
    4040                fn2 = fn1;
    41                 fn1 = this.fn;
     41                fn1 = this->fn;
    4242                suspend();                                      // return to last resume
    4343        } // for
    4444}
    4545
    46 int next( Fibonacci & this ) {
     46int next( Fibonacci * this ) {
    4747        resume( this );                                 // transfer to last suspend
    48         return this.fn;
     48        return this->fn;
    4949}
    5050
     
    5252        Fibonacci f1, f2;
    5353        for ( int i = 1; i <= 10; i += 1 ) {
    54                 sout | next( f1 ) | ' ' | next( f2 ) | endl;
     54                sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
    5555        } // for
    5656}
Note: See TracChangeset for help on using the changeset viewer.