Ignore:
Timestamp:
Dec 6, 2017, 8:01:23 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
16988e8
Parents:
65197c2
Message:

add "with" clause to test programs

File:
1 moved

Legend:

Unmodified
Added
Removed
  • src/tests/coroutine/fibonacci.c

    r65197c2 r971d9f2  
    1010// Created On       : Thu Jun  8 07:29:37 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep 17 21:38:15 2017
    13 // Update Count     : 7
     12// Last Modified On : Tue Dec  5 22:27:54 2017
     13// Update Count     : 14
    1414//
    1515
     
    1717#include <coroutine>
    1818
    19 coroutine Fibonacci {
    20         int fn;                                                                                         // used for communication
    21 };
     19coroutine Fibonacci { int fn; };                                                // used for communication
    2220
    23 void ?{}( Fibonacci & this ) {
    24         this.fn = 0;
    25 }
     21void ?{}( Fibonacci & fib ) with( fib ) { fn = 0; }
    2622
    27 void main( Fibonacci & this ) {
     23void main( Fibonacci & fib ) with( fib ) {
    2824        int fn1, fn2;                                                                           // retained between resumes
    29         this.fn = 0;                                                                            // case 0
    30         fn1 = this.fn;
     25
     26        fn = 0; fn1 = fn;                                                                       // 1st case
    3127        suspend();                                                                                      // restart last resume
    3228
    33         this.fn = 1;                                                                            // case 1
    34         fn2 = fn1;  fn1 = this.fn;
     29        fn = 1; fn2 = fn1;  fn1 = fn;                                           // 2nd case
    3530        suspend();                                                                                      // restart last resume
    3631
    37         for ( ;; ) {                                                                            // general case
    38                 this.fn = fn1 + fn2;
    39                 fn2 = fn1;  fn1 = this.fn;
     32        for ( ;; ) {
     33                fn = fn1 + fn2; fn2 = fn1;  fn1 = fn;                   // general case
    4034                suspend();                                                                              // restart last resume
    4135        } // for
    4236}
    4337
    44 int next( Fibonacci & this ) {
    45         resume( this );                                                                         // restart last suspend
    46         return this.fn;
     38int next( Fibonacci & fib ) with( fib ) {
     39        resume( fib );                                                                          // restart last suspend
     40        return fn;
    4741}
    4842
Note: See TracChangeset for help on using the changeset viewer.