Ignore:
Timestamp:
Dec 6, 2017, 8:01:23 AM (8 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

Location:
src/tests/coroutine
Files:
2 edited
2 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
  • src/tests/coroutine/fmtLines.c

    r65197c2 r971d9f2  
    1010// Created On       : Sun Sep 17 21:56:15 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct  1 11:57:19 2017
    13 // Update Count     : 34
     12// Last Modified On : Tue Dec  5 21:56:35 2017
     13// Update Count     : 38
    1414//
    1515
     
    2626}
    2727
    28 void ^?{}( Format & fmt ) {
    29         if ( fmt.g != 0 || fmt.b != 0 ) sout | endl;
     28void ^?{}( Format & fmt ) with( fmt ) {
     29        if ( g != 0 || b != 0 ) sout | endl;
    3030}
    3131
    32 void main( Format & fmt ) {
     32void main( Format & fmt ) with( fmt ) {
    3333        for ( ;; ) {                                                                            // for as many characters
    34                 for ( fmt.g = 0; fmt.g < 5; fmt.g += 1 ) {              // groups of 5 blocks
    35                         for ( fmt.b = 0; fmt.b < 4; fmt.b += 1 ) {      // blocks of 4 characters
     34                for ( g = 0; g < 5; g += 1 ) {                                  // groups of 5 blocks
     35                        for ( b = 0; b < 4; b += 1 ) {                          // blocks of 4 characters
    3636                                for ( ;; ) {                                                    // for newline characters
    3737                                        suspend();
    38                                         if ( fmt.ch != '\n' ) break;            // ignore newline
     38                                        if ( ch != '\n' ) break;                        // ignore newline
    3939                                } // for
    40                                 sout | fmt.ch;                                                  // print character
     40                                sout | ch;                                                              // print character
    4141                        } // for
    4242                        sout | "  ";                                                            // print block separator
  • src/tests/coroutine/prodcons.c

    r65197c2 r971d9f2  
    1010// Created On       : Mon Sep 18 12:23:39 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Oct 30 23:06:05 2017
    13 // Update Count     : 42
     12// Last Modified On : Tue Dec  5 22:40:55 2017
     13// Update Count     : 46
    1414//
    1515
     
    2424
    2525coroutine Prod {
    26         Cons *c;
     26        Cons * c;
    2727        int N, money, receipt;
    2828};
    29 void main( Prod & prod ) {                                                              // starter ::main
     29void main( Prod & prod ) with( prod ) {                                 // starter ::main
    3030        // 1st resume starts here
    31         for ( int i = 0; i < prod.N; i += 1 ) {
     31        for ( int i = 0; i < N; i += 1 ) {
    3232                int p1 = random( 100 );
    3333                int p2 = random( 100 );
    3434                sout | p1 | " " | p2 | endl;
    35                 int status = delivery( *prod.c, p1, p2 );
    36                 sout | " $" | prod.money | endl;
     35                int status = delivery( *c, p1, p2 );
     36                sout | " $" | money | endl;
    3737                sout | status | endl;
    38                 prod.receipt += 1;
     38                receipt += 1;
    3939        }
    40         stop( *prod.c );
     40        stop( *c );
    4141        sout | "prod stops" | endl;
    4242}
     
    6464}
    6565void ^?{}( Cons & cons ) {}
    66 void main( Cons & cons ) {                                                              // starter prod
     66void main( Cons & cons ) with( cons ) {                                 // starter prod
    6767        // 1st resume starts here
    6868        int money = 1, receipt;
    69         for ( ; ! cons.done; ) {
    70                 sout | cons.p1 | " " | cons.p2 | endl;
     69        for ( ; ! done; ) {
     70                sout | p1 | " " | p2 | endl;
    7171                sout | " $" | money | endl;
    72                 cons.status += 1;
    73                 receipt = payment( *cons.p, money );
     72                status += 1;
     73                receipt = payment( *p, money );
    7474                sout | " #" | receipt | endl;
    7575                money += 1;
Note: See TracChangeset for help on using the changeset viewer.