Changeset 3ac5fd8 for tests/coroutine


Ignore:
Timestamp:
Aug 17, 2024, 3:15:21 PM (8 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
df2e00f
Parents:
afb15cf
Message:

first attempt changing end-of-file to an exception

Location:
tests/coroutine
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • tests/coroutine/.expect/fmtLines.txt

    rafb15cf r3ac5fd8  
    99E" d  istr  ibut  ed w  ith   
    1010Cfor  all.  ////   fmt  Line 
    11 s.cc   --/  ///   Auth  or   
    12              : P  eter   A.   
    13 Buhr  // C  reat  ed O  n     
    14       : Su  n Se  p 17   21: 
    15 56:1  5 20  17//   Las  t Mo 
    16 difi  ed B  y :   Pete  r A. 
    17  Buh  r//   Last   Mod  ifie 
    18 d On   : F  ri M  ar 2  2 13 
    19 :41:  03 2  019/  / Up  date 
    20  Cou  nt       :   33/  /#in 
    21 clud  e <f  stre  am.h  fa># 
    22 incl  ude   <cor  outi  ne.h 
    23 fa>c  orou  tine   For  mat   
    24 {       ch  ar c  h;                                                                             
    25         //   used   for   com  muni 
    26 cati  on        i  nt g  , b;                             
    27                                                         /  / gl  obal   bec 
    28 ause   use  d in   des  truc 
    29 tor}  ;voi  d ?{  }( F  orma 
    30 t &   fmt   ) {      r  esum 
    31 e( f  mt )  ;                                                                           / 
    32 / st  art   coro  utin  e}vo 
    33 id ^  ?{}(   For  mat   & fm 
    34 t )   {      if   ( fm  t.g   
    35 != 0   ||   fmt.  b !=   0 ) 
    36  sou  t |   nl;}  void   mai 
    37 n( F  orma  t &   fmt   ) {       
    38 for   ( ;;   ) {                                                                 
    39                 //   for   as   many   cha 
    40 ract  ers               for   ( f  mt.g 
    41  = 0  ; fm  t.g   < 5;   fmt 
    42 .g +  = 1   ) {         //   grou 
     11s.cc   --   form  at c  hara 
     12cter  s in  to b  lock  s of 
     13 4 a  nd g  roup  s of   5 b 
     14lock  s pe  r li  ne//  // A 
     15utho  r                 : Pe 
     16ter   A. B  uhr/  / Cr  eate 
     17d On           :   Sun   Sep 
     18 17   21:5  6:15   201  7//   
     19Last   Mod  ifie  d By   : P 
     20eter   A.   Buhr  // L  ast   
     21Modi  fied   On   : Sa  t Au 
     22g 17   14:  26:0  3 20  24// 
     23 Upd  ate   Coun  t       :   
     2460//  #inc  lude   <fs  trea 
     25m.hf  a>#i  nclu  de <  coro 
     26utin  e.hf  a>co  rout  ine   
     27Form  at {      cha  r ch  ;                     
     28                                                                  // u  sed   for   
     29comm  unic  atio  n     in  t g, 
     30 b;                                                                                     //   glo 
     31bal   beca  use   used   in   
     32dest  ruct  or};  void   mai 
     33n( F  orma  t &   fmt   ) wi 
     34th(   fmt   ) {   for   () { 
     35                                                                                        /  / fo  r as 
     36 man  y ch  arac  ters                  fo 
     37r (   g =   0; g   < 5  ; g   
     38+= 1   ) {                                      //   grou 
    4339ps o  f 5   bloc  ks                    for 
    44  ( f  mt.b   = 0  ; fm  t.b   
    45 < 4;   fmt  .b +  = 1   ) {       
    46 // b  lock  s of   4 c  hara 
    47 cter  s                         for   ( ;  ; )   
    48 {                                                         // f  or n  ewli 
    49 ne c  hara  cter  s                                     su 
    50 spen  d;                                        i  f (   fmt. 
    51 ch !  = '\  n' )   bre  ak;       
    52         //   igno  re n  ewli  ne                 
    53                 }   // f  or                            so  ut | 
    54  fmt  .ch;                                                      /  / pr 
    55 int   char  acte  r                       } // 
    56  for                    s  out   | "    ";       
    57                                                         /  / pr  int   bloc 
    58 k se  para  tor         } /  / fo 
    59 r               s  out   | nl  ;                                                         
    60                 //   pri  nt g  roup   sep 
    61 arat  or        }   //   for}   //   
    62 main  void   prt  ( Fo  rmat 
    63  & f  mt,   char   ch   ) {   
    64    f  mt.c  h =   ch;      r 
    65 esum  e( f  mt )  ;} /  / pr 
    66 tint   mai  n()   {     Fo  rmat 
    67  fmt  ; ch  ar c  h;    f  or ( 
    68  ;;   ) {               sin   | c  h;             
    69                                                                   // r  ead   one   
    70 char  acte  r       if (   eof 
    71 ( si  n )   ) br  eak;                                   
    72                         /  / eo  f ?            prt  ( fm 
    73 t, c  h );      } /  / fo  r} / 
    74 / ma  in//   Loc  al V  aria 
    75 bles  : //  // t  ab-w  idth 
    76 : 4   ////   com  pile  -com 
    77 mand  : "c  fa f  mtLi  nes. 
    78 cfa"   ///  / En  d: /  /
     40 ( b   = 0  ; b   < 4;   b + 
     41= 1   ) {                               /  / bl  ocks 
     42 of   4 ch  arac  ters                                   
     43for   () {                                                                // f 
     44or n  ewli  ne c  hara  cter 
     45s                                       su  spen  d;                               
     46if (   ch   != '  \n'   ) br 
     47eak;                              // i  gnor  e ne 
     48wlin  e                         } /  / fo  r                     
     49        sou  t |   ch;                                                          / 
     50/ pr  int   char  acte  r                         
     51} //   for                      s  out   | "   
     52 ";                                                             /  / pr  int   
     53bloc  k se  para  tor           } / 
     54/ fo  r         s  out   | nl  ;                         
     55                                                        /  / pr  int   grou 
     56p se  para  tor   } //   for 
     57} //   mai  nvoi  d ?{  }( F 
     58orma  t &   fmt   ) {     resu 
     59me(   fmt   );                                                                           
     60// p  rime   (st  art)   cor 
     61outi  ne}v  oid   ^?{}  ( Fo 
     62rmat   & f  mt )   wit  h( f 
     63mt )   {        i  f (   g !=   0 | 
     64| b   != 0   ) s  out   | nl 
     65;}vo  id f  orma  t( F  orma 
     66t &   fmt   ) {   resu  me(   
     67fmt   );}   // f  orma  tint 
     68 mai  n()   {   Fo  rmat   fmt 
     69;       so  ut |   nlO  ff;                                       
     70                                        //   turn   off   aut 
     71o ne  wlin  e   tr  y {         for 
     72 ()   {                                                                         /  / re 
     73ad u  ntil   end   of   file 
     74                        s  in |   fmt  .ch;                               
     75                                  // r  ead   one   char 
     76acte  r                   form  at(   fmt   
     77);                                                              //   pus  h ch 
     78arac  ter   for   form  atti 
     79ng                } //   for    } c  atch 
     80( en  d_of  _fil  e *   ) {       
     81} //   try  } //   mai  n
  • tests/coroutine/.in/fmtLines.txt

    rafb15cf r3ac5fd8  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // fmtLines.cc --
     7// fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Sun Sep 17 21:56:15 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 22 13:41:03 2019
    13 // Update Count     : 33
     12// Last Modified On : Sat Aug 17 14:26:03 2024
     13// Update Count     : 60
    1414//
    1515
     
    2222};
    2323
    24 void ?{}( Format & fmt ) {
    25     resume( fmt );                                                                              // start coroutine
    26 }
    27 
    28 void ^?{}( Format & fmt ) {
    29     if ( fmt.g != 0 || fmt.b != 0 ) sout | nl;
    30 }
    31 
    32 void main( Format & fmt ) {
    33         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
    36                                 for ( ;; ) {                                                    // for newline characters
     24void main( Format & fmt ) with( fmt ) {
     25        for () {                                                                                        // for as many characters
     26                for ( g = 0; g < 5; g += 1 ) {                                  // groups of 5 blocks
     27                        for ( b = 0; b < 4; b += 1 ) {                          // blocks of 4 characters
     28                                for () {                                                                // for newline characters
    3729                                        suspend;
    38                                         if ( fmt.ch != '\n' ) break;            // ignore newline
     30                                  if ( ch != '\n' ) break;                              // ignore newline
    3931                                } // for
    40                                 sout | fmt.ch;                                                  // print character
     32                                sout | ch;                                                              // print character
    4133                        } // for
    4234                        sout | "  ";                                                            // print block separator
    4335                } // for
    44                 sout | nl;                                                                      // print group separator
     36                sout | nl;                                                                              // print group separator
    4537        } // for
    4638} // main
    4739
    48 void prt( Format & fmt, char ch ) {
    49     fmt.ch = ch;
    50     resume( fmt );
    51 } // prt
     40void ?{}( Format & fmt ) {
     41        resume( fmt );                                                                          // prime (start) coroutine
     42}
     43
     44void ^?{}( Format & fmt ) with( fmt ) {
     45        if ( g != 0 || b != 0 ) sout | nl;
     46}
     47
     48void format( Format & fmt ) {
     49        resume( fmt );
     50} // format
    5251
    5352int main() {
    5453        Format fmt;
    55         char ch;
     54        sout | nlOff;                                                                           // turn off auto newline
    5655
    57         for ( ;; ) {
    58                 sin | ch;                                                                               // read one character
    59           if ( eof( sin ) ) break;                                                      // eof ?
    60                 prt( fmt, ch );
    61         } // for
     56        try {
     57                for () {                                                                                // read until end of file
     58                        sin | fmt.ch;                                                           // read one character
     59                        format( fmt );                                                          // push character for formatting
     60                } // for
     61        } catch( end_of_file * ) {
     62        } // try
    6263} // main
    63 
    64 // Local Variables: //
    65 // tab-width: 4 //
    66 // compile-command: "cfa fmtLines.cfa" //
    67 // End: //
  • tests/coroutine/cntparens.cfa

    rafb15cf r3ac5fd8  
    1010// Created On       : Sat Apr 20 11:04:45 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 20 11:06:21 2019
    13 // Update Count     : 1
     12// Last Modified On : Thu Aug 15 20:39:34 2024
     13// Update Count     : 2
    1414//
    1515
     
    4646        char ch;
    4747
    48         for () {                                                                                        // read until end of file
    49                 sin | ch;                                                                               // read one character
    50           if ( eof( sin ) ) { sout | "Error"; break; }          // eof ?
    51                 Status ret = next( cpns, ch );                                  // push character for formatting
    52           if ( ret == Match ) { sout | "Match"; break; }
    53           if ( ret == Error ) { sout | "Error"; break; }
    54         } // for
     48        try {
     49                for () {                                                                                        // read until end of file
     50                        sin | ch;                                                                               // read one character
     51                        Status ret = next( cpns, ch );                                  // push character for formatting
     52                        if ( ret == Match ) { sout | "Match"; break; }
     53                        if ( ret == Error ) { sout | "Error"; break; }
     54                } // for
     55        } catch( end_of_file * ) {
     56                sout | "Error";
     57        } // try
    5558} // main
    5659
  • tests/coroutine/devicedriver.cfa

    rafb15cf r3ac5fd8  
    1010// Created On       : Sat Mar 16 15:30:34 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 17 09:11:56 2023
    13 // Update Count     : 94
     12// Last Modified On : Thu Aug 15 18:45:45 2024
     13// Update Count     : 96
    1414//
    1515
     
    7171
    7272        sin | nlOn;                                                                                     // read newline (all) characters
    73   eof: for () {                                                                                 // read until end of file
    74                 sin | byte;                                                                             // read one character
    75           if ( eof( sin ) ) break eof;                                          // eof ?
    76                 choose( next( driver, byte ) ) {                                // analyse character
    77                   case CONT: ;
    78                   case MSG: sout | "msg:" | msg;
    79                   case ESTX: sout | "STX in message";
    80                   case ELNTH: sout | "message too long";
    81                   case ECRC: sout | "CRC failure";
    82                 } // choose
    83         } // for
     73        try {
     74                for () {                                                                                // read until end of file
     75                        sin | byte;                                                                     // read one character
     76                        choose( next( driver, byte ) ) {                        // analyse character
     77                          case CONT: ;
     78                          case MSG: sout | "msg:" | msg;
     79                          case ESTX: sout | "STX in message";
     80                          case ELNTH: sout | "message too long";
     81                          case ECRC: sout | "CRC failure";
     82                        } // choose
     83                } // for
     84        } catch( end_of_file * ) {
     85        } // try
    8486} // main
    8587
  • tests/coroutine/fmtLines.cfa

    rafb15cf r3ac5fd8  
    1010// Created On       : Sun Sep 17 21:56:15 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 22 13:41:16 2019
    13 // Update Count     : 58
     12// Last Modified On : Sat Aug 17 14:26:03 2024
     13// Update Count     : 60
    1414//
    1515
     
    5454        sout | nlOff;                                                                           // turn off auto newline
    5555
    56   eof: for () {                                                                                 // read until end of file
    57                 sin | fmt.ch;                                                                   // read one character
    58           if ( eof( sin ) ) break eof;                                          // eof ?
    59                 format( fmt );                                                                  // push character for formatting
    60         } // for
     56        try {
     57                for () {                                                                                // read until end of file
     58                        sin | fmt.ch;                                                           // read one character
     59                        format( fmt );                                                          // push character for formatting
     60                } // for
     61        } catch( end_of_file * ) {
     62        } // try
    6163} // main
    62 
    63 // Local Variables: //
    64 // tab-width: 4 //
    65 // compile-command: "cfa fmtLines.cfa" //
    66 // End: //
Note: See TracChangeset for help on using the changeset viewer.