Changeset 25cdca5
- Timestamp:
- Jan 8, 2019, 11:31:21 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 08222c7, 274da98
- Parents:
- 84b4d607 (diff), d5b2ac8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 21 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 08:34:28 201813 // Update Count : 29812 // Last Modified On : Mon Dec 24 18:33:38 2018 13 // Update Count : 304 14 14 // 15 15 … … 26 26 #define IO_MSG "I/O error: " 27 27 28 void ?{}( ofstream & os, void * file, bool sepDefault, bool sepOnOff, bool nlOnOff, bool nonlManip, const char * separator, const char * tupleSeparator ) {28 void ?{}( ofstream & os, void * file, bool sepDefault, bool sepOnOff, bool nlOnOff, bool prt, const char * separator, const char * tupleSeparator ) { 29 29 os.file = file; 30 30 os.sepDefault = sepDefault; 31 31 os.sepOnOff = sepOnOff; 32 32 os.nlOnOff = nlOnOff; 33 os. nonlManip = nonlManip;33 os.prt = prt; 34 34 sepSet( os, separator ); 35 35 sepSetCur( os, sepGet( os ) ); … … 46 46 void setNL( ofstream & os, bool state ) { os.sawNL = state; } 47 47 bool getANL( ofstream & os ) { return os.nlOnOff; } 48 bool get Nonl( ofstream & os ) { return os.nonlManip; }49 void set Nonl( ofstream & os, bool state ) { os.nonlManip= state; }48 bool getPrt( ofstream & os ) { return os.prt; } 49 void setPrt( ofstream & os, bool state ) { os.prt = state; } 50 50 51 51 // public … … 150 150 va_end( args ); 151 151 152 setPrt( os, true ); // called in output cascade 152 153 sepReset( os ); // reset separator 153 154 return len; -
libcfa/src/fstream.hfa
r84b4d607 r25cdca5 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 07:52:41 201813 // Update Count : 14 312 // Last Modified On : Mon Dec 24 18:33:41 2018 13 // Update Count : 149 14 14 // 15 15 … … 24 24 bool sepOnOff; 25 25 bool nlOnOff; 26 bool nonlManip;26 bool prt; // print text 27 27 bool sawNL; 28 28 const char * sepCur; … … 40 40 void setNL( ofstream &, bool ); 41 41 bool getANL( ofstream & ); 42 bool get Nonl( ofstream & );43 void set Nonl( ofstream &, bool );42 bool getPrt( ofstream & ); 43 void setPrt( ofstream &, bool ); 44 44 45 45 // public … … 62 62 void close( ofstream & ); 63 63 ofstream & write( ofstream &, const char * data, size_t size ); 64 int fmt( ofstream &, const char f mt[], ... );64 int fmt( ofstream &, const char format[], ... ); 65 65 66 66 void ?{}( ofstream & os ); … … 83 83 ifstream & read( ifstream & is, char * data, size_t size ); 84 84 ifstream & ungetc( ifstream & is, char c ); 85 int fmt( ifstream &, const char f mt[], ... );85 int fmt( ifstream &, const char format[], ... ); 86 86 87 87 void ?{}( ifstream & is ); -
libcfa/src/iostream.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 13 14:13:22201813 // Update Count : 5 4812 // Last Modified On : Mon Dec 24 18:33:40 2018 13 // Update Count : 589 14 14 // 15 15 … … 33 33 } // ?|? 34 34 void ?|?( ostype & os, bool b ) { 35 (ostype )(os | b); if ( getANL( os ) )nl( os );35 (ostype &)(os | b); nl( os ); 36 36 } // ?|? 37 37 … … 42 42 } // ?|? 43 43 void ?|?( ostype & os, char c ) { 44 (ostype )(os | c); if ( getANL( os ) )nl( os );44 (ostype &)(os | c); nl( os ); 45 45 } // ?|? 46 46 … … 51 51 } // ?|? 52 52 void ?|?( ostype & os, signed char sc ) { 53 (ostype )(os | sc); if ( getANL( os ) )nl( os );53 (ostype &)(os | sc); nl( os ); 54 54 } // ?|? 55 55 … … 60 60 } // ?|? 61 61 void ?|?( ostype & os, unsigned char usc ) { 62 (ostype )(os | usc); if ( getANL( os ) )nl( os );62 (ostype &)(os | usc); nl( os ); 63 63 } // ?|? 64 64 … … 69 69 } // ?|? 70 70 void & ?|?( ostype & os, short int si ) { 71 (ostype )(os | si); if ( getANL( os ) )nl( os );71 (ostype &)(os | si); nl( os ); 72 72 } // ?|? 73 73 … … 78 78 } // ?|? 79 79 void & ?|?( ostype & os, unsigned short int usi ) { 80 (ostype )(os | usi); if ( getANL( os ) )nl( os );80 (ostype &)(os | usi); nl( os ); 81 81 } // ?|? 82 82 … … 87 87 } // ?|? 88 88 void & ?|?( ostype & os, int i ) { 89 (ostype )(os | i); if ( getANL( os ) )nl( os );89 (ostype &)(os | i); nl( os ); 90 90 } // ?|? 91 91 … … 96 96 } // ?|? 97 97 void & ?|?( ostype & os, unsigned int ui ) { 98 (ostype )(os | ui); if ( getANL( os ) )nl( os );98 (ostype &)(os | ui); nl( os ); 99 99 } // ?|? 100 100 … … 105 105 } // ?|? 106 106 void & ?|?( ostype & os, long int li ) { 107 (ostype )(os | li); if ( getANL( os ) )nl( os );107 (ostype &)(os | li); nl( os ); 108 108 } // ?|? 109 109 … … 114 114 } // ?|? 115 115 void & ?|?( ostype & os, unsigned long int uli ) { 116 (ostype )(os | uli); if ( getANL( os ) )nl( os );116 (ostype &)(os | uli); nl( os ); 117 117 } // ?|? 118 118 … … 123 123 } // ?|? 124 124 void & ?|?( ostype & os, long long int lli ) { 125 (ostype )(os | lli); if ( getANL( os ) )nl( os );125 (ostype &)(os | lli); nl( os ); 126 126 } // ?|? 127 127 … … 132 132 } // ?|? 133 133 void & ?|?( ostype & os, unsigned long long int ulli ) { 134 (ostype )(os | ulli); if ( getANL( os ) )nl( os );134 (ostype &)(os | ulli); nl( os ); 135 135 } // ?|? 136 136 … … 141 141 } // ?|? 142 142 void & ?|?( ostype & os, float f ) { 143 (ostype )(os | f); if ( getANL( os ) )nl( os );143 (ostype &)(os | f); nl( os ); 144 144 } // ?|? 145 145 … … 150 150 } // ?|? 151 151 void & ?|?( ostype & os, double d ) { 152 (ostype )(os | d); if ( getANL( os ) )nl( os );152 (ostype &)(os | d); nl( os ); 153 153 } // ?|? 154 154 … … 159 159 } // ?|? 160 160 void & ?|?( ostype & os, long double ld ) { 161 (ostype )(os | ld); if ( getANL( os ) )nl( os );161 (ostype &)(os | ld); nl( os ); 162 162 } // ?|? 163 163 … … 168 168 } // ?|? 169 169 void & ?|?( ostype & os, float _Complex fc ) { 170 (ostype )(os | fc); if ( getANL( os ) )nl( os );170 (ostype &)(os | fc); nl( os ); 171 171 } // ?|? 172 172 … … 177 177 } // ?|? 178 178 void & ?|?( ostype & os, double _Complex dc ) { 179 (ostype )(os | dc); if ( getANL( os ) )nl( os );179 (ostype &)(os | dc); nl( os ); 180 180 } // ?|? 181 181 … … 186 186 } // ?|? 187 187 void & ?|?( ostype & os, long double _Complex ldc ) { 188 (ostype )(os | ldc); if ( getANL( os ) )nl( os );188 (ostype &)(os | ldc); nl( os ); 189 189 } // ?|? 190 190 … … 228 228 } // ?|? 229 229 void ?|?( ostype & os, const char * str ) { 230 (ostype )(os | str); if ( getANL( os ) )nl( os );230 (ostype &)(os | str); nl( os ); 231 231 } // ?|? 232 232 … … 257 257 } // ?|? 258 258 void ?|?( ostype & os, const void * p ) { 259 (ostype )(os | p); if ( getANL( os ) )nl( os );259 (ostype &)(os | p); nl( os ); 260 260 } // ?|? 261 261 262 262 // manipulators 263 263 ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 264 (ostype)(manip( os )); 265 setNonl( os, false ); // ignore nonl in middle 264 (ostype &)(manip( os )); 266 265 return os; 267 266 } // ?|? 268 267 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 269 (ostype )(manip( os ));270 if ( get ANL( os ) && ! getNonl( os ) ) nl( os ); // ignore nl if nonl at end271 set Nonl( os, false );268 (ostype &)(manip( os )); 269 if ( getPrt( os ) ) nl( os ); // something printed ? 270 setPrt( os, false ); // turn off 272 271 } // ?|? 273 272 274 273 ostype & sep( ostype & os ) { 275 return (ostype )(os | sepGet( os ));274 return (ostype &)(os | sepGet( os )); 276 275 } // sep 277 276 … … 281 280 282 281 ostype & nl( ostype & os ) { 283 (ostype)(os | '\n'); 282 (ostype &)(os | '\n'); 283 setPrt( os, false ); // turn off 284 284 setNL( os, true ); 285 285 flush( os ); … … 287 287 } // nl 288 288 289 void nl( ostype & os ) { 290 if ( getANL( os ) ) (ostype &)(nl( os )); // implementation only 291 else setPrt( os, false ); // turn off 292 } // nl 293 289 294 ostype & nonl( ostype & os ) { 290 set Nonl( os, true ); // indicate nonl manipulator295 setPrt( os, false ); // turn off 291 296 return os; 292 297 } // nonl … … 326 331 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 327 332 ostype & ?|?( ostype & os, T arg, Params rest ) { 328 (ostype )(os | arg);// print first argument333 (ostype &)(os | arg); // print first argument 329 334 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 330 (ostype )(os | rest); // print remaining arguments335 (ostype &)(os | rest); // print remaining arguments 331 336 sepSetCur( os, sepGet( os ) ); // switch to regular separator 332 337 return os; 333 338 } // ?|? 334 339 void ?|?( ostype & os, T arg, Params rest ) { 335 // (ostype)(?|?( os, arg, rest )); if ( getANL( os ) )nl( os );336 (ostype )(os | arg);// print first argument340 // (ostype &)(?|?( os, arg, rest )); nl( os ); 341 (ostype &)(os | arg); // print first argument 337 342 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 338 (ostype )(os | rest); // print remaining arguments343 (ostype &)(os | rest); // print remaining arguments 339 344 sepSetCur( os, sepGet( os ) ); // switch to regular separator 340 if ( getANL( os ) )nl( os );345 nl( os ); 341 346 } // ?|? 342 347 } // distribution -
libcfa/src/iostream.hfa
r84b4d607 r25cdca5 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:01:31201813 // Update Count : 2 1312 // Last Modified On : Mon Dec 24 18:33:40 2018 13 // Update Count : 220 14 14 // 15 15 … … 20 20 trait ostream( dtype ostype ) { 21 21 // private 22 bool sepPrt( ostype & ); // returnseparator state (on/off)22 bool sepPrt( ostype & ); // get separator state (on/off) 23 23 void sepReset( ostype & ); // set separator state to default state 24 24 void sepReset( ostype &, bool ); // set separator and default state … … 27 27 bool getNL( ostype & ); // check newline 28 28 void setNL( ostype &, bool ); // saw newline 29 bool getANL( ostype & ); // check auto newline30 bool get Nonl( ostype & ); // check nonnl manipulator31 void set Nonl( ostype &, bool ); // set nonnl manipulator29 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 32 32 // public 33 33 void sepOn( ostype & ); // turn separator state on … … 48 48 void close( ostype & os ); 49 49 ostype & write( ostype &, const char *, size_t ); 50 int fmt( ostype &, const char f mt[], ... );50 int fmt( ostype &, const char format[], ... ); 51 51 }; // ostream 52 52 … … 63 63 forall( dtype ostype | ostream( ostype ) ) { 64 64 ostype & ?|?( ostype &, bool ); 65 void &?|?( ostype &, bool );65 void ?|?( ostype &, bool ); 66 66 67 67 ostype & ?|?( ostype &, char ); 68 void &?|?( ostype &, char );68 void ?|?( ostype &, char ); 69 69 ostype & ?|?( ostype &, signed char ); 70 void &?|?( ostype &, signed char );70 void ?|?( ostype &, signed char ); 71 71 ostype & ?|?( ostype &, unsigned char ); 72 void &?|?( ostype &, unsigned char );72 void ?|?( ostype &, unsigned char ); 73 73 74 74 ostype & ?|?( ostype &, short int ); 75 void &?|?( ostype &, short int );75 void ?|?( ostype &, short int ); 76 76 ostype & ?|?( ostype &, unsigned short int ); 77 void &?|?( ostype &, unsigned short int );77 void ?|?( ostype &, unsigned short int ); 78 78 ostype & ?|?( ostype &, int ); 79 void &?|?( ostype &, int );79 void ?|?( ostype &, int ); 80 80 ostype & ?|?( ostype &, unsigned int ); 81 void &?|?( ostype &, unsigned int );81 void ?|?( ostype &, unsigned int ); 82 82 ostype & ?|?( ostype &, long int ); 83 void &?|?( ostype &, long int );83 void ?|?( ostype &, long int ); 84 84 ostype & ?|?( ostype &, long long int ); 85 void &?|?( ostype &, long long int );85 void ?|?( ostype &, long long int ); 86 86 ostype & ?|?( ostype &, unsigned long int ); 87 void &?|?( ostype &, unsigned long int );87 void ?|?( ostype &, unsigned long int ); 88 88 ostype & ?|?( ostype &, unsigned long long int ); 89 void &?|?( ostype &, unsigned long long int );89 void ?|?( ostype &, unsigned long long int ); 90 90 91 91 ostype & ?|?( ostype &, float ); // FIX ME: should not be required 92 void &?|?( ostype &, float ); // FIX ME: should not be required92 void ?|?( ostype &, float ); // FIX ME: should not be required 93 93 ostype & ?|?( ostype &, double ); 94 void &?|?( ostype &, double );94 void ?|?( ostype &, double ); 95 95 ostype & ?|?( ostype &, long double ); 96 void &?|?( ostype &, long double );96 void ?|?( ostype &, long double ); 97 97 98 98 ostype & ?|?( ostype &, float _Complex ); 99 void &?|?( ostype &, float _Complex );99 void ?|?( ostype &, float _Complex ); 100 100 ostype & ?|?( ostype &, double _Complex ); 101 void &?|?( ostype &, double _Complex );101 void ?|?( ostype &, double _Complex ); 102 102 ostype & ?|?( ostype &, long double _Complex ); 103 void &?|?( ostype &, long double _Complex );103 void ?|?( ostype &, long double _Complex ); 104 104 105 105 ostype & ?|?( ostype &, const char * ); 106 void &?|?( ostype &, const char * );106 void ?|?( ostype &, const char * ); 107 107 // ostype & ?|?( ostype &, const char16_t * ); 108 108 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous … … 111 111 // ostype & ?|?( ostype &, const wchar_t * ); 112 112 ostype & ?|?( ostype &, const void * ); 113 void &?|?( ostype &, const void * );113 void ?|?( ostype &, const void * ); 114 114 115 115 // manipulators … … 117 117 void ?|?( ostype &, ostype & (*)( ostype & ) ); 118 118 ostype & nl( ostype & ); 119 void nl( ostype & ); 119 120 ostype & nonl( ostype & ); 120 121 ostype & sep( ostype & ); … … 149 150 istype & read( istype &, char *, size_t ); 150 151 istype & ungetc( istype &, char ); 151 int fmt( istype &, const char f mt[], ... );152 int fmt( istype &, const char format[], ... ); 152 153 }; // istream 153 154 -
libcfa/src/rational.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:02:29 201813 // Update Count : 1 6812 // Last Modified On : Sun Dec 23 22:56:49 2018 13 // Update Count : 170 14 14 // 15 15 … … 181 181 182 182 void ?|?( ostype & os, Rational(RationalImpl) r ) { 183 (ostype )(os | r); if ( getANL( os ) )nl( os );183 (ostype &)(os | r); nl( os ); 184 184 } // ?|? 185 185 } // distribution -
libcfa/src/stdlib.hfa
r84b4d607 r25cdca5 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 27 07:21:36201813 // Update Count : 34 512 // Last Modified On : Mon Dec 17 15:37:45 2018 13 // Update Count : 346 14 14 // 15 15 … … 178 178 179 179 static 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 ); } 181 181 unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); } 182 182 long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); } -
libcfa/src/time.cfa
r84b4d607 r25cdca5 10 10 // Created On : Tue Mar 27 13:33:14 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 21:32:15201813 // Update Count : 5 312 // Last Modified On : Sun Dec 23 22:57:48 2018 13 // Update Count : 57 14 14 // 15 15 … … 33 33 forall( dtype ostype | ostream( ostype ) ) { 34 34 ostype & ?|?( ostype & os, Duration dur ) with( dur ) { 35 (ostype )(os | tv / TIMEGRAN); // print seconds35 (ostype &)(os | tv / TIMEGRAN); // print seconds 36 36 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 37 37 if ( ns != 0 ) { // some ? 38 38 char buf[16]; 39 (ostype )(os | nanomsd( ns, buf )); // print nanoseconds39 (ostype &)(os | nanomsd( ns, buf )); // print nanoseconds 40 40 } // if 41 41 return os; … … 43 43 44 44 void ?|?( ostype & os, Duration dur ) with( dur ) { 45 (ostype )(os | dur); if ( getANL( os ) )nl( os );45 (ostype &)(os | dur); nl( os ); 46 46 } // ?|? 47 47 } // distribution … … 150 150 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 151 151 if ( ns == 0 ) { // none ? 152 (ostype )(os | buf); // print date/time/year152 (ostype &)(os | buf); // print date/time/year 153 153 } else { 154 154 buf[19] = '\0'; // truncate to "Wed Jun 30 21:49:08" 155 155 char buf2[16]; 156 156 nanomsd( ns, buf2 ); // compute nanoseconds 157 (ostype )(os | buf | buf2 | ' ' | &buf[20]); // print date/time, nanoseconds and year157 (ostype &)(os | buf | buf2 | ' ' | &buf[20]); // print date/time, nanoseconds and year 158 158 } // if 159 159 return os; … … 161 161 162 162 void ?|?( ostype & os, Time time ) with( time ) { 163 (ostype )(os | time); if ( getANL( os ) )nl( os );163 (ostype &)(os | time); nl( os ); 164 164 } // ?|? 165 165 } // distribution -
tests/concurrent/examples/quickSort.cfa
r84b4d607 r25cdca5 9 9 // Created On : Wed Dec 6 12:15:52 2017 10 10 // Last Modified By : Peter A. Buhr 11 // Last Modified On : Tue Dec 4 18:00:27 201812 // Update Count : 16 711 // Last Modified On : Sat Dec 22 08:44:27 2018 12 // Update Count : 168 13 13 // 14 14 … … 151 151 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 152 152 } // for 153 sortedfile | nl ;153 sortedfile | nl | nl; 154 154 155 155 delete( values ); -
tests/coroutine/fmtLines.cfa
r84b4d607 r25cdca5 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 22:45:36201813 // Update Count : 4812 // Last Modified On : Sat Dec 22 18:27:00 2018 13 // Update Count : 57 14 14 // 15 15 … … 24 24 void main( Format & fmt ) with( fmt ) { 25 25 for () { // for as many characters 26 for ( g ; 5 ) {// groups of 5 blocks27 for ( b ; 4 ) {// blocks of 4 characters26 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 27 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 28 28 for () { // for newline characters 29 29 suspend(); 30 if ( ch != '\n' ) break;// ignore newline30 if ( ch != '\n' ) break; // ignore newline 31 31 } // for 32 32 sout | ch; // print character -
tests/fallthrough.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed Mar 14 10:06:25 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:36:14201813 // Update Count : 1712 // Last Modified On : Mon Dec 24 11:24:35 2018 13 // Update Count : 22 14 14 // 15 15 … … 18 18 void test(int choice) { 19 19 choose ( choice ) { 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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"; 35 35 // break 36 37 38 39 40 41 42 43 44 45 46 47 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"; 48 48 // break 49 50 51 52 } 49 default: 50 sout | "default"; 51 fallthru; 52 } // choose 53 53 54 54 sout | nl; … … 61 61 sout | "case 1"; 62 62 for ( int i = 0; i < 4; i += 1 ) { 63 printf("%d\n", i);63 sout | i; 64 64 if ( i == 2 ) fallthru common; 65 65 } // for … … 77 77 } // if 78 78 common: 79 printf( "common\n" );79 sout | "common"; 80 80 fallthru; 81 81 break; 82 82 default: 83 printf( "default\n" );83 sout | "default"; 84 84 fallthru; 85 85 } // switch … … 93 93 fallthru default; 94 94 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; 103 } 104 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; 105 103 } 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 } 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 114 114 #endif 115 115 } -
tests/fstream_test.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 4 21:36:34 201813 // Update Count : 6 712 // Last Modified On : Sat Dec 22 09:47:44 2018 13 // Update Count : 68 14 14 // 15 15 … … 24 24 | (nombre > 0 ? "positif" : nombre == 0 ? "zéro" : "négatif"); 25 25 26 sout | "Entrez trois nombres, s'il vous plaît: 26 sout | "Entrez trois nombres, s'il vous plaît:"; 27 27 int i, j, k; 28 28 sin | i | j | k; -
tests/genericUnion.cfa
r84b4d607 r25cdca5 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 1 16 #include <limits.hfa> 2 17 … … 4 19 union ByteView { 5 20 T val; 6 char bytes[(sizeof(int))]; 21 char bytes[(sizeof(int))]; // want to change to sizeof(T) 7 22 }; 8 23 9 24 forall(otype T) 10 25 void print(ByteView(T) x) { 11 for (int i = 0; i < sizeof(int); i++) { 26 for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T) 12 27 printf("%02x", x.bytes[i] & 0xff); 13 28 } … … 29 44 f(i, -1); 30 45 } 46 47 // Local Variables: // 48 // tab-width: 4 // 49 // compile-command: "cfa genericUnion.cfa" // 50 // End: // -
tests/gmp.cfa
r84b4d607 r25cdca5 10 10 // Created On : Tue Apr 19 08:55:51 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 4 21:37:29201813 // Update Count : 55 812 // Last Modified On : Thu Dec 20 22:41:47 2018 13 // Update Count : 559 14 14 // 15 15 … … 76 76 sout | "x:" | x | "y:" | y; 77 77 78 sout ;78 sout | nl; 79 79 80 80 sin | x | y | z; 81 81 sout | x | y | z; 82 82 83 sout ;83 sout | nl; 84 84 85 85 sout | "Fibonacci Numbers"; … … 94 94 } // for 95 95 96 sout ;96 sout | nl; 97 97 98 98 sout | "Factorial Numbers"; -
tests/io1.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 18:23:44201813 // Update Count : 11 012 // Last Modified On : Fri Dec 21 16:02:55 2018 13 // Update Count : 114 14 14 // 15 15 … … 22 22 sout | '1' | '2' | '3'; 23 23 sout | 1 | "" | 2 | "" | 3; 24 sout ;24 sout | nl; 25 25 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; 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; 36 37 sout | "x «" | 10; 38 sout | nl | nl; 37 39 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;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"; 49 51 sout | 11 | "} x"; 52 sout | nl | nl; 50 53 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;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; 57 60 sout | "\rx"; 61 sout | nl | nl; 58 62 63 sout | nlOn; 59 64 sout | "override opening/closing delimiters"; 60 65 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4; 61 sout ;66 sout | nl; 62 67 } 63 68 -
tests/io2.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 16:19:15201813 // Update Count : 11 012 // Last Modified On : Fri Dec 21 08:20:14 2018 13 // Update Count : 112 14 14 // 15 15 … … 96 96 sout | sepOn | 1 | 2 | 3 | sepOn; // no separator at start/end of line 97 97 sout | 1 | sepOff | 2 | 3; // locally turn off implicit separator 98 sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n' ; // no separator at start/end of line99 sout | 1 | 2 | 3 | "\n\n" | sepOn ; // no separator at start of next line98 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 100 100 sout | 1 | 2 | 3; 101 101 sout | nl; … … 133 133 // Local Variables: // 134 134 // tab-width: 4 // 135 // compile-command: "cfa io2.cfa" //135 // compile-command: "cfa -DIN_DIR=".in/" io2.cfa" // 136 136 // End: // -
tests/loopctrl.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed Aug 8 18:32:59 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 12 08:14:44201813 // Update Count : 7 612 // Last Modified On : Sun Dec 23 23:00:29 2018 13 // Update Count : 79 14 14 // 15 15 … … 32 32 S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; } 33 33 ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; } 34 void & ?|?( ofstream & os, S v ) { (ofstream )(os | v); if ( getANL( os ) )nl( os ); }34 void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); } 35 35 36 36 int main() { … … 38 38 while () { sout | "empty"; break; } sout | nl; 39 39 do { sout | "empty"; break; } while (); sout | nl; 40 for () { sout | "empty"; break; } sout | nl ;40 for () { sout | "empty"; break; } sout | nl | nl; 41 41 42 42 for ( 0 ) { sout | "A"; } sout | "zero" | nl; -
tests/polymorphism.cfa
r84b4d607 r25cdca5 9 9 // Author : Rob Schluntz 10 10 // Created On : Tue Oct 17 12:19:48 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Oct 17 12:21:07 201713 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 25 14:40:24 2018 13 // Update Count : 3 14 14 // 15 15 16 16 #include <assert.h> 17 17 #include <inttypes.h> 18 #include <fstream.hfa> 18 19 19 20 forall(otype T) … … 61 62 int y = 456; 62 63 int z = f(x, y); 63 printf("%d %d %d\n", x, y, z);64 sout | x | y | z; 64 65 } 65 66 66 { 67 67 // explicitly specialize function 68 68 int (*f)(int) = ident; 69 69 ((int(*)(int))ident); 70 printf("%d %d\n", f(5), ((int(*)(int))ident)(5));70 sout | f(5) | ((int(*)(int))ident)(5); 71 71 } 72 73 72 { 74 73 // test aggregates with polymorphic members … … 100 99 101 100 void print(x_type x) { 102 printf("%"PRIu32"\n", x);101 sout | x; 103 102 } 104 103 105 104 void print(y_type y) { 106 printf("%"PRIu64"\n", y);105 sout | y; 107 106 } 108 107 -
tests/pybin/tools.py
r84b4d607 r25cdca5 79 79 def diff( lhs, rhs ): 80 80 # diff the output of the files 81 diff_cmd = ("diff --ignore-all-space --text " 82 "--ignore-blank-lines " 81 diff_cmd = ("diff --text " 82 # "--ignore-all-space " 83 # "--ignore-blank-lines " 83 84 "--old-group-format='\t\tmissing lines :\n" 84 85 "%%<' \\\n" -
tests/raii/dtor-early-exit.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed Aug 17 08:26:25 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:05:24201813 // Update Count : 912 // Last Modified On : Fri Dec 21 08:45:19 2018 13 // Update Count : 10 14 14 // 15 15 … … 71 71 } 72 72 } 73 sout ;73 sout | nl; 74 74 for (int i = 0; i < 10; i++) { 75 75 switch(10) { -
tests/references.cfa
r84b4d607 r25cdca5 9 9 // Author : Rob Schluntz 10 10 // Created On : Wed Aug 23 16:11:50 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Aug 23 16:12:0313 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 25 14:31:48 2018 13 // Update Count : 11 14 14 // 15 15 16 #include <fstream.hfa> 17 16 18 struct Y { int i; }; 17 void ?{}( Y & y) { printf("Default constructing a Y\n"); }18 void ?{}( Y & y, Y other) { printf("Copy constructing a Y\n"); }19 void ^?{}( Y & y) { printf("Destructing a Y\n"); }20 Y ?=?( Y & y, Y other) { printf("Assigning a Y\n"); return y; }21 void ?{}( Y & y, int i) { printf("Value constructing a Y %d\n", i); y.i = 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; } 22 24 23 25 struct X { Y & r; Y y; }; 24 void ?{}( X & x) {26 void ?{}( X & x ) { 25 27 // ensure that r is not implicitly constructed 26 28 } 27 void ?{}( X & x, X other) {29 void ?{}( X & x, X other ) { 28 30 // ensure that r is not implicitly constructed 29 31 } 30 void ^?{}( X & x) {32 void ^?{}( X & x ) { 31 33 // ensure that r is not implicitly destructed 32 34 } 33 X ?=?( X & x, X other) { return x; }35 X ?=?( X & x, X other ) { return x; } 34 36 35 37 // ensure that generated functions do not implicitly operate on references … … 48 50 int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2, 49 51 &r1 = x, &&r2 = r1, &&&r3 = r2; 50 ***p3 = 3; 51 **p3 = &x; 52 *p3 = &p1; 53 int y = 0, z = 11, & ar[3] = { x, y, z }; 54 // &ar[1] = &z; // change reference array element55 // typeof( ar[1] ) p = 3; // is int, i.e., the type of referenced object56 // typeof( &ar[1] ) q = &x; // is int *, i.e., the type of pointer52 ***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 57 59 // _Static_assert( sizeof( ar[1] ) == sizeof( int ), "Array type should be int." ); // is true, i.e., the size of referenced object 58 60 // _Static_assert( sizeof( &ar[1] ) == sizeof( int *), "Address of array should be int *." ); // is true, i.e., the size of a reference 59 61 60 ((int*&)&r3) = &x; 62 ((int*&)&r3) = &x; // change r1, (&*)**r3 61 63 x = 3; 62 64 // test that basic reference properties are true - r1 should be an alias for x 63 printf("%d %d %d\n", x, r1, &x == &r1);65 sout | x | r1 | &x == &r1; 64 66 r1 = 12; 65 printf("%d %d %d\n", x, r1, &x == &r1);67 sout | x | r1 | &x == &r1; 66 68 67 69 // test that functions using basic references work 68 printf("%d %d %d %d\n", toref(&x), toref(p1), toptr(r1) == toptr(x), toptr(r1) == &x);70 sout | toref( &x ) | toref( p1 ) | toptr( r1 ) == toptr( x ) | toptr( r1 ) == &x; 69 71 70 72 changeRef( x ); 71 73 changeRef( y ); 72 74 changeRef( z ); 73 printf("%d %d %d\n", x, y, z);75 sout | x | y | z; 74 76 changeRef( r1 ); 75 printf("%d %d\n", r1, x);77 sout | r1 | x; 76 78 77 r3 = 6; 78 printf("x = %d ; x2 = %d\n", x, x2);// check that x was changed79 &r3 = &x2; 80 r3 = 999; 81 printf("x = %d ; x2 = %d\n", x, x2);// check that x2 was changed82 ((int**&)&&r3) = p2; 83 r3 = 12345; 84 printf("x = %d ; x2 = %d\n", x, x2);// check that x was changed85 &&&r3 = p3; 86 ((int&)r3) = 22222; 87 printf("x = %d ; x2 = %d\n", x, x2);// check that x was changed79 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 88 90 89 91 // test that reference members are not implicitly constructed/destructed/assigned … … 102 104 struct S { double x, y; }; 103 105 void f( int & i, int & j, S & s, int v[] ) { 104 printf("%d %d { %g, %g }, [%d, %d, %d]\n", i, j, s.[x, y], v[0], v[1], v[2]);106 sout | i | j | "{ " | s.[x, y] | " }," | "[" | v[0] | "," | v[1] | "," | v[2] | "]"; 105 107 } 106 void g(int & i) { printf("%d\n", i); }107 void h(int &&& i) { printf("%d\n", i); }108 void g(int & i) { sout | i; } 109 void h(int &&& i) { sout | i; } 108 110 109 int &&& r = 3; 111 int &&& r = 3; // rvalue to reference 110 112 int i = r; 111 printf("%d %d\n", i, r);// both 3113 sout | i | r; // both 3 112 114 113 g( 3 ); 114 h( (int &&&)3 ); 115 g( 3 ); // rvalue to reference 116 h( (int &&&)3 ); // rvalue to reference 115 117 116 118 int a = 5, b = 4; -
tests/searchsort.cfa
r84b4d607 r25cdca5 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 5 08:18:42201813 // Update Count : 10 612 // Last Modified On : Thu Dec 20 22:49:46 2018 13 // Update Count : 108 14 14 // 15 15 … … 21 21 22 22 int main( void ) { 23 const unsignedint size = 10;23 const int size = 10; 24 24 int iarr[size]; 25 25 26 26 sout | nlOff; // turn off auto newline 27 27 28 for ( i; 0 u~ size ) {28 for ( i; 0 ~ size ) { 29 29 iarr[i] = size - i; 30 30 sout | iarr[i] | ", "; 31 31 } // for 32 sout | nl ;32 sout | nl | nl; 33 33 34 34 // ascending sort/search by changing < to > 35 35 qsort( iarr, size ); 36 for ( i; 0 u~ size ) {36 for ( i; 0 ~ size ) { 37 37 sout | iarr[i] | ", "; 38 38 } // for 39 39 sout | nl; 40 for ( i; 0 u~ size ) { // C version40 for ( i; 0 ~ size ) { // C version 41 41 int key = size - i; 42 42 int * v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp ); … … 45 45 sout | nl; 46 46 47 for ( i; 0 u~ size ) {47 for ( i; 0 ~ size ) { 48 48 int * v = bsearch( size - i, iarr, size ); 49 49 sout | size - i | ':' | *v | ", "; 50 50 } // for 51 51 sout | nl; 52 for ( i; 0 u~ size ) {52 for ( i; 0 ~ size ) { 53 53 unsigned int posn = bsearch( size - i, iarr, size ); 54 54 sout | size - i | ':' | iarr[posn] | ", "; 55 55 } // for 56 sout | nl ;56 sout | nl | nl; 57 57 58 58 // descending sort/search by changing < to > … … 63 63 sout | nl; 64 64 { 65 int ?<?( int x, int y ) { return x > y; } 66 qsort( iarr, size ); 67 for ( i; 0u ~ size ) { 65 // redefinition of ?<? can't overlap the loop controls: 66 { 67 int (*?<?)(int, int) = ?>?; 68 qsort( iarr, size ); 69 } 70 for ( i; 0 ~ size ) { 68 71 sout | iarr[i] | ", "; 69 72 } // for 70 73 sout | nl; 71 for ( i; 0u ~ size ) { 74 for ( i; 0 ~ size ) { 75 int (*?<?)(int, int) = ?>?; 72 76 int * v = bsearch( size - i, iarr, size ); 73 77 sout | size - i | ':' | *v | ", "; 74 78 } // for 75 79 sout | nl; 76 for ( i; 0u ~ size ) { 80 for ( i; 0 ~ size ) { 81 int (*?<?)(int, int) = ?>?; 77 82 unsigned int posn = bsearch( size - i, iarr, size ); 78 83 sout | size - i | ':' | iarr[posn] | ", "; 79 84 } // for 80 85 } 81 sout | nl ;86 sout | nl | nl; 82 87 83 88 double darr[size]; 84 for ( i; 0 u~ size ) {89 for ( i; 0 ~ size ) { 85 90 darr[i] = size - i + 0.5; 86 91 sout | darr[i] | ", "; … … 88 93 sout | nl; 89 94 qsort( darr, size ); 90 for ( i; 0 u~ size ) {95 for ( i; 0 ~ size ) { 91 96 sout | darr[i] | ", "; 92 97 } // for 93 98 sout | nl; 94 for ( i; 0 u~ size ) {99 for ( i; 0 ~ size ) { 95 100 double * v = bsearch( size - i + 0.5, darr, size ); 96 101 sout | size - i + 0.5 | ':' | *v | ", "; 97 102 } // for 98 103 sout | nl; 99 for ( i; 0 u~ size ) {104 for ( i; 0 ~ size ) { 100 105 unsigned int posn = bsearch( size - i + 0.5, darr, size ); 101 106 sout | size - i + 0.5 | ':' | darr[posn] | ", "; 102 107 } // for 103 sout | nl ;108 sout | nl | nl; 104 109 105 110 struct S { int i, j; } sarr[size]; 106 111 int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; } 107 112 ofstream & ?|?( ofstream & os, S v ) { return os | v.i | ' ' | v.j; } 108 for ( i; 0 u~ size ) {113 for ( i; 0 ~ size ) { 109 114 sarr[i].i = size - i; 110 115 sarr[i].j = size - i + 1; … … 113 118 sout | nl; 114 119 qsort( sarr, size ); 115 for ( i; 0 u~ size ) {120 for ( i; 0 ~ size ) { 116 121 sout | sarr[i] | ", "; 117 122 } // for 118 123 sout | nl; 119 for ( i; 0 u~ size ) {124 for ( i; 0 ~ size ) { 120 125 S temp = { size - i, size - i + 1 }; 121 126 S * v = bsearch( temp, sarr, size ); … … 123 128 } // for 124 129 sout | nl; 125 for ( i; 0 u~ size ) {130 for ( i; 0 ~ size ) { 126 131 S temp = { size - i, size - i + 1 }; 127 132 unsigned int posn = bsearch( temp, sarr, size ); 128 133 sout | temp | ':' | sarr[posn] | ", "; 129 134 } // for 130 sout | nl ;135 sout | nl | nl; 131 136 { 132 unsignedint getKey( const S & s ) { return s.j; }133 for ( i; 0 u~ size ) {137 int getKey( const S & s ) { return s.j; } 138 for ( i; 0 ~ size ) { 134 139 sout | sarr[i] | ", "; 135 140 } // for 136 141 sout | nl; 137 for ( i; 0 u~ size ) {142 for ( i; 0 ~ size ) { 138 143 S * v = bsearch( size - i + 1, sarr, size ); 139 144 sout | size - i + 1 | ':' | *v | ", "; 140 145 } // for 141 146 sout | nl; 142 for ( i; 0 u~ size ) {147 for ( i; 0 ~ size ) { 143 148 unsigned int posn = bsearch( size - i + 1, sarr, size ); 144 149 sout | size - i + 1 | ':' | sarr[posn] | ", "; 145 150 } // for 146 sout | nl ;151 sout | nl | nl; 147 152 } 148 153 } // main -
tests/sum.cfa
r84b4d607 r25cdca5 11 11 // Created On : Wed May 27 17:56:53 2015 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Dec 11 21:50:41201814 // Update Count : 28 513 // Last Modified On : Sun Dec 23 23:00:38 2018 14 // Update Count : 287 15 15 // 16 16 … … 93 93 S ?++( S & t ) { S temp = t; t += (S){1}; return temp; } 94 94 ofstream & ?|?( ofstream & os, S v ) { return os | v.i | v.j; } 95 void ?|?( ofstream & os, S v ) { (ofstream )(os | v); if ( getANL( os ) )nl( os ); }95 void ?|?( ofstream & os, S v ) { (ofstream &)(os | v); nl( os ); } 96 96 97 97 S s = (S){0}, a[size], v = { low, low }; -
tests/swap.cfa
r84b4d607 r25cdca5 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 10:17:40201813 // Update Count : 7 412 // Last Modified On : Sun Dec 23 23:00:49 2018 13 // Update Count : 77 14 14 // 15 15 … … 85 85 struct S { int i, j; } s1 = { 1, 2 }, s2 = { 2, 1 }; 86 86 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 ); } 87 88 sout | "struct S\t\t" | s1 | "," | s2 | "\t\tswap " | nonl; 88 89 swap( s1, s2 ); -
tests/time.cfa
r84b4d607 r25cdca5 10 10 // Created On : Tue Mar 27 17:24:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Dec 11 21:44:03201813 // Update Count : 2 212 // Last Modified On : Thu Dec 20 23:09:21 2018 13 // Update Count : 23 14 14 // 15 15 … … 30 30 sout | d1 == 7`s | d1 == d2 | d1 == 0; 31 31 sout | div( 7`s, 2`s ); 32 sout | nl; 32 33 33 34 Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 }; … … 46 47 Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 }; 47 48 sout | t2 | t2.tv | nl | t3 | t3.tv; 49 sout | nl; 48 50 49 51 // Clock Newfoundland = { -3.5`h }, PST = { -8`h }; // distance from GMT (UTC) … … 53 55 // | "local nsec" | getTimeNsec() 54 56 // | "PST" | PST(); // getTime short form 55 // sout ;57 // sout | nl; 56 58 57 59 // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4 -
tests/withStatement.cfa
r84b4d607 r25cdca5 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon Dec 04 17:41:45 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Dec 04 17:45:07 201713 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 24 19:08:18 2018 13 // Update Count : 5 14 14 // 15 15 16 #include <fstream.hfa> 17 16 18 struct S { 17 18 19 19 int i; 20 // dynamically allocated member ensures ctor/dtors are called correctly on temporaries 21 int * ptr; 20 22 }; 21 23 22 24 // with clause on reference parameter 23 void ?{}( S & this, int n) with(this) {24 25 ptr = (int *)malloc(sizeof(int));25 void ?{}( S & this, int n ) with( this ) { 26 i = n; 27 ptr = (int *)malloc( sizeof(int) ); 26 28 } 27 29 28 void ?{}( S & this) {29 30 void ?{}( S & this ) { 31 this{ 0 }; 30 32 } 31 33 32 void ?{}( S & this, S other) {33 34 void ?{}( S & this, S other ) { 35 this{ other.i }; 34 36 } 35 37 36 S ?=?( S & this, S other) with(this) {37 38 39 38 S ?=?( S & this, S other ) with( this ) { 39 i = other.i; 40 *ptr = *other.ptr; 41 return this; 40 42 } 41 43 42 void ^?{}( S & this) with(this) {43 free(ptr);44 void ^?{}( S & this ) with( this ) { 45 free( ptr ); 44 46 } 45 47 46 48 struct S2 { 47 49 S s; 48 50 }; 49 51 50 void ?{}( S2 & this, int n) {51 52 void ?{}( S2 & this, int n ) { 53 (this.s){ n }; 52 54 } 53 55 54 forall( otype T)56 forall( otype T ) 55 57 struct Box { 56 58 T x; 57 59 }; 58 60 59 forall( otype T)60 void ?{}( Box(T) & this) with(this) { // with clause in polymorphic function61 61 forall( otype T ) 62 void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function 63 x{}; 62 64 } 63 65 64 void print( int i) { printf("%d", i); }66 void print( int i ) { sout | i; } 65 67 66 forall(otype T | { void print(T); }) 67 void foo(T t) { 68 Box(T) b = { t }; 69 with(b) { // with statement in polymorphic function 70 print(x); 71 printf("\n"); 72 } 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 } 73 74 } 74 75 75 76 // ensure with-statement temporary generation works correctly 76 77 S mk() { 77 printf("called mk\n");78 return (S){ 444 };78 sout | "called mk"; 79 return (S){ 444 }; 79 80 } 80 81 81 82 // ensure with-statement temporary generation with reference-returning functions works correctly 82 83 S & ref() { 83 84 84 static S var = { 123456789 }; 85 return var; 85 86 } 86 87 87 88 int main() { 88 89 with (s2) {90 with(s) { // with s2.s91 printf("%d %d %d\n", i, s.i, s2.s.i);92 foo(i); // s.i93 with(mk()) {94 printf("%d %d %d\n", i, i, i);95 with(ref()) {96 printf("%d %d %d\n", i, i, i);97 98 with(ref()) {99 printf("%d %d %d\n", i, i, i);100 101 102 103 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 104 105 } 105 106
Note: See TracChangeset
for help on using the changeset viewer.