Changes in / [25cdca5:84b4d607]


Ignore:
Files:
21 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 18:33:38 2018
    13 // Update Count     : 304
     12// Last Modified On : Wed Dec 12 08:34:28 2018
     13// Update Count     : 298
    1414//
    1515
     
    2626#define IO_MSG "I/O error: "
    2727
    28 void ?{}( ofstream & os, void * file, bool sepDefault, bool sepOnOff, bool nlOnOff, bool prt, const char * separator, const char * tupleSeparator ) {
     28void ?{}( ofstream & os, void * file, bool sepDefault, bool sepOnOff, bool nlOnOff, bool nonlManip, const char * separator, const char * tupleSeparator ) {
    2929        os.file = file;
    3030        os.sepDefault = sepDefault;
    3131        os.sepOnOff = sepOnOff;
    3232        os.nlOnOff = nlOnOff;
    33         os.prt = prt;
     33        os.nonlManip = nonlManip;
    3434        sepSet( os, separator );
    3535        sepSetCur( os, sepGet( os ) );
     
    4646void setNL( ofstream & os, bool state ) { os.sawNL = state; }
    4747bool getANL( ofstream & os ) { return os.nlOnOff; }
    48 bool getPrt( ofstream & os ) { return os.prt; }
    49 void setPrt( ofstream & os, bool state ) { os.prt = state; }
     48bool getNonl( ofstream & os ) { return os.nonlManip; }
     49void setNonl( ofstream & os, bool state ) { os.nonlManip = state; }
    5050
    5151// public
     
    150150        va_end( args );
    151151
    152         setPrt( os, true );                                                                     // called in output cascade
    153152        sepReset( os );                                                                         // reset separator
    154153        return len;
  • libcfa/src/fstream.hfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 18:33:41 2018
    13 // Update Count     : 149
     12// Last Modified On : Wed Dec 12 07:52:41 2018
     13// Update Count     : 143
    1414//
    1515
     
    2424        bool sepOnOff;
    2525        bool nlOnOff;
    26         bool prt;                                                                                       // print text
     26        bool nonlManip;
    2727        bool sawNL;
    2828        const char * sepCur;
     
    4040void setNL( ofstream &, bool );
    4141bool getANL( ofstream & );
    42 bool getPrt( ofstream & );
    43 void setPrt( ofstream &, bool );
     42bool getNonl( ofstream & );
     43void setNonl( ofstream &, bool );
    4444
    4545// public
     
    6262void close( ofstream & );
    6363ofstream & write( ofstream &, const char * data, size_t size );
    64 int fmt( ofstream &, const char format[], ... );
     64int fmt( ofstream &, const char fmt[], ... );
    6565
    6666void ?{}( ofstream & os );
     
    8383ifstream & read( ifstream & is, char * data, size_t size );
    8484ifstream & ungetc( ifstream & is, char c );
    85 int fmt( ifstream &, const char format[], ... );
     85int fmt( ifstream &, const char fmt[], ... );
    8686
    8787void ?{}( ifstream & is );
  • libcfa/src/iostream.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 18:33:40 2018
    13 // Update Count     : 589
     12// Last Modified On : Thu Dec 13 14:13:22 2018
     13// Update Count     : 548
    1414//
    1515
     
    3333        } // ?|?
    3434        void ?|?( ostype & os, bool b ) {
    35                 (ostype &)(os | b); nl( os );
     35                (ostype)(os | b); if ( getANL( os ) ) nl( os );
    3636        } // ?|?
    3737
     
    4242        } // ?|?
    4343        void ?|?( ostype & os, char c ) {
    44                 (ostype &)(os | c); nl( os );
     44                (ostype)(os | c); if ( getANL( os ) ) nl( os );
    4545        } // ?|?
    4646
     
    5151        } // ?|?
    5252        void ?|?( ostype & os, signed char sc ) {
    53                 (ostype &)(os | sc); nl( os );
     53                (ostype)(os | sc); if ( getANL( os ) ) nl( os );
    5454        } // ?|?
    5555
     
    6060        } // ?|?
    6161        void ?|?( ostype & os, unsigned char usc ) {
    62                 (ostype &)(os | usc); nl( os );
     62                (ostype)(os | usc); if ( getANL( os ) ) nl( os );
    6363        } // ?|?
    6464
     
    6969        } // ?|?
    7070        void & ?|?( ostype & os, short int si ) {
    71                 (ostype &)(os | si); nl( os );
     71                (ostype)(os | si); if ( getANL( os ) ) nl( os );
    7272        } // ?|?
    7373
     
    7878        } // ?|?
    7979        void & ?|?( ostype & os, unsigned short int usi ) {
    80                 (ostype &)(os | usi); nl( os );
     80                (ostype)(os | usi); if ( getANL( os ) ) nl( os );
    8181        } // ?|?
    8282
     
    8787        } // ?|?
    8888        void & ?|?( ostype & os, int i ) {
    89                 (ostype &)(os | i); nl( os );
     89                (ostype)(os | i); if ( getANL( os ) ) nl( os );
    9090        } // ?|?
    9191
     
    9696        } // ?|?
    9797        void & ?|?( ostype & os, unsigned int ui ) {
    98                 (ostype &)(os | ui); nl( os );
     98                (ostype)(os | ui); if ( getANL( os ) ) nl( os );
    9999        } // ?|?
    100100
     
    105105        } // ?|?
    106106        void & ?|?( ostype & os, long int li ) {
    107                 (ostype &)(os | li); nl( os );
     107                (ostype)(os | li); if ( getANL( os ) ) nl( os );
    108108        } // ?|?
    109109
     
    114114        } // ?|?
    115115        void & ?|?( ostype & os, unsigned long int uli ) {
    116                 (ostype &)(os | uli); nl( os );
     116                (ostype)(os | uli); if ( getANL( os ) ) nl( os );
    117117        } // ?|?
    118118
     
    123123        } // ?|?
    124124        void & ?|?( ostype & os, long long int lli ) {
    125                 (ostype &)(os | lli); nl( os );
     125                (ostype)(os | lli); if ( getANL( os ) ) nl( os );
    126126        } // ?|?
    127127
     
    132132        } // ?|?
    133133        void & ?|?( ostype & os, unsigned long long int ulli ) {
    134                 (ostype &)(os | ulli); nl( os );
     134                (ostype)(os | ulli); if ( getANL( os ) ) nl( os );
    135135        } // ?|?
    136136
     
    141141        } // ?|?
    142142        void & ?|?( ostype & os, float f ) {
    143                 (ostype &)(os | f); nl( os );
     143                (ostype)(os | f); if ( getANL( os ) ) nl( os );
    144144        } // ?|?
    145145
     
    150150        } // ?|?
    151151        void & ?|?( ostype & os, double d ) {
    152                 (ostype &)(os | d); nl( os );
     152                (ostype)(os | d); if ( getANL( os ) ) nl( os );
    153153        } // ?|?
    154154
     
    159159        } // ?|?
    160160        void & ?|?( ostype & os, long double ld ) {
    161                 (ostype &)(os | ld); nl( os );
     161                (ostype)(os | ld); if ( getANL( os ) ) nl( os );
    162162        } // ?|?
    163163
     
    168168        } // ?|?
    169169        void & ?|?( ostype & os, float _Complex fc ) {
    170                 (ostype &)(os | fc); nl( os );
     170                (ostype)(os | fc); if ( getANL( os ) ) nl( os );
    171171        } // ?|?
    172172
     
    177177        } // ?|?
    178178        void & ?|?( ostype & os, double _Complex dc ) {
    179                 (ostype &)(os | dc); nl( os );
     179                (ostype)(os | dc); if ( getANL( os ) ) nl( os );
    180180        } // ?|?
    181181
     
    186186        } // ?|?
    187187        void & ?|?( ostype & os, long double _Complex ldc ) {
    188                 (ostype &)(os | ldc); nl( os );
     188                (ostype)(os | ldc); if ( getANL( os ) ) nl( os );
    189189        } // ?|?
    190190
     
    228228        } // ?|?
    229229        void ?|?( ostype & os, const char * str ) {
    230                 (ostype &)(os | str); nl( os );
     230                (ostype)(os | str); if ( getANL( os ) ) nl( os );
    231231        } // ?|?
    232232
     
    257257        } // ?|?
    258258        void ?|?( ostype & os, const void * p ) {
    259                 (ostype &)(os | p); nl( os );
     259                (ostype)(os | p); if ( getANL( os ) ) nl( os );
    260260        } // ?|?
    261261
    262262        // manipulators
    263263        ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    264                 (ostype &)(manip( os ));
     264                (ostype)(manip( os ));
     265                setNonl( os, false );                                                   // ignore nonl in middle
    265266                return os;
    266267        } // ?|?
    267268        void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    268                 (ostype &)(manip( os ));
    269                 if ( getPrt( os ) ) nl( os );                                   // something printed ?
    270                 setPrt( os, false );                                                    // turn off
     269                (ostype)(manip( os ));
     270                if ( getANL( os ) && ! getNonl( os ) ) nl( os ); // ignore nl if nonl at end
     271                setNonl( os, false );
    271272        } // ?|?
    272273
    273274        ostype & sep( ostype & os ) {
    274                 return (ostype &)(os | sepGet( os ));
     275                return (ostype)(os | sepGet( os ));
    275276        } // sep
    276277
     
    280281
    281282        ostype & nl( ostype & os ) {
    282                 (ostype &)(os | '\n');
    283                 setPrt( os, false );                                                    // turn off
     283                (ostype)(os | '\n');
    284284                setNL( os, true );
    285285                flush( os );
     
    287287        } // nl
    288288
    289         void nl( ostype & os ) {
    290                 if ( getANL( os ) ) (ostype &)(nl( os ));               // implementation only
    291                 else setPrt( os, false );                                               // turn off
    292         } // nl
    293 
    294289        ostype & nonl( ostype & os ) {
    295                 setPrt( os, false );                                                    // turn off
     290                setNonl( os, true );                                                    // indicate nonl manipulator
    296291                return os;
    297292        } // nonl
     
    331326forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    332327        ostype & ?|?( ostype & os, T arg, Params rest ) {
    333                 (ostype &)(os | arg);                                                   // print first argument
     328                (ostype)(os | arg);                                                             // print first argument
    334329                sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
    335                 (ostype &)(os | rest);                                                  // print remaining arguments
     330                (ostype)(os | rest);                                                    // print remaining arguments
    336331                sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
    337332                return os;
    338333        } // ?|?
    339334        void ?|?( ostype & os, T arg, Params rest ) {
    340                 // (ostype &)(?|?( os, arg, rest )); nl( os );
    341                 (ostype &)(os | arg);                                                   // print first argument
     335//              (ostype)(?|?( os, arg, rest )); if ( getANL( os ) ) nl( os );
     336                (ostype)(os | arg);                                                             // print first argument
    342337                sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
    343                 (ostype &)(os | rest);                                                  // print remaining arguments
     338                (ostype)(os | rest);                                                    // print remaining arguments
    344339                sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
    345                 nl( os );
     340                if ( getANL( os ) ) nl( os );
    346341        } // ?|?
    347342} // distribution
  • libcfa/src/iostream.hfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 18:33:40 2018
    13 // Update Count     : 220
     12// Last Modified On : Tue Dec 11 22:01:31 2018
     13// Update Count     : 213
    1414//
    1515
     
    2020trait ostream( dtype ostype ) {
    2121        // private
    22         bool sepPrt( ostype & );                                                        // get separator state (on/off)
     22        bool sepPrt( ostype & );                                                        // return separator state (on/off)
    2323        void sepReset( ostype & );                                                      // set separator state to default state
    2424        void sepReset( ostype &, bool );                                        // set separator and default state
     
    2727        bool getNL( ostype & );                                                         // check newline
    2828        void setNL( ostype &, bool );                                           // saw newline
    29         bool getANL( ostype & );                                                        // get auto newline (on/off)
    30         bool getPrt( ostype & );                                                        // get fmt called in output cascade
    31         void setPrt( ostype &, bool );                                          // set fmt called in output cascade
     29        bool getANL( ostype & );                                                        // check auto newline
     30        bool getNonl( ostype & );                                                       // check nonnl manipulator
     31        void setNonl( ostype &, bool );                                         // set nonnl manipulator
    3232        // public
    3333        void sepOn( ostype & );                                                         // turn separator state on
     
    4848        void close( ostype & os );
    4949        ostype & write( ostype &, const char *, size_t );
    50         int fmt( ostype &, const char format[], ... );
     50        int fmt( ostype &, const char fmt[], ... );
    5151}; // ostream
    5252
     
    6363forall( dtype ostype | ostream( ostype ) ) {
    6464        ostype & ?|?( ostype &, bool );
    65         void ?|?( ostype &, bool );
     65        void & ?|?( ostype &, bool );
    6666
    6767        ostype & ?|?( ostype &, char );
    68         void ?|?( ostype &, char );
     68        void & ?|?( ostype &, char );
    6969        ostype & ?|?( ostype &, signed char );
    70         void ?|?( ostype &, signed char );
     70        void & ?|?( ostype &, signed char );
    7171        ostype & ?|?( ostype &, unsigned char );
    72         void ?|?( ostype &, unsigned char );
     72        void & ?|?( ostype &, unsigned char );
    7373
    7474        ostype & ?|?( ostype &, short int );
    75         void ?|?( ostype &, short int );
     75        void & ?|?( ostype &, short int );
    7676        ostype & ?|?( ostype &, unsigned short int );
    77         void ?|?( ostype &, unsigned short int );
     77        void & ?|?( ostype &, unsigned short int );
    7878        ostype & ?|?( ostype &, int );
    79         void ?|?( ostype &, int );
     79        void & ?|?( ostype &, int );
    8080        ostype & ?|?( ostype &, unsigned int );
    81         void ?|?( ostype &, unsigned int );
     81        void & ?|?( ostype &, unsigned int );
    8282        ostype & ?|?( ostype &, long int );
    83         void ?|?( ostype &, long int );
     83        void & ?|?( ostype &, long int );
    8484        ostype & ?|?( ostype &, long long int );
    85         void ?|?( ostype &, long long int );
     85        void & ?|?( ostype &, long long int );
    8686        ostype & ?|?( ostype &, unsigned long int );
    87         void ?|?( ostype &, unsigned long int );
     87        void & ?|?( ostype &, unsigned long int );
    8888        ostype & ?|?( ostype &, unsigned long long int );
    89         void ?|?( ostype &, unsigned long long int );
     89        void & ?|?( ostype &, unsigned long long int );
    9090
    9191        ostype & ?|?( ostype &, float ); // FIX ME: should not be required
    92         void ?|?( ostype &, float ); // FIX ME: should not be required
     92        void & ?|?( ostype &, float ); // FIX ME: should not be required
    9393        ostype & ?|?( ostype &, double );
    94         void ?|?( ostype &, double );
     94        void & ?|?( ostype &, double );
    9595        ostype & ?|?( ostype &, long double );
    96         void ?|?( ostype &, long double );
     96        void & ?|?( ostype &, long double );
    9797
    9898        ostype & ?|?( ostype &, float _Complex );
    99         void ?|?( ostype &, float _Complex );
     99        void & ?|?( ostype &, float _Complex );
    100100        ostype & ?|?( ostype &, double _Complex );
    101         void ?|?( ostype &, double _Complex );
     101        void & ?|?( ostype &, double _Complex );
    102102        ostype & ?|?( ostype &, long double _Complex );
    103         void ?|?( ostype &, long double _Complex );
     103        void & ?|?( ostype &, long double _Complex );
    104104
    105105        ostype & ?|?( ostype &, const char * );
    106         void ?|?( ostype &, const char * );
     106        void & ?|?( ostype &, const char * );
    107107        // ostype & ?|?( ostype &, const char16_t * );
    108108#if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
     
    111111        // ostype & ?|?( ostype &, const wchar_t * );
    112112        ostype & ?|?( ostype &, const void * );
    113         void ?|?( ostype &, const void * );
     113        void & ?|?( ostype &, const void * );
    114114
    115115        // manipulators
     
    117117        void ?|?( ostype &, ostype & (*)( ostype & ) );
    118118        ostype & nl( ostype & );
    119         void nl( ostype & );
    120119        ostype & nonl( ostype & );
    121120        ostype & sep( ostype & );
     
    150149        istype & read( istype &, char *, size_t );
    151150        istype & ungetc( istype &, char );
    152         int fmt( istype &, const char format[], ... );
     151        int fmt( istype &, const char fmt[], ... );
    153152}; // istream
    154153
  • libcfa/src/rational.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed Apr  6 17:54:28 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 23 22:56:49 2018
    13 // Update Count     : 170
     12// Last Modified On : Tue Dec 11 22:02:29 2018
     13// Update Count     : 168
    1414//
    1515
     
    181181
    182182                void ?|?( ostype & os, Rational(RationalImpl) r ) {
    183                         (ostype &)(os | r); nl( os );
     183                        (ostype)(os | r); if ( getANL( os ) ) nl( os );
    184184                } // ?|?
    185185        } // distribution
  • libcfa/src/stdlib.hfa

    r25cdca5 r84b4d607  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 17 15:37:45 2018
    13 // Update Count     : 346
     12// Last Modified On : Fri Jul 27 07:21:36 2018
     13// Update Count     : 345
    1414//
    1515
     
    178178
    179179static inline {
    180         int ato( const char * sptr ) { return (int)strtol( sptr, 0, 10 ); }
     180        int ato( const char * sptr ) {return (int)strtol( sptr, 0, 10 ); }
    181181        unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
    182182        long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
  • libcfa/src/time.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Tue Mar 27 13:33:14 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 23 22:57:48 2018
    13 // Update Count     : 57
     12// Last Modified On : Tue Dec 11 21:32:15 2018
     13// Update Count     : 53
    1414//
    1515
     
    3333forall( dtype ostype | ostream( ostype ) ) {
    3434        ostype & ?|?( ostype & os, Duration dur ) with( dur ) {
    35                 (ostype &)(os | tv / TIMEGRAN);                                 // print seconds
     35                (ostype)(os | tv / TIMEGRAN);                                   // print seconds
    3636                long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;   // compute nanoseconds
    3737                if ( ns != 0 ) {                                                                // some ?
    3838                        char buf[16];
    39                         (ostype &)(os | nanomsd( ns, buf ));                    // print nanoseconds
     39                        (ostype)(os | nanomsd( ns, buf ));                      // print nanoseconds
    4040                } // if
    4141                return os;
     
    4343
    4444        void ?|?( ostype & os, Duration dur ) with( dur ) {
    45                 (ostype &)(os | dur); nl( os );
     45                (ostype)(os | dur); if ( getANL( os ) ) nl( os );
    4646        } // ?|?
    4747} // distribution
     
    150150                long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;   // compute nanoseconds
    151151                if ( ns == 0 ) {                                                                // none ?
    152                         (ostype &)(os | buf);                                                   // print date/time/year
     152                        (ostype)(os | buf);                                                     // print date/time/year
    153153                } else {
    154154                        buf[19] = '\0';                                                         // truncate to "Wed Jun 30 21:49:08"
    155155                        char buf2[16];
    156156                        nanomsd( ns, buf2 );                                            // compute nanoseconds
    157                         (ostype &)(os | buf | buf2 | ' ' | &buf[20]);   // print date/time, nanoseconds and year
     157                        (ostype)(os | buf | buf2 | ' ' | &buf[20]);     // print date/time, nanoseconds and year
    158158                } // if
    159159                return os;
     
    161161
    162162        void ?|?( ostype & os, Time time ) with( time ) {
    163                 (ostype &)(os | time); nl( os );
     163                (ostype)(os | time); if ( getANL( os ) ) nl( os );
    164164        } // ?|?
    165165} // distribution
  • tests/concurrent/examples/quickSort.cfa

    r25cdca5 r84b4d607  
    99// Created On       : Wed Dec  6 12:15:52 2017
    1010// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Sat Dec 22 08:44:27 2018
    12 // Update Count     : 168
     11// Last Modified On : Tue Dec  4 18:00:27 2018
     12// Update Count     : 167
    1313//
    1414
     
    151151                                if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' ';
    152152                        } // for
    153                         sortedfile | nl | nl;
     153                        sortedfile | nl;
    154154
    155155                        delete( values );
  • tests/coroutine/fmtLines.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Sun Sep 17 21:56:15 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Dec 22 18:27:00 2018
    13 // Update Count     : 57
     12// Last Modified On : Wed Dec 12 22:45:36 2018
     13// Update Count     : 48
    1414//
    1515
     
    2424void main( Format & fmt ) with( fmt ) {
    2525        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
     26                for ( g; 5 ) {                                                                  // groups of 5 blocks
     27                        for ( b; 4 ) {                                                          // blocks of 4 characters
    2828                                for () {                                                                // for newline characters
    2929                                        suspend();
    30                                   if ( ch != '\n' ) break;                              // ignore newline
     30                                        if ( ch != '\n' ) break;                        // ignore newline
    3131                                } // for
    3232                                sout | ch;                                                              // print character
  • tests/fallthrough.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed Mar 14 10:06:25 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 11:24:35 2018
    13 // Update Count     : 22
     12// Last Modified On : Tue Dec  4 21:36:14 2018
     13// Update Count     : 17
    1414//
    1515
     
    1818void test(int choice) {
    1919        choose ( choice ) {
    20           case 1:
    21                 sout | "case 1";
    22                 fallthru;
    23           case 2:
    24                 sout | "case 2";
    25                 fallthru;
    26                 sout | "did not fallthru";
    27                 if ( 7 ) fallthru common2;
    28                 fallthru common1;
    29           case 3:
    30                 sout | "case 3";
    31                 fallthru default;
    32                 fallthru common1;
    33           common1:
    34                 sout | "common1";
     20                case 1:
     21                        sout | "case 1";
     22                        fallthru;
     23                case 2:
     24                        sout | "case 2";
     25                        fallthru;
     26                        sout | "did not fallthru";
     27                        if ( 7 ) fallthru common2;
     28                        fallthru common1;
     29                case 3:
     30                        sout | "case 3";
     31                        fallthru default;
     32                        fallthru common1;
     33                common1:
     34                        sout | "common1";
    3535                // break
    36           case 4:
    37                 sout | "case 4";
    38                 fallthru common2;
    39           case 5:
    40                 sout | "case 5";
    41                 fallthru common2;
    42                 fallthru default;
    43           case 6:
    44                 sout | "case 6";
    45                 fallthru common2;
    46           common2:
    47                 sout | "common2";
     36                case 4:
     37                        sout | "case 4";
     38                        fallthru common2;
     39                case 5:
     40                        sout | "case 5";
     41                        fallthru common2;
     42                        fallthru default;
     43                case 6:
     44                        sout | "case 6";
     45                        fallthru common2;
     46                common2:
     47                        sout | "common2";
    4848                // break
    49           default:
    50                 sout | "default";
    51                 fallthru;
    52         } // choose
     49                default:
     50                        sout | "default";
     51                        fallthru;
     52        }
    5353
    5454        sout | nl;
     
    6161                        sout | "case 1";
    6262                        for ( int i = 0; i < 4; i += 1 ) {
    63                                 sout | i;
     63                                printf("%d\n", i);
    6464                                if ( i == 2 ) fallthru common;
    6565                        } // for
     
    7777                } // if
    7878          common:
    79                 sout | "common";
     79                printf( "common\n" );
    8080                fallthru;
    8181                break;
    8282          default:
    83                 sout | "default";
     83                printf( "default\n" );
    8484                fallthru;
    8585        } // switch
     
    9393        fallthru default;
    9494        choose ( 3 ) {
    95           case 2:
    96                 for () {
    97                         choose ( 2 ) {
    98                           case 1:
    99                                 // ERROR: default is later, but in a different switch
    100                                 fallthru default;
    101                                 // ERROR: common3 is later, but not at the same level as a case clause
    102                                 fallthru common3;
     95                case 2:
     96                        for () {
     97                                choose ( 2 ) {
     98                                        case 1:
     99                                                // ERROR: default is later, but in a different switch
     100                                                fallthru default;
     101                                                // ERROR: common3 is later, but not at the same level as a case clause
     102                                                fallthru common3;
     103                                }
     104                                common3: ;
    103105                        }
    104                   common3: ;
    105                 } // for
    106           default:
    107           case 1:
    108           common4:
    109                 // ERROR: attempt to jump up with fallthrough
    110                 if ( 7 ) fallthru common4;
    111                 // ERROR: attempt to jump up with fallthrough
    112                 fallthru default;
    113         } // choose
     106                default:
     107                case 1:
     108                common4:
     109                        // ERROR: attempt to jump up with fallthrough
     110                        if ( 7 ) fallthru common4;
     111                        // ERROR: attempt to jump up with fallthrough
     112                        fallthru default;
     113        }
    114114#endif
    115115}
  • tests/fstream_test.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Dec 22 09:47:44 2018
    13 // Update Count     : 68
     12// Last Modified On : Tue Dec  4 21:36:34 2018
     13// Update Count     : 67
    1414//
    1515
     
    2424                 | (nombre > 0 ? "positif" : nombre == 0 ? "zéro" : "négatif");
    2525
    26         sout | "Entrez trois nombres, s'il vous plaît:";
     26        sout | "Entrez trois nombres, s'il vous plaît: ";
    2727        int i, j, k;
    2828        sin  | i | j | k;
  • tests/genericUnion.cfa

    r25cdca5 r84b4d607  
    1 //
    2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    3 //
    4 // The contents of this file are covered under the licence agreement in the
    5 // file "LICENCE" distributed with Cforall.
    6 //
    7 // genericUnion.cfa --
    8 //
    9 // Author           : Peter A. Buhr
    10 // Created On       : Tue Dec 25 14:42:46 2018
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 25 14:46:33 2018
    13 // Update Count     : 2
    14 //
    15 
    161#include <limits.hfa>
    172
     
    194union ByteView {
    205        T val;
    21         char bytes[(sizeof(int))];                                                      // want to change to sizeof(T)
     6        char bytes[(sizeof(int))]; // want to change to sizeof(T)
    227};
    238
    249forall(otype T)
    2510void print(ByteView(T) x) {
    26         for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T)
     11        for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T)
    2712                printf("%02x", x.bytes[i] & 0xff);
    2813        }
     
    4429        f(i, -1);
    4530}
    46 
    47 // Local Variables: //
    48 // tab-width: 4 //
    49 // compile-command: "cfa genericUnion.cfa" //
    50 // End: //
  • tests/gmp.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Tue Apr 19 08:55:51 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 20 22:41:47 2018
    13 // Update Count     : 559
     12// Last Modified On : Tue Dec  4 21:37:29 2018
     13// Update Count     : 558
    1414//
    1515
     
    7676        sout | "x:" | x | "y:" | y;
    7777
    78         sout | nl;
     78        sout;
    7979
    8080        sin | x | y | z;
    8181        sout | x | y | z;
    8282
    83         sout | nl;
     83        sout;
    8484
    8585        sout | "Fibonacci Numbers";
     
    9494        } // for
    9595
    96         sout | nl;
     96        sout;
    9797
    9898        sout | "Factorial Numbers";
  • tests/io1.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 21 16:02:55 2018
    13 // Update Count     : 114
     12// Last Modified On : Wed Dec 12 18:23:44 2018
     13// Update Count     : 110
    1414//
    1515
     
    2222        sout | '1' | '2' | '3';
    2323        sout | 1 | "" | 2 | "" | 3;
    24         sout | nl;
     24        sout;
    2525
    26         sout | nlOff;
    27         sout | "opening delimiters" | nl;
    28         sout | "x (" | 1;
    29         sout | "x [" | 2;
    30         sout | "x {" | 3;
    31         sout | "x =" | 4;
    32         sout | "x $" | 5;
    33         sout | "x £" | 6;
    34         sout | "x ¥" | 7;
    35         sout | "x ¡" | 8;
    36         sout | "x ¿" | 9;
     26        sout | "opening delimiters";
     27        sout | "x (" | 1 | nonl;
     28        sout | "x [" | 2 | nonl;
     29        sout | "x {" | 3 | nonl;
     30        sout | "x =" | 4 | nonl;
     31        sout | "x $" | 5 | nonl;
     32        sout | "x £" | 6 | nonl;
     33        sout | "x ¥" | 7 | nonl;
     34        sout | "x ¡" | 8 | nonl;
     35        sout | "x ¿" | 9 | nonl;
    3736        sout | "x «" | 10;
    38         sout | nl | nl;
    3937
    40         sout | "closing delimiters" | nl;
    41         sout | 1 | ", x";
    42         sout | 2 | ". x";
    43         sout | 3 | "; x";
    44         sout | 4 | "! x";
    45         sout | 5 | "? x";
    46         sout | 6 | "% x";
    47         sout | 7 | "¢ x";
    48         sout | 8 | "» x";
    49         sout | 9 | ") x";
    50         sout | 10 | "] x";
     38        sout | "closing delimiters";
     39        sout | 1 | ", x" | nonl;
     40        sout | 2 | ". x" | nonl;
     41        sout | 3 | "; x" | nonl;
     42        sout | 4 | "! x" | nonl;
     43        sout | 5 | "? x" | nonl;
     44        sout | 6 | "% x" | nonl;
     45        sout | 7 | "¢ x" | nonl;
     46        sout | 8 | "» x" | nonl;
     47        sout | 9 | ") x" | nonl;
     48        sout | 10 | "] x" | nonl;
    5149        sout | 11 | "} x";
    52         sout | nl | nl;
    5350
    54         sout | "opening/closing delimiters" | nl;
    55         sout | "x`" | 1 | "`x'" | 2;
    56         sout | "'x\"" | 3 | "\"x:" | 4;
    57         sout | ":x " | 5 | " x\t" | 6;
    58         sout | "\tx\f" | 7 | "\fx\v" | 8;
    59         sout | "\vx\n" | 9 | "\nx\r" | 10;
     51        sout | "opening/closing delimiters";
     52        sout | "x`" | 1 | "`x'" | 2 | nonl;
     53        sout | "'x\"" | 3 | "\"x:" | 4 | nonl;
     54        sout | ":x " | 5 | " x\t" | 6 | nonl;
     55        sout | "\tx\f" | 7 | "\fx\v" | 8 | nonl;
     56        sout | "\vx\n" | 9 | "\nx\r" | 10 | nonl;
    6057        sout | "\rx";
    61         sout | nl | nl;
    6258
    63         sout | nlOn;
    6459        sout | "override opening/closing delimiters";
    6560        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4;
    66         sout | nl;
     61        sout;
    6762}
    6863
  • tests/io2.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 21 08:20:14 2018
    13 // Update Count     : 112
     12// Last Modified On : Wed Dec 12 16:19:15 2018
     13// Update Count     : 110
    1414//
    1515
     
    9696        sout | sepOn | 1 | 2 | 3 | sepOn;                                       // no separator at start/end of line
    9797        sout | 1 | sepOff | 2 | 3;                                                      // locally turn off implicit separator
    98         sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n' | nonl; // no separator at start/end of line
    99         sout | 1 | 2 | 3 | "\n\n" | sepOn | nonl;                                       // no separator at start of next line
     98        sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
     99        sout | 1 | 2 | 3 | "\n\n" | sepOn;                                      // no separator at start of next line
    100100        sout | 1 | 2 | 3;
    101101        sout | nl;
     
    133133// Local Variables: //
    134134// tab-width: 4 //
    135 // compile-command: "cfa -DIN_DIR=".in/" io2.cfa" //
     135// compile-command: "cfa io2.cfa" //
    136136// End: //
  • tests/loopctrl.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed Aug  8 18:32:59 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 23 23:00:29 2018
    13 // Update Count     : 79
     12// Last Modified On : Wed Dec 12 08:14:44 2018
     13// Update Count     : 76
    1414//
    1515
     
    3232S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; }
    3333ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; }
    34 void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); }
     34void & ?|?( ofstream & os, S v ) { (ofstream)(os | v); if ( getANL( os ) ) nl( os ); }
    3535
    3636int main() {
     
    3838        while () { sout | "empty"; break; }                                     sout | nl;
    3939        do { sout | "empty"; break; } while ();                         sout | nl;
    40         for () { sout | "empty"; break; }                                       sout | nl | nl;
     40        for () { sout | "empty"; break; }                                       sout | nl;
    4141
    4242        for ( 0 ) { sout | "A"; }                                                       sout | "zero" | nl;
  • tests/polymorphism.cfa

    r25cdca5 r84b4d607  
    99// Author           : Rob Schluntz
    1010// Created On       : Tue Oct 17 12:19:48 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 25 14:40:24 2018
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Oct 17 12:21:07 2017
     13// Update Count     : 1
    1414//
    1515
    1616#include <assert.h>
    1717#include <inttypes.h>
    18 #include <fstream.hfa>
    1918
    2019forall(otype T)
     
    6261                int y = 456;
    6362                int z = f(x, y);
    64                 sout | x | y | z;
     63                printf("%d %d %d\n", x, y, z);
    6564        }
     65
    6666        {
    6767                // explicitly specialize function
    6868                int (*f)(int) = ident;
    6969                ((int(*)(int))ident);
    70                 sout | f(5) | ((int(*)(int))ident)(5);
     70                printf("%d %d\n", f(5), ((int(*)(int))ident)(5));
    7171        }
     72
    7273        {
    7374                // test aggregates with polymorphic members
     
    99100
    100101                void print(x_type x) {
    101                         sout | x;
     102                        printf("%"PRIu32"\n", x);
    102103                }
    103104
    104105                void print(y_type y) {
    105                         sout | y;
     106                        printf("%"PRIu64"\n", y);
    106107                }
    107108
  • tests/pybin/tools.py

    r25cdca5 r84b4d607  
    7979def diff( lhs, rhs ):
    8080        # diff the output of the files
    81         diff_cmd = ("diff --text "
    82 #                               "--ignore-all-space "
    83 #                               "--ignore-blank-lines "
     81        diff_cmd = ("diff --ignore-all-space --text "
     82                                "--ignore-blank-lines "
    8483                                "--old-group-format='\t\tmissing lines :\n"
    8584                                "%%<' \\\n"
  • tests/raii/dtor-early-exit.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed Aug 17 08:26:25 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 21 08:45:19 2018
    13 // Update Count     : 10
     12// Last Modified On : Tue Dec 11 22:05:24 2018
     13// Update Count     : 9
    1414//
    1515
     
    7171                }
    7272        }
    73         sout | nl;
     73        sout;
    7474        for (int i = 0; i < 10; i++) {
    7575                switch(10) {
  • tests/references.cfa

    r25cdca5 r84b4d607  
    99// Author           : Rob Schluntz
    1010// Created On       : Wed Aug 23 16:11:50 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 25 14:31:48 2018
    13 // Update Count     : 11
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 23 16:12:03
     13// Update Count     : 2
    1414//
    1515
    16 #include <fstream.hfa>
    17 
    1816struct Y { int i; };
    19 void ?{}( Y & y ) { sout | "Default constructing a Y"; }
    20 void ?{}( Y & y, Y other ) { sout | "Copy constructing a Y"; }
    21 void ^?{}( Y & y ) { sout | "Destructing a Y"; }
    22 Y ?=?( Y & y, Y other ) { sout | "Assigning a Y"; return y; }
    23 void ?{}( Y & y, int i ) { sout | "Value constructing a Y" | i; y.i = i; }
     17void ?{}(Y & y) { printf("Default constructing a Y\n"); }
     18void ?{}(Y & y, Y other) { printf("Copy constructing a Y\n"); }
     19void ^?{}(Y & y) { printf("Destructing a Y\n"); }
     20Y ?=?(Y & y, Y other) { printf("Assigning a Y\n"); return y; }
     21void ?{}(Y & y, int i) { printf("Value constructing a Y %d\n", i); y.i = i; }
    2422
    2523struct X { Y & r; Y y; };
    26 void ?{}( X & x ) {
     24void ?{}(X & x) {
    2725        // ensure that r is not implicitly constructed
    2826}
    29 void ?{}( X & x, X other ) {
     27void ?{}(X & x, X other) {
    3028        // ensure that r is not implicitly constructed
    3129}
    32 void ^?{}( X & x ) {
     30void ^?{}(X & x) {
    3331        // ensure that r is not implicitly destructed
    3432}
    35 X ?=?( X & x, X other ) { return x; }
     33X ?=?(X & x, X other) { return x; }
    3634
    3735// ensure that generated functions do not implicitly operate on references
     
    5048        int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    5149                &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    52         ***p3 = 3;                                                                                      // change x
    53         **p3 = &x;                                                                                      // change p1
    54         *p3 = &p1;                                                                                      // change p2
    55         int y = 0, z = 11, & ar[3] = { x, y, z };                       // initialize array of references
    56                                                                                                                 // &ar[1] = &z;                        // change reference array element
    57                                                                                                                 // typeof( ar[1] ) p = 3;              // is int, i.e., the type of referenced object
    58                                                                                                                 // typeof( &ar[1] ) q = &x;            // is int *, i.e., the type of pointer
     50        ***p3 = 3;                          // change x
     51        **p3 = &x;                          // change p1
     52        *p3 = &p1;                          // change p2
     53        int y = 0, z = 11, & ar[3] = { x, y, z };    // initialize array of references
     54        // &ar[1] = &z;                        // change reference array element
     55        // typeof( ar[1] ) p = 3;              // is int, i.e., the type of referenced object
     56        // typeof( &ar[1] ) q = &x;            // is int *, i.e., the type of pointer
    5957        // _Static_assert( sizeof( ar[1] ) == sizeof( int ), "Array type should be int." );   // is true, i.e., the size of referenced object
    6058        // _Static_assert( sizeof( &ar[1] ) == sizeof( int *), "Address of array should be int *." ); // is true, i.e., the size of a reference
    6159
    62         ((int*&)&r3) = &x;                                                                      // change r1, (&*)**r3
     60        ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    6361        x = 3;
    6462        // test that basic reference properties are true - r1 should be an alias for x
    65         sout | x | r1 | &x == &r1;
     63        printf("%d %d %d\n", x, r1, &x == &r1);
    6664        r1 = 12;
    67         sout | x | r1 | &x == &r1;
     65        printf("%d %d %d\n", x, r1, &x == &r1);
    6866
    6967        // test that functions using basic references work
    70         sout | toref( &x ) | toref( p1 ) | toptr( r1 ) == toptr( x ) | toptr( r1 ) == &x;
     68        printf("%d %d %d %d\n", toref(&x), toref(p1), toptr(r1) == toptr(x), toptr(r1) == &x);
    7169
    7270        changeRef( x );
    7371        changeRef( y );
    7472        changeRef( z );
    75         sout | x | y | z;
     73        printf("%d %d %d\n", x, y, z);
    7674        changeRef( r1 );
    77         sout | r1 | x;
     75        printf("%d %d\n", r1, x);
    7876
    79         r3 = 6;                                                                                         // change x, ***r3
    80         sout | "x = " | x | " ; x2 = " | x2;                            // check that x was changed
    81         &r3 = &x2;                                                                                      // change r1 to refer to x2, (&*)**r3
    82         r3 = 999;                                                                                       // modify x2
    83         sout | "x = " | x | " ; x2 = " | x2;                            // check that x2 was changed
    84         ((int**&)&&r3) = p2;                                                            // change r2, (&(&*)*)*r3, ensure explicit cast to reference works
    85         r3 = 12345;                                                                                     // modify x
    86         sout | "x = " | x | " ; x2 = " | x2;                            // check that x was changed
    87         &&&r3 = p3;                                                                                     // change r3 to p3, (&(&(&*)*)*)r3
    88         ((int&)r3) = 22222;                                                                     // modify x, ensure explicit cast to reference works
    89         sout | "x = " | x | " ; x2 = " | x2;                                    // check that x was changed
     77        r3 = 6;                               // change x, ***r3
     78        printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
     79        &r3 = &x2;                            // change r1 to refer to x2, (&*)**r3
     80        r3 = 999;                             // modify x2
     81        printf("x = %d ; x2 = %d\n", x, x2);  // check that x2 was changed
     82        ((int**&)&&r3) = p2;                  // change r2, (&(&*)*)*r3, ensure explicit cast to reference works
     83        r3 = 12345;                           // modify x
     84        printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
     85        &&&r3 = p3;                           // change r3 to p3, (&(&(&*)*)*)r3
     86        ((int&)r3) = 22222;                   // modify x, ensure explicit cast to reference works
     87        printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    9088
    9189        // test that reference members are not implicitly constructed/destructed/assigned
     
    104102                struct S { double x, y; };
    105103                void f( int & i, int & j, S & s, int v[] ) {
    106                         sout | i | j | "{ " | s.[x, y] | " }," | "[" | v[0] | "," | v[1] | "," | v[2] | "]";
     104                        printf("%d %d { %g, %g }, [%d, %d, %d]\n", i, j, s.[x, y], v[0], v[1], v[2]);
    107105                }
    108                 void g(int & i) { sout | i; }
    109                 void h(int &&& i) { sout | i; }
     106                void g(int & i) { printf("%d\n", i); }
     107                void h(int &&& i) { printf("%d\n", i); }
    110108
    111                 int &&& r = 3;                                                                  // rvalue to reference
     109                int &&& r = 3;  // rvalue to reference
    112110                int i = r;
    113                 sout | i | r;                                                                   // both 3
     111                printf("%d %d\n", i, r);  // both 3
    114112
    115                 g( 3 );                                                                                 // rvalue to reference
    116                 h( (int &&&)3 );                                                                // rvalue to reference
     113                g( 3 );          // rvalue to reference
     114                h( (int &&&)3 ); // rvalue to reference
    117115
    118116                int a = 5, b = 4;
  • tests/searchsort.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Thu Feb  4 18:17:50 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 20 22:49:46 2018
    13 // Update Count     : 108
     12// Last Modified On : Wed Dec  5 08:18:42 2018
     13// Update Count     : 106
    1414//
    1515
     
    2121
    2222int main( void ) {
    23         const int size = 10;
     23        const unsigned int size = 10;
    2424        int iarr[size];
    2525
    2626        sout | nlOff;                                                                           // turn off auto newline
    2727
    28         for ( i; 0 ~ size ) {
     28        for ( i; 0u ~ size ) {
    2929                iarr[i] = size - i;
    3030                sout | iarr[i] | ", ";
    3131        } // for
    32         sout | nl | nl;
     32        sout | nl;
    3333
    3434        // ascending sort/search by changing < to >
    3535        qsort( iarr, size );
    36         for ( i; 0 ~ size ) {
     36        for ( i; 0u ~ size ) {
    3737                sout | iarr[i] | ", ";
    3838        } // for
    3939        sout | nl;
    40         for ( i; 0 ~ size ) {           // C version
     40        for ( i; 0u ~ size ) {          // C version
    4141                int key = size - i;
    4242                int * v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp );
     
    4545        sout | nl;
    4646
    47         for ( i; 0 ~ size ) {
     47        for ( i; 0u ~ size ) {
    4848                int * v = bsearch( size - i, iarr, size );
    4949                sout | size - i | ':' | *v | ", ";
    5050        } // for
    5151        sout | nl;
    52         for ( i; 0 ~ size ) {
     52        for ( i; 0u ~ size ) {
    5353                unsigned int posn = bsearch( size - i, iarr, size );
    5454                sout | size - i | ':' | iarr[posn] | ", ";
    5555        } // for
    56         sout | nl | nl;
     56        sout | nl;
    5757
    5858        // descending sort/search by changing < to >
     
    6363        sout | nl;
    6464        {
    65                 // redefinition of ?<? can't overlap the loop controls:
    66                 {
    67                         int (*?<?)(int, int) = ?>?;
    68                         qsort( iarr, size );
    69                 }
    70                 for ( i; 0 ~ size ) {
     65                int ?<?( int x, int y ) { return x > y; }
     66                qsort( iarr, size );
     67                for ( i; 0u ~ size ) {
    7168                        sout | iarr[i] | ", ";
    7269                } // for
    7370                sout | nl;
    74                 for ( i; 0 ~ size ) {
    75                         int (*?<?)(int, int) = ?>?;
     71                for ( i; 0u ~ size ) {
    7672                        int * v = bsearch( size - i, iarr, size );
    7773                        sout | size - i | ':' | *v | ", ";
    7874                } // for
    7975                sout | nl;
    80                 for ( i; 0 ~ size ) {
    81                         int (*?<?)(int, int) = ?>?;
     76                for ( i; 0u ~ size ) {
    8277                        unsigned int posn = bsearch( size - i, iarr, size );
    8378                        sout | size - i | ':' | iarr[posn] | ", ";
    8479                } // for
    8580        }
    86         sout | nl | nl;
     81        sout | nl;
    8782
    8883        double darr[size];
    89         for ( i; 0 ~ size ) {
     84        for ( i; 0u ~ size ) {
    9085                darr[i] = size - i + 0.5;
    9186                sout | darr[i] | ", ";
     
    9388        sout | nl;
    9489        qsort( darr, size );
    95         for ( i; 0 ~ size ) {
     90        for ( i; 0u ~ size ) {
    9691                sout | darr[i] | ", ";
    9792        } // for
    9893        sout | nl;
    99         for ( i; 0 ~ size ) {
     94        for ( i; 0u ~ size ) {
    10095                double * v = bsearch( size - i + 0.5, darr, size );
    10196                sout | size - i + 0.5 | ':' | *v | ", ";
    10297        } // for
    10398        sout | nl;
    104         for ( i; 0 ~ size ) {
     99        for ( i; 0u ~ size ) {
    105100                unsigned int posn = bsearch( size - i + 0.5, darr, size );
    106101                sout | size - i + 0.5 | ':' | darr[posn] | ", ";
    107102        } // for
    108         sout | nl | nl;
     103        sout | nl;
    109104
    110105        struct S { int i, j; } sarr[size];
    111106        int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; }
    112107        ofstream & ?|?( ofstream & os, S v ) { return os | v.i | ' ' | v.j; }
    113         for ( i; 0 ~ size ) {
     108        for ( i; 0u ~ size ) {
    114109                sarr[i].i = size - i;
    115110                sarr[i].j = size - i + 1;
     
    118113        sout | nl;
    119114        qsort( sarr, size );
    120         for ( i; 0 ~ size ) {
     115        for ( i; 0u ~ size ) {
    121116                sout | sarr[i] | ", ";
    122117        } // for
    123118        sout | nl;
    124         for ( i; 0 ~ size ) {
     119        for ( i; 0u ~ size ) {
    125120                S temp = { size - i, size - i + 1 };
    126121                S * v = bsearch( temp, sarr, size );
     
    128123        } // for
    129124        sout | nl;
    130         for ( i; 0 ~ size ) {
     125        for ( i; 0u ~ size ) {
    131126                S temp = { size - i, size - i + 1 };
    132127                unsigned int posn = bsearch( temp, sarr, size );
    133128                sout | temp | ':' | sarr[posn] | ", ";
    134129        } // for
    135         sout | nl | nl;
     130        sout | nl;
    136131        {
    137                 int getKey( const S & s ) { return s.j; }
    138                 for ( i; 0 ~ size ) {
     132                unsigned int getKey( const S & s ) { return s.j; }
     133                for ( i; 0u ~ size ) {
    139134                        sout | sarr[i] | ", ";
    140135                } // for
    141136                sout | nl;
    142                 for ( i; 0 ~ size ) {
     137                for ( i; 0u ~ size ) {
    143138                        S * v = bsearch( size - i + 1, sarr, size );
    144139                        sout | size - i + 1 | ':' | *v | ", ";
    145140                } // for
    146141                sout | nl;
    147                 for ( i; 0 ~ size ) {
     142                for ( i; 0u ~ size ) {
    148143                        unsigned int posn = bsearch( size - i + 1, sarr, size );
    149144                        sout | size - i + 1 | ':' | sarr[posn] | ", ";
    150145                } // for
    151                 sout | nl | nl;
     146                sout | nl;
    152147        }
    153148} // main
  • tests/sum.cfa

    r25cdca5 r84b4d607  
    1111// Created On       : Wed May 27 17:56:53 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sun Dec 23 23:00:38 2018
    14 // Update Count     : 287
     13// Last Modified On : Tue Dec 11 21:50:41 2018
     14// Update Count     : 285
    1515//
    1616
     
    9393        S ?++( S & t ) { S temp = t; t += (S){1}; return temp; }
    9494        ofstream & ?|?( ofstream & os, S v ) { return os | v.i | v.j; }
    95         void ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); }
     95        void ?|?( ofstream & os, S v ) { (ofstream)(os | v); if ( getANL( os ) ) nl( os ); }
    9696
    9797        S s = (S){0}, a[size], v = { low, low };
  • tests/swap.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 23 23:00:49 2018
    13 // Update Count     : 77
     12// Last Modified On : Tue Dec 11 10:17:40 2018
     13// Update Count     : 74
    1414//
    1515
     
    8585        struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 };
    8686        ofstream & ?|?( ofstream & os, S s ) { return os | s.i | s.j; }
    87         void ?|?( ofstream & os, S s ) { (ofstream &)(os | s.i | s.j); nl( os ); }
    8887        sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap " | nonl;
    8988        swap( s1, s2 );
  • tests/time.cfa

    r25cdca5 r84b4d607  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 20 23:09:21 2018
    13 // Update Count     : 23
     12// Last Modified On : Tue Dec 11 21:44:03 2018
     13// Update Count     : 22
    1414//
    1515
     
    3030        sout | d1 == 7`s | d1 == d2 | d1 == 0;
    3131        sout | div( 7`s, 2`s );
    32         sout | nl;
    3332
    3433        Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 };
     
    4746        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
    4847        sout | t2 | t2.tv | nl | t3 | t3.tv;
    49         sout | nl;
    5048
    5149        // Clock Newfoundland = { -3.5`h }, PST = { -8`h };     // distance from GMT (UTC)
     
    5553        //       | "local nsec" | getTimeNsec()
    5654        //       | "PST" | PST();                                                               // getTime short form
    57         // sout | nl;
     55        // sout;
    5856
    5957        // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
  • tests/withStatement.cfa

    r25cdca5 r84b4d607  
    99// Author           : Rob Schluntz
    1010// Created On       : Mon Dec 04 17:41:45 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 19:08:18 2018
    13 // Update Count     : 5
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Mon Dec 04 17:45:07 2017
     13// Update Count     : 2
    1414//
    1515
    16 #include <fstream.hfa>
    17 
    1816struct S {
    19         int i;
    20         // dynamically allocated member ensures ctor/dtors are called correctly on temporaries
    21         int * ptr;
     17  int i;
     18  // dynamically allocated member ensures ctor/dtors are called correctly on temporaries
     19  int * ptr;
    2220};
    2321
    2422// with clause on reference parameter
    25 void ?{}( S & this, int n ) with( this ) {
    26         i = n;
    27         ptr = (int *)malloc( sizeof(int) );
     23void ?{}(S & this, int n) with(this) {
     24  i = n;
     25  ptr = (int *)malloc(sizeof(int));
    2826}
    2927
    30 void ?{}( S & this ) {
    31         this{ 0 };
     28void ?{}(S & this) {
     29  this{ 0 };
    3230}
    3331
    34 void ?{}( S & this, S other ) {
    35         this{ other.i };
     32void ?{}(S & this, S other) {
     33  this{ other.i };
    3634}
    3735
    38 S ?=?( S & this, S other ) with( this ) {
    39         i = other.i;
    40         *ptr = *other.ptr;
    41         return this;
     36S ?=?(S & this, S other) with(this) {
     37  i = other.i;
     38  *ptr = *other.ptr;
     39  return this;
    4240}
    4341
    44 void ^?{}( S & this ) with( this ) {
    45         free( ptr );
     42void ^?{}(S & this) with(this) {
     43  free(ptr);
    4644}
    4745
    4846struct S2 {
    49         S s;
     47  S s;
    5048};
    5149
    52 void ?{}( S2 & this, int n ) {
    53         (this.s){ n };
     50void ?{}(S2 & this, int n) {
     51  (this.s){ n };
    5452}
    5553
    56 forall( otype T )
     54forall(otype T)
    5755struct Box {
    58         T x;
     56  T x;
    5957};
    6058
    61 forall( otype T )
    62 void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function
    63         x{};
     59forall(otype T)
     60void ?{}(Box(T) & this) with(this) { // with clause in polymorphic function
     61  x{};
    6462}
    6563
    66 void print( int i ) { sout | i; }
     64void print(int i) { printf("%d", i); }
    6765
    68 forall( otype T | { void print( T ); })
    69 void foo( T t ) {
    70         Box( T ) b = { t };
    71         with( b ) {  // with statement in polymorphic function
    72                 print( x );
    73         }
     66forall(otype T | { void print(T); })
     67void foo(T t) {
     68  Box(T) b = { t };
     69  with(b) {  // with statement in polymorphic function
     70    print(x);
     71    printf("\n");
     72  }
    7473}
    7574
    7675// ensure with-statement temporary generation works correctly
    7776S mk() {
    78         sout | "called mk";
    79         return (S){ 444 };
     77  printf("called mk\n");
     78  return (S) { 444 };
    8079}
    8180
    8281// ensure with-statement temporary generation with reference-returning functions works correctly
    8382S & ref() {
    84         static S var = { 123456789 };
    85         return var;
     83  static S var = { 123456789 };
     84  return var;
    8685}
    8786
    8887int main() {
    89         S2 s2 = { 12345 };
    90         with ( s2) {
    91                 with( s ) { // with s2.s
    92                         sout | i | s.i | s2.s.i;
    93                         foo( i );  // s.i
    94                         with( mk()) {
    95                                 sout | i | i | i;
    96                                 with( ref()) {
    97                                         sout | i | i | i;
    98                                 } // with ref()
    99                                 with( ref()) {
    100                                         sout | i | i | i;
    101                                 } // with ref()
    102                         } // with mk()
    103                 } // with s
    104         } // with s2
     88  S2 s2 = { 12345 };
     89  with (s2) {
     90    with(s) { // with s2.s
     91      printf("%d %d %d\n", i, s.i, s2.s.i);
     92      foo(i);  // s.i
     93      with(mk()) {
     94        printf("%d %d %d\n", i, i, i);
     95        with(ref()) {
     96          printf("%d %d %d\n", i, i, i);
     97        } // with ref()
     98        with(ref()) {
     99          printf("%d %d %d\n", i, i, i);
     100        } // with ref()
     101      } // with mk()
     102    } // with s
     103  } // with s2
    105104}
    106105
Note: See TracChangeset for help on using the changeset viewer.