- Timestamp:
- Jul 3, 2018, 3:25:56 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 638ac26
- Parents:
- c653b37 (diff), bbe1a87 (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. - Location:
- src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/LinkageSpec.h
rc653b37 re3b2474 10 10 // Created On : Sat May 16 13:24:28 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:32:16 201713 // Update Count : 1 412 // Last Modified On : Mon Jul 2 07:46:49 2018 13 // Update Count : 16 14 14 // 15 15 … … 22 22 namespace LinkageSpec { 23 23 // All linkage specs are some combination of these flags: 24 enum { 25 Mangle = 1 << 0, 26 Generate = 1 << 1, 27 Overrideable = 1 << 2, 28 Builtin = 1 << 3, 29 GccBuiltin = 1 << 4, 30 31 NoOfSpecs = 1 << 5, 32 }; 24 enum { Mangle = 1 << 0, Generate = 1 << 1, Overrideable = 1 << 2, Builtin = 1 << 3, GccBuiltin = 1 << 4, NoOfSpecs = 1 << 5, }; 33 25 34 26 union Spec { … … 42 34 }; 43 35 constexpr Spec( unsigned int val ) : val( val ) {} 44 constexpr Spec( Spec const & other ) : val( other.val ) {}36 constexpr Spec( Spec const & other ) : val( other.val ) {} 45 37 // Operators may go here. 46 38 // Supports == and != 47 constexpr operator unsigned int 39 constexpr operator unsigned int() const { return val; } 48 40 }; 49 41 -
src/Parser/parser.yy
rc653b37 re3b2474 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jun 24 10:41:10201813 // Update Count : 3 58712 // Last Modified On : Mon Jul 2 20:23:14 2018 13 // Update Count : 3607 14 14 // 15 15 … … 112 112 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 113 113 iter->set_extension( true ); 114 } // for 115 } // distExt 116 117 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 118 // distribute qualifiers across all declarations in a distribution statemement 119 for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 120 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 121 iter->addQualifiers( qualifiers->clone() ); 122 } // if 114 123 } // for 115 124 } // distExt … … 1136 1145 1137 1146 waitfor: 1138 WAITFOR '(' identifier ')' 1139 { 1140 $$ = new ExpressionNode( new NameExpr( *$3 ) ); 1141 delete $3; 1142 } 1143 | WAITFOR '(' identifier ',' argument_expression_list ')' 1144 { 1145 $$ = new ExpressionNode( new NameExpr( *$3 ) ); 1146 $$->set_last( $5 ); 1147 delete $3; 1148 } 1147 WAITFOR '(' cast_expression ')' 1148 { $$ = $3; } 1149 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1150 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1149 1151 ; 1150 1152 … … 1163 1165 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); } 1164 1166 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1167 | when_clause_opt timeout statement WOR ELSE statement 1168 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1165 1169 | when_clause_opt timeout statement WOR when_clause ELSE statement 1166 1170 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); } … … 2380 2384 '{' up external_definition_list_opt down '}' // CFA, namespace 2381 2385 { 2382 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2383 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2384 iter->addQualifiers( $1->clone() ); 2385 } // if 2386 } // for 2386 distQual( $5, $1 ); 2387 2387 xxx = false; 2388 2388 delete $1; … … 2391 2391 | declaration_qualifier_list 2392 2392 { 2393 if ( $1->type ->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }2394 if ( $1->type ->forall ) xxx = forall = true; // remember generic type2393 if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2394 if ( $1->type && $1->type->forall ) xxx = forall = true; // remember generic type 2395 2395 } 2396 2396 '{' up external_definition_list_opt down '}' // CFA, namespace 2397 2397 { 2398 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2399 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2400 iter->addQualifiers( $1->clone() ); 2401 } // if 2402 } // for 2398 distQual( $5, $1 ); 2403 2399 xxx = false; 2404 2400 delete $1; … … 2412 2408 '{' up external_definition_list_opt down '}' // CFA, namespace 2413 2409 { 2414 for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2415 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2416 iter->addQualifiers( $1->clone() ); 2417 iter->addQualifiers( $2->clone() ); 2418 } // if 2419 } // for 2410 distQual( $6, $2 ); 2411 distQual( $6, $1 ); 2420 2412 xxx = false; 2421 2413 delete $1; -
src/ResolvExpr/Resolver.cc
rc653b37 re3b2474 583 583 // Make sure we don't widen any existing bindings 584 584 resultEnv.forbidWidening(); 585 585 586 586 // Find any unbound type variables 587 587 resultEnv.extractOpenVars( openVars ); … … 590 590 auto param_end = function->parameters.end(); 591 591 592 int n_mutex_ arg= 0;592 int n_mutex_param = 0; 593 593 594 594 // For every arguments of its set, check if it matches one of the parameter … … 600 600 // We ran out of parameters but still have arguments 601 601 // this function doesn't match 602 SemanticError( function, toString("candidate function not viable: too many mutex arguments, expected ", n_mutex_ arg, "\n" ));602 SemanticError( function, toString("candidate function not viable: too many mutex arguments, expected ", n_mutex_param, "\n" )); 603 603 } 604 604 605 n_mutex_ arg++;605 n_mutex_param++; 606 606 607 607 // Check if the argument matches the parameter type in the current scope … … 626 626 // Check if parameters are missing 627 627 if( advance_to_mutex( param, param_end ) ) { 628 do { 629 n_mutex_param++; 630 param++; 631 } while( advance_to_mutex( param, param_end ) ); 632 628 633 // We ran out of arguments but still have parameters left 629 634 // this function doesn't match 630 SemanticError( function, toString("candidate function not viable: too few mutex arguments, expected ", n_mutex_ arg, "\n" ));635 SemanticError( function, toString("candidate function not viable: too few mutex arguments, expected ", n_mutex_param, "\n" )); 631 636 } 632 637 -
src/libcfa/clock
rc653b37 re3b2474 10 10 // Created On : Thu Apr 12 14:36:06 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 12 16:53:31 201813 // Update Count : 312 // Last Modified On : Mon Jul 2 21:40:01 2018 13 // Update Count : 7 14 14 // 15 15 … … 34 34 }; 35 35 36 static inline void resetClock( Clock & clk ) with( clk ) { 37 clocktype = CLOCK_REALTIME_COARSE; 38 } // Clock::resetClock 36 static inline { 37 void resetClock( Clock & clk ) with( clk ) { 38 clocktype = CLOCK_REALTIME_COARSE; 39 } // Clock::resetClock 39 40 40 static inlinevoid resetClock( Clock & clk, Duration adj ) with( clk ) {41 clocktype = -1;42 offset = adj + timezone`s;// timezone (global) is (UTC - local time) in seconds43 } // resetClock41 void resetClock( Clock & clk, Duration adj ) with( clk ) { 42 clocktype = -1; 43 offset = adj + __timezone`s; // timezone (global) is (UTC - local time) in seconds 44 } // resetClock 44 45 45 static inlinevoid ?{}( Clock & clk ) { resetClock( clk ); }46 static inlinevoid ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }46 void ?{}( Clock & clk ) { resetClock( clk ); } 47 void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); } 47 48 48 static inline Duration getRes() {49 struct timespec res;50 clock_getres( CLOCK_REALTIME_COARSE, &res );51 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;52 } // getRes49 Duration getResNsec() { 50 struct timespec res; 51 clock_getres( CLOCK_REALTIME, &res ); 52 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 53 } // getRes 53 54 54 static inline Time getTimeNsec() { // with nanoseconds 55 timespec curr;56 clock_gettime( CLOCK_REALTIME_COARSE, &curr);57 return (Time){ curr };58 } // getTime 55 Duration getRes() { 56 struct timespec res; 57 clock_getres( CLOCK_REALTIME_COARSE, &res ); 58 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 59 } // getRes 59 60 60 static inline Time getTime() { // without nanoseconds 61 timespec curr; 62 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); 63 curr.tv_nsec = 0; 64 return (Time){ curr }; 65 } // getTime 61 Time getTimeNsec() { // with nanoseconds 62 timespec curr; 63 clock_gettime( CLOCK_REALTIME, &curr ); 64 return (Time){ curr }; 65 } // getTime 66 66 67 static inline Time getTime( Clock & clk ) with( clk ) { 68 return getTime() + offset; 69 } // getTime 67 Time getTime() { // without nanoseconds 68 timespec curr; 69 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); 70 curr.tv_nsec = 0; 71 return (Time){ curr }; 72 } // getTime 70 73 71 static inline Time ?()( Clock & clk ) with( clk ) { // alternative syntax 72 return getTime() + offset;73 } // getTime74 Time getTime( Clock & clk ) with( clk ) { 75 return getTime() + offset; 76 } // getTime 74 77 75 static inline timeval getTime( Clock & clk ) { 76 return (timeval){ clk() };77 } // getTime78 Time ?()( Clock & clk ) with( clk ) { // alternative syntax 79 return getTime() + offset; 80 } // getTime 78 81 79 static inline tm getTime( Clock & clk ) with( clk ) { 80 tm ret; 81 localtime_r( getTime( clk ).tv_sec, &ret ); 82 return ret; 83 } // getTime 82 timeval getTime( Clock & clk ) { 83 return (timeval){ clk() }; 84 } // getTime 85 86 tm getTime( Clock & clk ) with( clk ) { 87 tm ret; 88 localtime_r( getTime( clk ).tv_sec, &ret ); 89 return ret; 90 } // getTime 91 } // distribution 84 92 85 93 // Local Variables: // -
src/libcfa/iostream
rc653b37 re3b2474 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jun 2 08:07:55201813 // Update Count : 15 312 // Last Modified On : Sun Jul 1 12:12:22 2018 13 // Update Count : 155 14 14 // 15 15 … … 42 42 void open( ostype & os, const char * name, const char * mode ); 43 43 void close( ostype & os ); 44 ostype & write( ostype &, const char *, unsigned long int );44 ostype & write( ostype &, const char *, size_t ); 45 45 int fmt( ostype &, const char fmt[], ... ); 46 46 }; // ostream … … 117 117 void open( istype & is, const char * name ); 118 118 void close( istype & is ); 119 istype & read( istype &, char *, unsigned long int );119 istype & read( istype &, char *, size_t ); 120 120 istype & ungetc( istype &, char ); 121 121 int fmt( istype &, const char fmt[], ... ); -
src/libcfa/stdlib
rc653b37 re3b2474 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 2 08:46:35201813 // Update Count : 3 0612 // Last Modified On : Tue Jul 3 08:17:28 2018 13 // Update Count : 324 14 14 // 15 15 … … 264 264 //--------------------------------------- 265 265 266 extern "C" { void srandom( unsigned int seed ); } // override C version 267 char random( void ); 268 char random( char u ); 269 char random( char l, char u ); 270 int random( void ); 271 int random( int u ); 272 int random( int l, int u ); 273 unsigned int random( void ); 274 unsigned int random( unsigned int u ); 275 unsigned int random( unsigned int l, unsigned int u ); 276 extern "C" { long int random( void ); } // override C version 277 long int random( long int u ); 278 long int random( long int l, long int u ); 279 unsigned long int random( void ); 280 unsigned long int random( unsigned long int u ); 281 unsigned long int random( unsigned long int l, unsigned long int u ); 282 float random( void ); 283 double random( void ); 284 float _Complex random( void ); 285 double _Complex random( void ); 286 long double _Complex random( void ); 266 extern "C" { // override C version 267 void srandom( unsigned int seed ); 268 long int random( void ); 269 } // extern "C" 270 271 static inline { 272 long int random( long int l, long int u ) { if ( u < l ) [u, l] = [l, u]; return lrand48() % (u - l) + l; } // [l,u) 273 long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); } // [0,u) 274 unsigned long int random( void ) { return lrand48(); } 275 unsigned long int random( unsigned long int l, unsigned long int u ) { if ( u < l ) [u, l] = [l, u]; return lrand48() % (u - l) + l; } // [l,u) 276 unsigned long int random( unsigned long int u ) { return lrand48() % u; } // [0,u) 277 278 char random( void ) { return (unsigned long int)random(); } 279 char random( char u ) { return random( (unsigned long int)u ); } // [0,u) 280 char random( char l, char u ) { return random( (unsigned long int)l, (unsigned long int)u ); } // [l,u) 281 int random( void ) { return (long int)random(); } 282 int random( int u ) { return random( (long int)u ); } // [0,u] 283 int random( int l, int u ) { return random( (long int)l, (long int)u ); } // [l,u) 284 unsigned int random( void ) { return (unsigned long int)random(); } 285 unsigned int random( unsigned int u ) { return random( (unsigned long int)u ); } // [0,u] 286 unsigned int random( unsigned int l, unsigned int u ) { return random( (unsigned long int)l, (unsigned long int)u ); } // [l,u) 287 } // distribution 288 289 float random( void ); // [0.0, 1.0) 290 double random( void ); // [0.0, 1.0) 291 float _Complex random( void ); // [0.0, 1.0)+[0.0, 1.0)i 292 double _Complex random( void ); // [0.0, 1.0)+[0.0, 1.0)i 293 long double _Complex random( void ); // [0.0, 1.0)+[0.0, 1.0)i 287 294 288 295 //--------------------------------------- -
src/libcfa/stdlib.c
rc653b37 re3b2474 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 2 06:15:05201813 // Update Count : 4 4812 // Last Modified On : Tue Jul 3 08:17:30 2018 13 // Update Count : 457 14 14 // 15 15 … … 249 249 //--------------------------------------- 250 250 251 extern "C" { void srandom( unsigned int seed ) { srand48( (long int)seed ); } } // override C version 252 char random( void ) { return (unsigned long int)random(); } 253 char random( char u ) { return random( (unsigned long int)u ); } 254 char random( char l, char u ) { return random( (unsigned long int)l, (unsigned long int)u ); } 255 int random( void ) { return (long int)random(); } 256 int random( int u ) { return random( (long int)u ); } 257 int random( int l, int u ) { return random( (long int)l, (long int)u ); } 258 unsigned int random( void ) { return (unsigned long int)random(); } 259 unsigned int random( unsigned int u ) { return random( (unsigned long int)u ); } 260 unsigned int random( unsigned int l, unsigned int u ) { return random( (unsigned long int)l, (unsigned long int)u ); } 261 extern "C" { long int random( void ) { return mrand48(); } } // override C version 262 long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); } 263 long int random( long int l, long int u ) { assert( l < u ); return lrand48() % (u - l) + l; } 264 unsigned long int random( void ) { return lrand48(); } 265 unsigned long int random( unsigned long int u ) { return lrand48() % u; } 266 unsigned long int random( unsigned long int l, unsigned long int u ) { assert( l < u ); return lrand48() % (u - l) + l; } 251 extern "C" { // override C version 252 void srandom( unsigned int seed ) { srand48( (long int)seed ); } 253 long int random( void ) { return mrand48(); } 254 } // extern "C" 255 267 256 float random( void ) { return (float)drand48(); } // cast otherwise float uses lrand48 268 257 double random( void ) { return drand48(); } -
src/libcfa/time
rc653b37 re3b2474 10 10 // Created On : Wed Mar 14 23:18:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 14 17:48:23201813 // Update Count : 6 3612 // Last Modified On : Mon Jul 2 21:28:38 2018 13 // Update Count : 641 14 14 // 15 15 … … 27 27 enum { TIMEGRAN = 1_000_000_000LL }; // nanosecond granularity, except for timeval 28 28 29 30 29 //######################### Duration ######################### 31 30 32 static inline Duration ?=?( Duration & dur, zero_t ) { return dur{ 0 }; } 33 34 static inline Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; } 35 static inline Duration ?+?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv + rhs.tv }; } 36 static inline Duration ?+=?( Duration & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; } 37 38 static inline Duration -?( Duration rhs ) with( rhs ) { return (Duration)@{ -tv }; } 39 static inline Duration ?-?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; } 40 static inline Duration ?-=?( Duration & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; } 41 42 static inline Duration ?*?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv * rhs }; } 43 static inline Duration ?*?( int64_t lhs, Duration rhs ) { return (Duration)@{ lhs * rhs.tv }; } 44 static inline Duration ?*=?( Duration & lhs, int64_t rhs ) { lhs = lhs * rhs; return lhs; } 45 46 static inline int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; } 47 static inline Duration ?/?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv / rhs }; } 48 static inline Duration ?/=?( Duration & lhs, int64_t rhs ) { lhs = lhs / rhs; return lhs; } 49 static inline double div( Duration lhs, Duration rhs ) { return (double)lhs.tv / (double)rhs.tv; } 50 51 static inline Duration ?%?( Duration lhs, Duration rhs ) { return (Duration)@{ lhs.tv % rhs.tv }; } 52 static inline Duration ?%=?( Duration & lhs, Duration rhs ) { lhs = lhs % rhs; return lhs; } 53 54 static inline _Bool ?==?( Duration lhs, Duration rhs ) { return lhs.tv == rhs.tv; } 55 static inline _Bool ?!=?( Duration lhs, Duration rhs ) { return lhs.tv != rhs.tv; } 56 static inline _Bool ?<? ( Duration lhs, Duration rhs ) { return lhs.tv < rhs.tv; } 57 static inline _Bool ?<=?( Duration lhs, Duration rhs ) { return lhs.tv <= rhs.tv; } 58 static inline _Bool ?>? ( Duration lhs, Duration rhs ) { return lhs.tv > rhs.tv; } 59 static inline _Bool ?>=?( Duration lhs, Duration rhs ) { return lhs.tv >= rhs.tv; } 60 61 static inline _Bool ?==?( Duration lhs, zero_t ) { return lhs.tv == 0; } 62 static inline _Bool ?!=?( Duration lhs, zero_t ) { return lhs.tv != 0; } 63 static inline _Bool ?<? ( Duration lhs, zero_t ) { return lhs.tv < 0; } 64 static inline _Bool ?<=?( Duration lhs, zero_t ) { return lhs.tv <= 0; } 65 static inline _Bool ?>? ( Duration lhs, zero_t ) { return lhs.tv > 0; } 66 static inline _Bool ?>=?( Duration lhs, zero_t ) { return lhs.tv >= 0; } 67 68 static inline Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; } 69 70 static inline Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; } 71 static inline Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; } 72 static inline Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; } 73 static inline Duration ?`s( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; } 74 static inline Duration ?`s( double sec ) { return (Duration)@{ sec * TIMEGRAN }; } 75 static inline Duration ?`m( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 76 static inline Duration ?`m( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 77 static inline Duration ?`h( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; } 78 static inline Duration ?`h( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; } 79 static inline Duration ?`d( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; } 80 static inline Duration ?`d( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; } 81 static inline Duration ?`w( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 82 static inline Duration ?`w( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 83 84 static inline int64_t ?`ns( Duration dur ) { return dur.tv; } 85 static inline int64_t ?`us( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000_000LL); } 86 static inline int64_t ?`ms( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000LL); } 87 static inline int64_t ?`s( Duration dur ) { return dur.tv / TIMEGRAN; } 88 static inline int64_t ?`m( Duration dur ) { return dur.tv / (60LL * TIMEGRAN); } 89 static inline int64_t ?`h( Duration dur ) { return dur.tv / (60LL * 60LL * TIMEGRAN); } 90 static inline int64_t ?`d( Duration dur ) { return dur.tv / (24LL * 60LL * 60LL * TIMEGRAN); } 91 static inline int64_t ?`w( Duration dur ) { return dur.tv / (7LL * 24LL * 60LL * 60LL * TIMEGRAN); } 92 93 static inline Duration max( Duration lhs, Duration rhs ) { return (lhs.tv < rhs.tv) ? rhs : lhs;} 94 static inline Duration min( Duration lhs, Duration rhs ) { return !(rhs.tv < lhs.tv) ? lhs : rhs;} 95 31 static inline { 32 Duration ?=?( Duration & dur, zero_t ) { return dur{ 0 }; } 33 34 Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; } 35 Duration ?+?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv + rhs.tv }; } 36 Duration ?+=?( Duration & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; } 37 38 Duration -?( Duration rhs ) with( rhs ) { return (Duration)@{ -tv }; } 39 Duration ?-?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; } 40 Duration ?-=?( Duration & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; } 41 42 Duration ?*?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv * rhs }; } 43 Duration ?*?( int64_t lhs, Duration rhs ) { return (Duration)@{ lhs * rhs.tv }; } 44 Duration ?*=?( Duration & lhs, int64_t rhs ) { lhs = lhs * rhs; return lhs; } 45 46 int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; } 47 Duration ?/?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv / rhs }; } 48 Duration ?/=?( Duration & lhs, int64_t rhs ) { lhs = lhs / rhs; return lhs; } 49 double div( Duration lhs, Duration rhs ) { return (double)lhs.tv / (double)rhs.tv; } 50 51 Duration ?%?( Duration lhs, Duration rhs ) { return (Duration)@{ lhs.tv % rhs.tv }; } 52 Duration ?%=?( Duration & lhs, Duration rhs ) { lhs = lhs % rhs; return lhs; } 53 54 _Bool ?==?( Duration lhs, Duration rhs ) { return lhs.tv == rhs.tv; } 55 _Bool ?!=?( Duration lhs, Duration rhs ) { return lhs.tv != rhs.tv; } 56 _Bool ?<? ( Duration lhs, Duration rhs ) { return lhs.tv < rhs.tv; } 57 _Bool ?<=?( Duration lhs, Duration rhs ) { return lhs.tv <= rhs.tv; } 58 _Bool ?>? ( Duration lhs, Duration rhs ) { return lhs.tv > rhs.tv; } 59 _Bool ?>=?( Duration lhs, Duration rhs ) { return lhs.tv >= rhs.tv; } 60 61 _Bool ?==?( Duration lhs, zero_t ) { return lhs.tv == 0; } 62 _Bool ?!=?( Duration lhs, zero_t ) { return lhs.tv != 0; } 63 _Bool ?<? ( Duration lhs, zero_t ) { return lhs.tv < 0; } 64 _Bool ?<=?( Duration lhs, zero_t ) { return lhs.tv <= 0; } 65 _Bool ?>? ( Duration lhs, zero_t ) { return lhs.tv > 0; } 66 _Bool ?>=?( Duration lhs, zero_t ) { return lhs.tv >= 0; } 67 68 Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; } 69 70 Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; } 71 Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; } 72 Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; } 73 Duration ?`s( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; } 74 Duration ?`s( double sec ) { return (Duration)@{ sec * TIMEGRAN }; } 75 Duration ?`m( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 76 Duration ?`m( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 77 Duration ?`h( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; } 78 Duration ?`h( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; } 79 Duration ?`d( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; } 80 Duration ?`d( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; } 81 Duration ?`w( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 82 Duration ?`w( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 83 84 int64_t ?`ns( Duration dur ) { return dur.tv; } 85 int64_t ?`us( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000_000LL); } 86 int64_t ?`ms( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000LL); } 87 int64_t ?`s( Duration dur ) { return dur.tv / TIMEGRAN; } 88 int64_t ?`m( Duration dur ) { return dur.tv / (60LL * TIMEGRAN); } 89 int64_t ?`h( Duration dur ) { return dur.tv / (60LL * 60LL * TIMEGRAN); } 90 int64_t ?`d( Duration dur ) { return dur.tv / (24LL * 60LL * 60LL * TIMEGRAN); } 91 int64_t ?`w( Duration dur ) { return dur.tv / (7LL * 24LL * 60LL * 60LL * TIMEGRAN); } 92 93 Duration max( Duration lhs, Duration rhs ) { return (lhs.tv < rhs.tv) ? rhs : lhs;} 94 Duration min( Duration lhs, Duration rhs ) { return !(rhs.tv < lhs.tv) ? lhs : rhs;} 95 } // distribution 96 96 97 97 //######################### C timeval ######################### 98 98 99 static inline void ?{}( timeval & t ) {} 100 static inline void ?{}( timeval & t, time_t sec, suseconds_t usec ) { t.tv_sec = sec; t.tv_usec = usec; } 101 static inline void ?{}( timeval & t, time_t sec ) { t{ sec, 0 }; } 102 static inline void ?{}( timeval & t, zero_t ) { t{ 0, 0 }; } 103 static inline timeval ?=?( timeval & t, zero_t ) { return t{ 0 }; } 104 static inline timeval ?+?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_usec + rhs.tv_usec }; } 105 static inline timeval ?-?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_usec - rhs.tv_usec }; } 106 static inline _Bool ?==?( timeval lhs, timeval rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_usec == rhs.tv_usec; } 107 static inline _Bool ?!=?( timeval lhs, timeval rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_usec != rhs.tv_usec; } 108 99 static inline { 100 void ?{}( timeval & t ) {} 101 void ?{}( timeval & t, time_t sec, suseconds_t usec ) { t.tv_sec = sec; t.tv_usec = usec; } 102 void ?{}( timeval & t, time_t sec ) { t{ sec, 0 }; } 103 void ?{}( timeval & t, zero_t ) { t{ 0, 0 }; } 104 105 timeval ?=?( timeval & t, zero_t ) { return t{ 0 }; } 106 timeval ?+?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_usec + rhs.tv_usec }; } 107 timeval ?-?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_usec - rhs.tv_usec }; } 108 _Bool ?==?( timeval lhs, timeval rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_usec == rhs.tv_usec; } 109 _Bool ?!=?( timeval lhs, timeval rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_usec != rhs.tv_usec; } 110 } // distribution 109 111 110 112 //######################### C timespec ######################### 111 113 112 static inline void ?{}( timespec & t ) {} 113 static inline void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ) { t.tv_sec = sec; t.tv_nsec = nsec; } 114 static inline void ?{}( timespec & t, time_t sec ) { t{ sec, 0}; } 115 static inline void ?{}( timespec & t, zero_t ) { t{ 0, 0 }; } 116 static inline timespec ?=?( timespec & t, zero_t ) { return t{ 0 }; } 117 static inline timespec ?+?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_nsec + rhs.tv_nsec }; } 118 static inline timespec ?-?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_nsec - rhs.tv_nsec }; } 119 static inline _Bool ?==?( timespec lhs, timespec rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_nsec == rhs.tv_nsec; } 120 static inline _Bool ?!=?( timespec lhs, timespec rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_nsec != rhs.tv_nsec; } 121 114 static inline { 115 void ?{}( timespec & t ) {} 116 void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ) { t.tv_sec = sec; t.tv_nsec = nsec; } 117 void ?{}( timespec & t, time_t sec ) { t{ sec, 0}; } 118 void ?{}( timespec & t, zero_t ) { t{ 0, 0 }; } 119 120 timespec ?=?( timespec & t, zero_t ) { return t{ 0 }; } 121 timespec ?+?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_nsec + rhs.tv_nsec }; } 122 timespec ?-?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_nsec - rhs.tv_nsec }; } 123 _Bool ?==?( timespec lhs, timespec rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_nsec == rhs.tv_nsec; } 124 _Bool ?!=?( timespec lhs, timespec rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_nsec != rhs.tv_nsec; } 125 } // distribution 122 126 123 127 //######################### C itimerval ######################### 124 128 125 static inline void ?{}( itimerval & itv, Duration alarm ) with( itv ) { 126 // itimerval contains durations but but uses time data-structure timeval. 127 it_value{ alarm`s, (alarm % 1`s)`us }; // seconds, microseconds 128 it_interval{ 0 }; // 0 seconds, 0 microseconds 129 } // itimerval 130 131 static inline void ?{}( itimerval & itv, Duration alarm, Duration interval ) with( itv ) { 132 // itimerval contains durations but but uses time data-structure timeval. 133 it_value{ alarm`s, (alarm % 1`s)`us }; // seconds, microseconds 134 it_interval{ interval`s, interval`us }; // seconds, microseconds 135 } // itimerval 136 129 static inline { 130 void ?{}( itimerval & itv, Duration alarm ) with( itv ) { 131 // itimerval contains durations but but uses time data-structure timeval. 132 it_value{ alarm`s, (alarm % 1`s)`us }; // seconds, microseconds 133 it_interval{ 0 }; // 0 seconds, 0 microseconds 134 } // itimerval 135 136 void ?{}( itimerval & itv, Duration alarm, Duration interval ) with( itv ) { 137 // itimerval contains durations but but uses time data-structure timeval. 138 it_value{ alarm`s, (alarm % 1`s)`us }; // seconds, microseconds 139 it_interval{ interval`s, interval`us }; // seconds, microseconds 140 } // itimerval 141 } // distribution 137 142 138 143 //######################### Time ######################### 139 144 140 145 void ?{}( Time & time, int year, int month = 0, int day = 0, int hour = 0, int min = 0, int sec = 0, int nsec = 0 ); 141 static inline Time ?=?( Time & time, zero_t ) { return time{ 0 }; } 142 143 static inline void ?{}( Time & time, timeval t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; } 144 static inline Time ?=?( Time & time, timeval t ) with( time ) { 145 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL); 146 return time; 147 } // ?=? 148 149 static inline void ?{}( Time & time, timespec t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; } 150 static inline Time ?=?( Time & time, timespec t ) with( time ) { 151 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; 152 return time; 153 } // ?=? 154 155 static inline Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; } 156 static inline Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; } 157 static inline Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; } 158 159 static inline Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; } 160 static inline Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; } 161 static inline Time ?-=?( Time & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; } 162 static inline _Bool ?==?( Time lhs, Time rhs ) { return lhs.tv == rhs.tv; } 163 static inline _Bool ?!=?( Time lhs, Time rhs ) { return lhs.tv != rhs.tv; } 164 static inline _Bool ?<?( Time lhs, Time rhs ) { return lhs.tv < rhs.tv; } 165 static inline _Bool ?<=?( Time lhs, Time rhs ) { return lhs.tv <= rhs.tv; } 166 static inline _Bool ?>?( Time lhs, Time rhs ) { return lhs.tv > rhs.tv; } 167 static inline _Bool ?>=?( Time lhs, Time rhs ) { return lhs.tv >= rhs.tv; } 146 static inline { 147 Time ?=?( Time & time, zero_t ) { return time{ 0 }; } 148 149 void ?{}( Time & time, timeval t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; } 150 Time ?=?( Time & time, timeval t ) with( time ) { 151 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL); 152 return time; 153 } // ?=? 154 155 void ?{}( Time & time, timespec t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; } 156 Time ?=?( Time & time, timespec t ) with( time ) { 157 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; 158 return time; 159 } // ?=? 160 161 Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; } 162 Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; } 163 Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; } 164 165 Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; } 166 Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; } 167 Time ?-=?( Time & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; } 168 _Bool ?==?( Time lhs, Time rhs ) { return lhs.tv == rhs.tv; } 169 _Bool ?!=?( Time lhs, Time rhs ) { return lhs.tv != rhs.tv; } 170 _Bool ?<?( Time lhs, Time rhs ) { return lhs.tv < rhs.tv; } 171 _Bool ?<=?( Time lhs, Time rhs ) { return lhs.tv <= rhs.tv; } 172 _Bool ?>?( Time lhs, Time rhs ) { return lhs.tv > rhs.tv; } 173 _Bool ?>=?( Time lhs, Time rhs ) { return lhs.tv >= rhs.tv; } 174 } // distribution 168 175 169 176 char * yy_mm_dd( Time time, char * buf ); -
src/tests/literals.c
rc653b37 re3b2474 10 10 // Created On : Sat Sep 9 16:34:38 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 4 10:41:31201813 // Update Count : 13 412 // Last Modified On : Sun Jul 1 15:12:15 2018 13 // Update Count : 137 14 14 // 15 15 … … 155 155 156 156 // binary 157 0b01101011_l8; 0b01101011_l16; 0b01101011_l32; 0b01101011_l64; 0b01101011_l128; 0b01101011_l8u; 0b01101011_ul16; 0b01101011_l32u; 0b01101011_ul64; 0b01101011_ul128; 158 +0b01101011_l8; +0b01101011_l16; +0b01101011_l32; +0b01101011_l64; +0b01101011_l128; +0b01101011_l8u; +0b01101011_ul16; +0b01101011_l32u; +0b01101011_ul64; +0b01101011_ul128; 159 -0b01101011_l8; -0b01101011_l16; -0b01101011_l32; -0b01101011_l64; -0b01101011_l128; -0b01101011_l8u; -0b01101011_ul16; -0b01101011_l32u; -0b01101011_ul64; -0b01101011_ul128; 157 0b01101011_l8; 0b01101011_l16; 0b01101011_l32; 0b01101011_l64; 0b01101011_l8u; 0b01101011_ul16; 0b01101011_l32u; 0b01101011_ul64; 158 +0b01101011_l8; +0b01101011_l16; +0b01101011_l32; +0b01101011_l64; +0b01101011_l8u; +0b01101011_ul16; +0b01101011_l32u; +0b01101011_ul64; 159 -0b01101011_l8; -0b01101011_l16; -0b01101011_l32; -0b01101011_l64; -0b01101011_l8u; -0b01101011_ul16; -0b01101011_l32u; -0b01101011_ul64; 160 161 #ifdef __LP64__ // 64-bit processor 162 0b01101011_l128; 0b01101011_ul128; 163 +0b01101011_l128; +0b01101011_ul128; 164 -0b01101011_l128; -0b01101011_ul128; 165 #endif // __LP64__ 160 166 161 167 // octal 162 01234567_l8; 01234567_l16; 01234567_l32; 01234567_l64; 01234567_l128; 01234567_l8u; 01234567_ul16; 01234567_l32u; 01234567_ul64; 01234567_ul128; 163 +01234567_l8; +01234567_l16; +01234567_l32; +01234567_l64; +01234567_l128; +01234567_l8u; +01234567_ul16; +01234567_l32u; +01234567_ul64; +01234567_ul128; 164 -01234567_l8; -01234567_l16; -01234567_l32; -01234567_l64; -01234567_l128; -01234567_l8u; -01234567_ul16; -01234567_l32u; -01234567_ul64; -01234567_ul128; 168 01234567_l8; 01234567_l16; 01234567_l32; 01234567_l64; 01234567_l8u; 01234567_ul16; 01234567_l32u; 01234567_ul64; 169 +01234567_l8; +01234567_l16; +01234567_l32; +01234567_l64; +01234567_l8u; +01234567_ul16; +01234567_l32u; +01234567_ul64; 170 -01234567_l8; -01234567_l16; -01234567_l32; -01234567_l64; -01234567_l8u; -01234567_ul16; -01234567_l32u; -01234567_ul64; 171 172 #ifdef __LP64__ // 64-bit processor 173 01234567_l128; 01234567_ul128; 174 +01234567_l128; +01234567_ul128; 175 -01234567_l128; -01234567_ul128; 176 #endif // __LP64__ 165 177 166 178 // decimal 167 1234567890L8; 1234567890L16; 1234567890l32; 1234567890l64; 1234567890l128; 1234567890UL8; 1234567890L16U; 1234567890Ul32; 1234567890l64u; 1234567890l128u; 168 +1234567890L8; +1234567890L16; +1234567890l32; +1234567890l64; +1234567890l128; +1234567890UL8; +1234567890L16U; +1234567890Ul32; +1234567890l64u; +1234567890l128u; 169 -1234567890L8; -1234567890L16; -1234567890l32; -1234567890l64; -1234567890l128; -1234567890UL8; -1234567890L16U; -1234567890Ul32; -1234567890l64u; -1234567890l128u; 179 1234567890L8; 1234567890L16; 1234567890l32; 1234567890l64; 1234567890UL8; 1234567890L16U; 1234567890Ul32; 1234567890l64u; 180 +1234567890L8; +1234567890L16; +1234567890l32; +1234567890l64; +1234567890UL8; +1234567890L16U; +1234567890Ul32; +1234567890l64u; 181 -1234567890L8; -1234567890L16; -1234567890l32; -1234567890l64; -1234567890UL8; -1234567890L16U; -1234567890Ul32; -1234567890l64u; 182 183 #ifdef __LP64__ // 64-bit processor 184 1234567890l128; 1234567890l128u; 185 +1234567890l128; +1234567890l128u; 186 -1234567890l128; -1234567890l128u; 187 #endif // __LP64__ 170 188 171 189 // hexadecimal
Note: See TracChangeset
for help on using the changeset viewer.