Changes in / [a2c2363:e3784a50]
- Files:
-
- 3 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/common.hfa
ra2c2363 re3784a50 69 69 T min( T v1, T v2 ) { return v1 < v2 ? v1 : v2; } 70 70 71 forall( T, Ts... | { T min( T, T ); T min( T, T , Ts ); } )72 T min( T v1, T v2, T v3, Ts vs ) { return min( min( v1, v2 ), v3, vs ); }71 forall( T, Ts... | { T min( T, T ); T min( T, Ts ); } ) 72 T min( T v1, T v2, Ts vs ) { return min( min( v1, v2 ), vs ); } 73 73 74 74 forall( T | { int ?>?( T, T ); } ) 75 75 T max( T v1, T v2 ) { return v1 > v2 ? v1 : v2; } 76 76 77 forall( T, Ts... | { T max( T, T ); T max( T, T , Ts ); } )78 T max( T v1, T v2, T v3, Ts vs ) { return max( max( v1, v2 ), v3, vs ); }77 forall( T, Ts... | { T max( T, T ); T max( T, Ts ); } ) 78 T max( T v1, T v2, Ts vs ) { return max( max( v1, v2 ), vs ); } 79 79 80 80 forall( T | { T min( T, T ); T max( T, T ); } ) -
src/GenPoly/GenPoly.cc
ra2c2363 re3784a50 48 48 } 49 49 50 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env ) { 51 for ( auto ¶m : params ) { 52 auto paramType = param.as<ast::TypeExpr>(); 53 assertf( paramType, "Aggregate parameters should be type expressions" ); 54 if ( isPolyType( paramType->type, env ) ) return true; 50 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env) { 51 for (auto ¶m : params) { 52 auto paramType = param.strict_as<ast::TypeExpr>(); 53 if (isPolyType(paramType->type, env)) return true; 55 54 } 56 55 return false; … … 63 62 assertf(paramType, "Aggregate parameters should be type expressions"); 64 63 if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true; 65 }66 return false;67 }68 69 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const TypeVarMap & typeVars, const ast::TypeSubstitution * env ) {70 for ( auto & param : params ) {71 auto paramType = param.as<ast::TypeExpr>();72 assertf( paramType, "Aggregate parameters should be type expressions" );73 if ( isPolyType( paramType->type, typeVars, env ) ) return true;74 64 } 75 65 return false; … … 195 185 } 196 186 187 const ast::Type * isPolyType(const ast::Type * type, const TyVarMap & tyVars, const ast::TypeSubstitution * env) { 188 type = replaceTypeInst( type, env ); 189 190 if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( type ) ) { 191 if ( tyVars.contains( typeInst->typeString() ) ) return type; 192 } else if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) { 193 return isPolyType( arrayType->base, env ); 194 } else if ( auto structType = dynamic_cast< const ast::StructInstType* >( type ) ) { 195 if ( hasPolyParams( structType->params, env ) ) return type; 196 } else if ( auto unionType = dynamic_cast< const ast::UnionInstType* >( type ) ) { 197 if ( hasPolyParams( unionType->params, env ) ) return type; 198 } 199 return nullptr; 200 } 201 197 202 const ast::Type * isPolyType( const ast::Type * type, 198 203 const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) { … … 202 207 if ( typeVars.contains( *inst ) ) return type; 203 208 } else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) { 204 return isPolyType( array->base, typeVars,subst );209 return isPolyType( array->base, subst ); 205 210 } else if ( auto sue = dynamic_cast< const ast::StructInstType * >( type ) ) { 206 if ( hasPolyParams( sue->params, typeVars,subst ) ) return type;211 if ( hasPolyParams( sue->params, subst ) ) return type; 207 212 } else if ( auto sue = dynamic_cast< const ast::UnionInstType * >( type ) ) { 208 if ( hasPolyParams( sue->params, typeVars,subst ) ) return type;213 if ( hasPolyParams( sue->params, subst ) ) return type; 209 214 } 210 215 return nullptr; -
tests/.expect/minmax.txt
ra2c2363 re3784a50 20 20 double 4. 3.1 max 4. 21 21 long double 4. 3.1 max 4. 22 23 3 arguments24 2 3 4 min 2 max 425 4 2 3 min 2 max 426 3 4 2 min 2 max 427 4 arguments28 3 2 5 4 min 2 max 529 5 3 4 2 min 2 max 5 -
tests/concurrency/actors/dynamic.cfa
ra2c2363 re3784a50 9 9 struct derived_actor { inline actor; }; 10 10 struct derived_msg { 11 12 11 inline message; 12 int cnt; 13 13 }; 14 14 15 15 void ?{}( derived_msg & this, int cnt ) { 16 set_allocation( this, Delete );17 16 ((message &) this){ Delete }; 17 this.cnt = cnt; 18 18 } 19 19 void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; } 20 20 21 21 allocation receive( derived_actor & receiver, derived_msg & msg ) { 22 23 24 25 26 27 28 29 30 31 22 if ( msg.cnt >= Times ) { 23 sout | "Done"; 24 return Delete; 25 } 26 derived_msg * d_msg = alloc(); 27 (*d_msg){ msg.cnt + 1 }; 28 derived_actor * d_actor = alloc(); 29 (*d_actor){}; 30 *d_actor | *d_msg; 31 return Delete; 32 32 } 33 33 34 34 int main( int argc, char * argv[] ) { 35 35 switch ( argc ) { 36 36 case 2: 37 37 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 38 Times = ato ( argv[1] );39 if ( Times < 1 ) fallthru default;38 Times = atoi( argv[1] ); 39 if ( Times < 1 ) goto Usage; 40 40 } // if 41 41 case 1: // use defaults 42 42 break; 43 43 default: 44 exit | "Usage: " | argv[0] | " [ times (> 0) ]"; 44 Usage: 45 sout | "Usage: " | argv[0] | " [ times (> 0) ]"; 46 exit( EXIT_FAILURE ); 45 47 } // switch 46 48 47 sout | "starting";49 printf("starting\n"); 48 50 49 50 51 executor e{ 0, 1, 1, false }; 52 start_actor_system( e ); 51 53 52 sout | "started";54 printf("started\n"); 53 55 54 55 56 57 58 56 derived_msg * d_msg = alloc(); 57 (*d_msg){}; 58 derived_actor * d_actor = alloc(); 59 (*d_actor){}; 60 *d_actor | *d_msg; 59 61 60 sout | "stopping";62 printf("stopping\n"); 61 63 62 64 stop_actor_system(); 63 65 64 sout | "stopped"; 66 printf("stopped\n"); 67 68 return 0; 65 69 } -
tests/concurrency/actors/executor.cfa
ra2c2363 re3784a50 10 10 static int ids = 0; 11 11 struct d_actor { 12 13 14 12 inline actor; 13 d_actor * gstart; 14 int id, rounds, recs, sends; 15 15 }; 16 16 void ?{}( d_actor & this ) with(this) { 17 18 19 20 21 17 id = ids++; 18 gstart = (&this + (id / Set * Set - id)); // remember group-start array-element 19 rounds = Set * Rounds; // send at least one message to each group member 20 recs = 0; 21 sends = 0; 22 22 } 23 23 … … 25 25 26 26 allocation receive( d_actor & this, d_msg & msg ) with( this ) { 27 28 29 30 31 32 33 34 35 27 if ( recs == rounds ) return Finished; 28 if ( recs % Batch == 0 ) { 29 for ( i; Batch ) { 30 gstart[sends % Set] | shared_msg; 31 sends += 1; 32 } 33 } 34 recs += 1; 35 return Nodelete; 36 36 } 37 37 38 38 int main( int argc, char * argv[] ) { 39 39 switch ( argc ) { 40 40 case 7: 41 41 if ( strcmp( argv[6], "d" ) != 0 ) { // default ? 42 BufSize = ato ( argv[6] );43 if ( BufSize < 0 ) fallthru default;42 BufSize = atoi( argv[6] ); 43 if ( BufSize < 0 ) goto Usage; 44 44 } // if 45 45 case 6: 46 46 if ( strcmp( argv[5], "d" ) != 0 ) { // default ? 47 Batch = ato ( argv[5] );48 if ( Batch < 1 ) fallthru default;47 Batch = atoi( argv[5] ); 48 if ( Batch < 1 ) goto Usage; 49 49 } // if 50 50 case 5: 51 51 if ( strcmp( argv[4], "d" ) != 0 ) { // default ? 52 Processors = ato ( argv[4] );53 if ( Processors < 1 ) fallthru default;52 Processors = atoi( argv[4] ); 53 if ( Processors < 1 ) goto Usage; 54 54 } // if 55 55 case 4: 56 56 if ( strcmp( argv[3], "d" ) != 0 ) { // default ? 57 Rounds = ato ( argv[3] );58 if ( Rounds < 1 ) fallthru default;57 Rounds = atoi( argv[3] ); 58 if ( Rounds < 1 ) goto Usage; 59 59 } // if 60 60 case 3: 61 61 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 62 Set = ato ( argv[2] );63 if ( Set < 1 ) fallthru default;62 Set = atoi( argv[2] ); 63 if ( Set < 1 ) goto Usage; 64 64 } // if 65 65 case 2: 66 66 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 67 Actors = ato ( argv[1] );68 if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) fallthru default;67 Actors = atoi( argv[1] ); 68 if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) goto Usage; 69 69 } // if 70 70 case 1: // use defaults 71 71 break; 72 72 default: 73 exit | "Usage: " | argv[0] 74 | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors 73 Usage: 74 sout | "Usage: " | argv[0] 75 | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors 75 76 | ") ] [ set (> 0) | 'd' (default " | Set 76 77 | ") ] [ rounds (> 0) | 'd' (default " | Rounds … … 79 80 | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize 80 81 | ") ]" ; 82 exit( EXIT_FAILURE ); 81 83 } // switch 82 84 83 85 executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true }; 84 86 85 sout | "starting";87 printf("starting\n"); 86 88 87 89 start_actor_system( e ); 88 90 89 sout | "started";91 printf("started\n"); 90 92 91 93 d_actor actors[ Actors ]; 92 94 93 95 for ( i; Actors ) { … … 95 97 } // for 96 98 97 sout | "stopping";99 printf("stopping\n"); 98 100 99 101 stop_actor_system(); 100 102 101 sout | "stopped"; 103 printf("stopped\n"); 104 105 return 0; 102 106 } -
tests/concurrency/actors/inherit.cfa
ra2c2363 re3784a50 18 18 19 19 allocation handle() { 20 20 return Finished; 21 21 } 22 22 … … 27 27 28 28 int main() { 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 29 sout | "Start"; 30 { 31 start_actor_system(); 32 D_msg * dm = alloc(); 33 (*dm){}; 34 D_msg2 * dm2 = alloc(); 35 (*dm2){}; 36 Server2 * s = alloc(); 37 (*s){}; 38 Server2 * s2 = alloc(); 39 (*s2){}; 40 *s | *dm; 41 *s2 | *dm2; 42 stop_actor_system(); 43 } 44 { 45 start_actor_system(); 46 Server s[2]; 47 D_msg * dm = alloc(); 48 (*dm){}; 49 D_msg2 * dm2 = alloc(); 50 (*dm2){}; 51 s[0] | *dm; 52 s[1] | *dm2; 53 stop_actor_system(); 54 } 55 sout | "Finished"; 56 56 } -
tests/concurrency/actors/inline.cfa
ra2c2363 re3784a50 3 3 4 4 struct d_actor { 5 5 inline actor; 6 6 }; 7 7 struct msg_wrapper { 8 9 8 int b; 9 inline message; 10 10 }; 11 11 void ^?{}( msg_wrapper & this ) { sout | "msg_wrapper dtor"; } 12 12 13 13 struct d_msg { 14 15 14 int m; 15 inline msg_wrapper; 16 16 }; 17 17 void ?{}( d_msg & this, int m, int b ) { this.m = m; this.b = b; set_allocation( this, Delete ); } … … 19 19 20 20 allocation receive( d_actor &, d_msg & msg ) { 21 22 23 21 sout | msg.m; 22 sout | msg.b; 23 return Finished; 24 24 } 25 25 26 26 struct d_msg2 { 27 28 27 int m; 28 inline msg_wrapper; 29 29 }; 30 30 void ^?{}( d_msg2 & this ) { sout | "d_msg2 dtor";} 31 31 32 32 allocation receive( d_actor &, d_msg2 & msg ) { 33 34 33 sout | msg.m; 34 return Finished; 35 35 } 36 36 37 37 int main() { 38 39 40 start_actor_system();// sets up executor41 42 43 44 45 stop_actor_system();// waits until actors finish46 47 48 start_actor_system();// sets up executor49 50 51 52 53 54 55 56 stop_actor_system();// waits until actors finish57 38 processor p; 39 { 40 start_actor_system(); // sets up executor 41 d_actor da; 42 d_msg * dm = alloc(); 43 (*dm){ 42, 2423 }; 44 da | *dm; 45 stop_actor_system(); // waits until actors finish 46 } 47 { 48 start_actor_system(); // sets up executor 49 d_actor da; 50 d_msg2 dm{ 29079 }; 51 set_allocation( dm, Nodelete ); 52 msg_wrapper * mw = &dm; 53 message * mg = &dm; 54 virtual_dtor * v = &dm; 55 da | dm; 56 stop_actor_system(); // waits until actors finish 57 } 58 58 } -
tests/concurrency/actors/matrix.cfa
ra2c2363 re3784a50 5 5 #include <stdio.h> 6 6 7 int xr = 500, xc = 500, yc = 500, Processors = 1; // default values, must be signed 7 unsigned int xr = 500, xc = 500, yc = 500, Processors = 1; // default values 8 8 9 9 struct derived_actor { inline actor; }; 10 10 11 11 struct derived_msg { 12 13 12 inline message; 13 int * Z; 14 14 int * X; 15 15 int ** Y; 16 16 }; 17 17 18 18 void ?{}( derived_msg & this ) {} 19 19 void ?{}( derived_msg & this, int * Z, int * X, int ** Y ) { 20 set_allocation( this, Nodelete );21 22 23 20 ((message &) this){ Nodelete }; 21 this.Z = Z; 22 this.X = X; 23 this.Y = Y; 24 24 } 25 25 26 26 allocation receive( derived_actor & receiver, derived_msg & msg ) { 27 28 29 30 31 32 33 27 for ( unsigned int i = 0; i < yc; i += 1 ) { // multiply X_row by Y_col and sum products 28 msg.Z[i] = 0; 29 for ( unsigned int j = 0; j < xc; j += 1 ) { 30 msg.Z[i] += msg.X[j] * msg.Y[j][i]; 31 } // for 32 } // for 33 return Finished; 34 34 } 35 35 36 36 int main( int argc, char * argv[] ) { 37 37 switch ( argc ) { 38 38 case 5: 39 39 if ( strcmp( argv[4], "d" ) != 0 ) { // default ? 40 Processors = ato ( argv[4] );41 if ( Processors < 1 ) fallthru default;40 Processors = atoi( argv[4] ); 41 if ( Processors < 1 ) goto Usage; 42 42 } // if 43 43 case 4: 44 44 if ( strcmp( argv[3], "d" ) != 0 ) { // default ? 45 xr = ato ( argv[3] );46 if ( xr < 1 ) fallthru default;45 xr = atoi( argv[3] ); 46 if ( xr < 1 ) goto Usage; 47 47 } // if 48 48 case 3: 49 49 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 50 xc = ato ( argv[2] );51 if ( xc < 1 ) fallthru default;50 xc = atoi( argv[2] ); 51 if ( xc < 1 ) goto Usage; 52 52 } // if 53 53 case 2: 54 54 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 55 yc = ato ( argv[1] );56 if ( yc < 1 ) fallthru default;55 yc = atoi( argv[1] ); 56 if ( yc < 1 ) goto Usage; 57 57 } // if 58 58 case 1: // use defaults 59 59 break; 60 60 default: 61 exit | "Usage: " | argv[0] 61 Usage: 62 sout | "Usage: " | argv[0] 62 63 | " [ yc (> 0) | 'd' (default " | yc 63 64 | ") ] [ xc (> 0) | 'd' (default " | xc … … 65 66 | ") ] [ processors (> 0) | 'd' (default " | Processors 66 67 | ") ]" ; 68 exit( EXIT_FAILURE ); 67 69 } // switch 68 70 69 71 unsigned int r, c; 70 72 int * Z[xr], * X[xr], * Y[xc]; 71 73 … … 86 88 } // for 87 89 88 90 executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true }; 89 91 90 sout | "starting";92 printf("starting\n"); 91 93 92 94 start_actor_system( e ); 93 95 94 sout | "started";96 printf("started\n"); 95 97 96 98 derived_msg messages[xr]; 97 99 98 100 derived_actor actors[xr]; 99 101 100 102 for ( unsigned int r = 0; r < xr; r += 1 ) { … … 106 108 } // for 107 109 108 sout | "stopping";110 printf("stopping\n"); 109 111 110 112 stop_actor_system(); 111 113 112 sout | "stopped";114 printf("stopped\n"); 113 115 114 116 for ( r = 0; r < xr; r += 1 ) { // deallocate X and Z matrices 115 117 free( X[r] ); 116 118 free( Z[r] ); 117 119 } // for 118 120 for ( r = 0; r < xc; r += 1 ) { // deallocate Y matrix 119 121 free( Y[r] ); 120 122 } // for 123 124 return 0; 121 125 } -
tests/concurrency/actors/pingpong.cfa
ra2c2363 re3784a50 10 10 11 11 struct p_msg { 12 13 12 inline message; 13 size_t count; 14 14 }; 15 //static inline void ?{}( p_msg & this ) { ((message &)this){}; this.count = 0; } 16 static inline void ?{}( p_msg & this ) { this.count = 0; } 15 static inline void ?{}( p_msg & this ) { ((message &)this){}; this.count = 0; } 17 16 18 17 ping * pi; … … 21 20 22 21 allocation receive( ping & receiver, p_msg & msg ) { 23 24 22 msg.count++; 23 if ( msg.count > times ) return Finished; 25 24 26 27 28 29 25 allocation retval = Nodelete; 26 if ( msg.count == times ) retval = Finished; 27 *po | msg; 28 return retval; 30 29 } 31 30 32 31 allocation receive( pong & receiver, p_msg & msg ) { 33 34 35 36 37 38 39 32 msg.count++; 33 if ( msg.count > times ) return Finished; 34 35 allocation retval = Nodelete; 36 if ( msg.count == times ) retval = Finished; 37 *pi | msg; 38 return retval; 40 39 } 41 40 … … 43 42 44 43 int main( int argc, char * argv[] ) { 45 sout | "start";44 printf("start\n"); 46 45 47 46 processor p[Processors - 1]; 48 47 49 start_actor_system( Processors ); // test passing number of processors 50 ping pi_actor; 51 pong po_actor; 52 po = &po_actor; 53 pi = &pi_actor; 54 p_msg m; 55 pi_actor | m; 56 stop_actor_system(); 48 start_actor_system( Processors ); // test passing number of processors 57 49 58 sout | "end"; 50 ping pi_actor; 51 pong po_actor; 52 po = &po_actor; 53 pi = &pi_actor; 54 p_msg m; 55 pi_actor | m; 56 stop_actor_system(); 57 58 printf("end\n"); 59 return 0; 59 60 } -
tests/concurrency/actors/poison.cfa
ra2c2363 re3784a50 11 11 12 12 int main() { 13 13 sout | "Start"; 14 14 15 16 17 18 19 20 21 22 23 15 sout | "Finished"; 16 { 17 start_actor_system(); 18 Server s[10]; 19 for ( i; 10 ) { 20 s[i] | finished_msg; 21 } 22 stop_actor_system(); 23 } 24 24 25 26 27 28 29 30 31 32 33 34 25 sout | "Delete"; 26 { 27 start_actor_system(); 28 for ( i; 10 ) { 29 Server * s = alloc(); 30 (*s){}; 31 (*s) | delete_msg; 32 } 33 stop_actor_system(); 34 } 35 35 36 37 38 39 40 41 42 43 44 45 46 36 sout | "Destroy"; 37 { 38 start_actor_system(); 39 Server s[10]; 40 for ( i; 10 ) 41 s[i] | destroy_msg; 42 stop_actor_system(); 43 for ( i; 10 ) 44 if (s[i].val != 777) 45 sout | "Error: dtor not called correctly."; 46 } 47 47 48 sout | "Done"; 48 sout | "Done"; 49 return 0; 49 50 } -
tests/concurrency/actors/static.cfa
ra2c2363 re3784a50 9 9 struct derived_actor { inline actor; }; 10 10 struct derived_msg { 11 12 11 inline message; 12 int cnt; 13 13 }; 14 14 15 15 void ?{}( derived_msg & this, int cnt ) { 16 set_allocation( this, Nodelete );17 16 ((message &) this){ Nodelete }; 17 this.cnt = cnt; 18 18 } 19 19 void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; } 20 20 21 21 allocation receive( derived_actor & receiver, derived_msg & msg ) { 22 23 24 25 26 27 28 22 if ( msg.cnt >= Times ) { 23 sout | "Done"; 24 return Finished; 25 } 26 msg.cnt++; 27 receiver | msg; 28 return Nodelete; 29 29 } 30 30 31 31 int main( int argc, char * argv[] ) { 32 32 switch ( argc ) { 33 33 case 2: 34 34 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 35 Times = ato ( argv[1] );36 if ( Times < 1 ) fallthru default;35 Times = atoi( argv[1] ); 36 if ( Times < 1 ) goto Usage; 37 37 } // if 38 38 case 1: // use defaults 39 39 break; 40 40 default: 41 exit | "Usage: " | argv[0] | " [ times (> 0) ]"; 41 Usage: 42 sout | "Usage: " | argv[0] | " [ times (> 0) ]"; 43 exit( EXIT_FAILURE ); 42 44 } // switch 43 45 44 sout | "starting";46 printf("starting\n"); 45 47 46 47 48 executor e{ 0, 1, 1, false }; 49 start_actor_system( e ); 48 50 49 sout | "started";51 printf("started\n"); 50 52 51 53 derived_msg msg; 52 54 53 55 derived_actor actor; 54 56 55 57 actor | msg; 56 58 57 sout | "stopping";59 printf("stopping\n"); 58 60 59 61 stop_actor_system(); 60 62 61 sout | "stopped"; 63 printf("stopped\n"); 64 65 return 0; 62 66 } -
tests/concurrency/actors/types.cfa
ra2c2363 re3784a50 9 9 10 10 struct derived_actor { 11 12 11 inline actor; 12 int counter; 13 13 }; 14 14 static inline void ?{}( derived_actor & this ) { ((actor &)this){}; this.counter = 0; } 15 15 16 16 struct d_msg { 17 18 17 inline message; 18 int num; 19 19 }; 20 20 21 21 // this isn't a valid receive routine since int is not a message type 22 22 allocation receive( derived_actor & receiver, int i ) with( receiver ) { 23 24 25 26 23 mutex(sout) sout | i; 24 counter++; 25 if ( counter == 2 ) return Finished; 26 return Nodelete; 27 27 } 28 28 29 29 allocation receive( derived_actor & receiver, d_msg & msg ) { 30 30 return receive( receiver, msg.num ); 31 31 } 32 32 33 33 struct derived_actor2 { 34 35 34 struct nested { int i; }; // testing nested before inline 35 inline actor; 36 36 }; 37 37 38 38 allocation receive( derived_actor2 & receiver, d_msg & msg ) { 39 40 39 mutex(sout) sout | msg.num; 40 return Finished; 41 41 } 42 42 … … 44 44 struct derived_actor4 { inline derived_actor3; }; 45 45 struct d_msg2 { 46 47 46 inline message; 47 int num; 48 48 }; 49 49 50 50 allocation receive( derived_actor3 & receiver, d_msg & msg ) { 51 52 53 51 mutex(sout) sout | msg.num; 52 if ( msg.num == -1 ) return Nodelete; 53 return Finished; 54 54 } 55 55 56 56 allocation receive( derived_actor3 & receiver, d_msg2 & msg ) { 57 58 57 mutex(sout) sout | msg.num; 58 return Finished; 59 59 } 60 60 … … 62 62 63 63 int main( int argc, char * argv[] ) { 64 sout | "start";64 printf("start\n"); 65 65 66 66 processor p[Processors - 1]; 67 67 68 sout | "basic test";69 70 71 72 73 74 75 68 printf("basic test\n"); 69 start_actor_system( Processors ); // test passing number of processors 70 derived_actor a; 71 d_msg b, c; 72 b.num = 1; 73 c.num = 2; 74 a | b | c; 75 stop_actor_system(); 76 76 77 sout | "same message and different actors test";78 79 80 81 82 83 84 77 printf("same message and different actors test\n"); 78 start_actor_system(); // let system detect # of processors 79 derived_actor2 d_ac2_0, d_ac2_1; 80 d_msg d_ac2_msg; 81 d_ac2_msg.num = 3; 82 d_ac2_0 | d_ac2_msg; 83 d_ac2_1 | d_ac2_msg; 84 stop_actor_system(); 85 85 86 87 88 sout | "same message and different actor types test";89 90 91 92 93 94 95 96 97 98 86 87 { 88 printf("same message and different actor types test\n"); 89 executor e{ 0, Processors, Processors == 1 ? 1 : Processors * 4, false }; 90 start_actor_system( e ); // pass an explicit executor 91 derived_actor2 d_ac2_2; 92 derived_actor3 d_ac3_0; 93 d_msg d_ac23_msg; 94 d_ac23_msg.num = 4; 95 d_ac3_0 | d_ac23_msg; 96 d_ac2_2 | d_ac23_msg; 97 stop_actor_system(); 98 } // RAII to clean up executor 99 99 100 101 sout | "different message types, one actor test";102 103 104 105 106 107 108 109 110 111 100 { 101 printf("different message types, one actor test\n"); 102 executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true }; 103 start_actor_system( Processors ); 104 derived_actor3 a3; 105 d_msg b1; 106 d_msg2 c2; 107 b1.num = -1; 108 c2.num = 5; 109 a3 | b1 | c2; 110 stop_actor_system(); 111 } // RAII to clean up executor 112 112 113 114 sout | "nested inheritance actor test";115 116 117 118 119 120 121 122 123 124 113 { 114 printf("nested inheritance actor test\n"); 115 executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true }; 116 start_actor_system( Processors ); 117 derived_actor4 a4; 118 d_msg b1; 119 d_msg2 c2; 120 b1.num = -1; 121 c2.num = 5; 122 a4 | b1 | c2; 123 stop_actor_system(); 124 } // RAII to clean up executor 125 125 126 sout | "end"; 126 printf("end\n"); 127 return 0; 127 128 } -
tests/concurrency/channels/barrier.cfa
ra2c2363 re3784a50 8 8 9 9 size_t total_operations = 0; 10 ssize_t Processors = 1, Tasks = 5, BarrierSize = 2; // must be signed 10 int Processors = 1, Tasks = 5, BarrierSize = 2; 11 11 12 12 typedef channel( int ) Channel; … … 65 65 case 3: 66 66 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 67 BarrierSize = ato ( argv[2] );68 if ( Processors < 1 ) fallthru default;67 BarrierSize = atoi( argv[2] ); 68 if ( Processors < 1 ) goto Usage; 69 69 } // if 70 70 case 2: 71 71 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 72 Processors = ato ( argv[1] );73 if ( Processors < 1 ) fallthru default;72 Processors = atoi( argv[1] ); 73 if ( Processors < 1 ) goto Usage; 74 74 } // if 75 75 case 1: // use defaults 76 76 break; 77 77 default: 78 exit | "Usage: " | argv[0] 78 Usage: 79 sout | "Usage: " | argv[0] 79 80 | " [ processors (> 0) | 'd' (default " | Processors 80 81 | ") ] [ BarrierSize (> 0) | 'd' (default " | BarrierSize 81 82 | ") ]" ; 83 exit( EXIT_FAILURE ); 82 84 } // switch 83 85 if ( Tasks < BarrierSize ) -
tests/concurrency/channels/big_elems.cfa
ra2c2363 re3784a50 2 2 #include "parallel_harness.hfa" 3 3 4 s size_t Processors = 10, Channels = 10, Producers = 40, Consumers = 40, ChannelSize = 128;4 size_t Processors = 10, Channels = 10, Producers = 40, Consumers = 40, ChannelSize = 128; 5 5 6 6 int main() { -
tests/concurrency/channels/churn.cfa
ra2c2363 re3784a50 7 7 #include <time.hfa> 8 8 9 s size_t Processors = 1, Channels = 4, Producers = 2, Consumers = 2, ChannelSize = 128;9 size_t Processors = 1, Channels = 4, Producers = 2, Consumers = 2, ChannelSize = 128; 10 10 11 11 owner_lock o; … … 90 90 case 4: 91 91 if ( strcmp( argv[3], "d" ) != 0 ) { // default ? 92 ChannelSize = ato( argv[3] );93 if ( ChannelSize < 1 ) fallthru default;92 if ( atoi( argv[3] ) < 1 ) goto Usage; 93 ChannelSize = atoi( argv[3] ); 94 94 } // if 95 95 case 3: 96 96 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 97 Channels = ato( argv[2] );98 if ( Channels < 1 ) fallthru default;97 if ( atoi( argv[2] ) < 1 ) goto Usage; 98 Channels = atoi( argv[2] ); 99 99 } // if 100 100 case 2: 101 101 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 102 Processors = ato( argv[1] );103 if ( Processors < 1 ) fallthru default;102 if ( atoi( argv[1] ) < 1 ) goto Usage; 103 Processors = atoi( argv[1] ); 104 104 } // if 105 105 case 1: // use defaults 106 106 break; 107 107 default: 108 exit | "Usage: " | argv[0] 108 Usage: 109 sout | "Usage: " | argv[0] 109 110 | " [ processors > 0 | d ]" 110 111 | " [ producers > 0 | d ]" 111 112 | " [ consumers > 0 | d ]" 112 113 | " [ channels > 0 | d ]"; 114 exit( EXIT_FAILURE ); 113 115 } 114 116 processor p[Processors - 1]; -
tests/concurrency/channels/contend.cfa
ra2c2363 re3784a50 127 127 case 3: 128 128 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 129 ChannelSize = ato( argv[2] ); 130 if ( ChannelSize < 1 ) fallthru default; 129 ChannelSize = atoi( argv[2] ); 131 130 } // if 132 131 case 2: 133 132 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 134 Processors = ato ( argv[1] );135 if ( Processors < 1 ) fallthru default;133 Processors = atoi( argv[1] ); 134 if ( Processors < 1 ) goto Usage; 136 135 } // if 137 136 case 1: // use defaults 138 137 break; 139 138 default: 140 exit | "Usage: " | argv[0] 139 Usage: 140 sout | "Usage: " | argv[0] 141 141 | " [ processors (> 0) | 'd' (default " | Processors 142 142 | ") ] [ channel size (>= 0) | 'd' (default " | ChannelSize 143 143 | ") ]" ; 144 exit( EXIT_FAILURE ); 144 145 } // switch 145 146 146 test(Processors, Channels, Producers, Consumers, ChannelSize); 147 147 } -
tests/concurrency/channels/daisy_chain.cfa
ra2c2363 re3784a50 8 8 9 9 size_t total_operations = 0; 10 s size_t Processors = 1, Tasks = 4; // must be signed10 size_t Processors = 1, Tasks = 4; 11 11 12 12 owner_lock o; … … 37 37 case 3: 38 38 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 39 Tasks = ato ( argv[2] );40 if ( Tasks < 1 ) fallthru default;39 Tasks = atoi( argv[2] ); 40 if ( Tasks < 1 ) goto Usage; 41 41 } // if 42 42 case 2: 43 43 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 44 Processors = ato ( argv[1] );45 if ( Processors < 1 ) fallthru default;44 Processors = atoi( argv[1] ); 45 if ( Processors < 1 ) goto Usage; 46 46 } // if 47 47 case 1: // use defaults 48 48 break; 49 49 default: 50 exit | "Usage: " | argv[0] 50 Usage: 51 sout | "Usage: " | argv[0] 51 52 | " [ processors (> 0) | 'd' (default " | Processors 52 53 | ") ] [ channel size (>= 0) | 'd' (default " | Tasks 53 54 | ") ]" ; 55 exit( EXIT_FAILURE ); 54 56 } // switch 55 57 processor proc[Processors - 1]; … … 69 71 // sout | total_operations; 70 72 sout | "done"; 73 74 return 0; 71 75 } -
tests/concurrency/channels/hot_potato.cfa
ra2c2363 re3784a50 8 8 9 9 size_t total_operations = 0; 10 s size_t Processors = 1, Tasks = 4; // must be signed10 size_t Processors = 1, Tasks = 4; 11 11 12 12 owner_lock o; … … 38 38 } 39 39 40 40 41 int main( int argc, char * argv[] ) { 41 42 switch ( argc ) { 42 43 case 3: 43 44 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 44 Tasks = ato ( argv[2] );45 if ( Tasks < 1 ) fallthru default;45 Tasks = atoi( argv[2] ); 46 if ( Tasks < 1 ) goto Usage; 46 47 } // if 47 48 case 2: 48 49 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 49 Processors = ato ( argv[1] );50 if ( Processors < 1 ) fallthru default;50 Processors = atoi( argv[1] ); 51 if ( Processors < 1 ) goto Usage; 51 52 } // if 52 53 case 1: // use defaults 53 54 break; 54 55 default: 55 exit | "Usage: " | argv[0] 56 Usage: 57 sout | "Usage: " | argv[0] 56 58 | " [ processors (> 0) | 'd' (default " | Processors 57 59 | ") ] [ channel size (>= 0) | 'd' (default " | Tasks 58 60 | ") ]" ; 61 exit( EXIT_FAILURE ); 59 62 } // switch 60 61 63 processor proc[Processors - 1]; 62 64 -
tests/concurrency/channels/pub_sub.cfa
ra2c2363 re3784a50 87 87 case 3: 88 88 if ( strcmp( argv[2], "d" ) != 0 ) { // default ? 89 Tasks = ato ( argv[2] );90 if ( Tasks < 1 ) fallthru default;89 Tasks = atoi( argv[2] ); 90 if ( Tasks < 1 ) goto Usage; 91 91 } // if 92 92 case 2: 93 93 if ( strcmp( argv[1], "d" ) != 0 ) { // default ? 94 Processors = ato ( argv[1] );95 if ( Processors < 1 ) fallthru default;94 Processors = atoi( argv[1] ); 95 if ( Processors < 1 ) goto Usage; 96 96 } // if 97 97 case 1: // use defaults 98 98 break; 99 99 default: 100 exit | "Usage: " | argv[0] 100 Usage: 101 sout | "Usage: " | argv[0] 101 102 | " [ processors (> 0) | 'd' (default " | Processors 102 103 | ") ] [ Tasks (> 0) | 'd' (default " | Tasks 103 104 | ") ]" ; 105 exit( EXIT_FAILURE ); 104 106 } // switch 105 107 BarrierSize = Tasks; -
tests/concurrency/examples/matrixSum.cfa
ra2c2363 re3784a50 10 10 // Created On : Mon Oct 9 08:29:28 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 8 19:05:34 202313 // Update Count : 1 912 // Last Modified On : Wed Feb 20 08:37:53 2019 13 // Update Count : 16 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <kernel.hfa> 17 18 #include <thread.hfa> 18 19 … … 34 35 35 36 int main() { 36 constint rows = 10, cols = 1000;37 /* const */ int rows = 10, cols = 1000; 37 38 int matrix[rows][cols], subtotals[rows], total = 0; 38 39 processor p; // add kernel thread 39 40 40 for ( r; rows ) { // initialize41 for ( r; rows ) { 41 42 for ( c; cols ) { 42 43 matrix[r][c] = 1; 43 44 } // for 44 45 } // for 45 46 46 Adder * adders[rows]; 47 47 for ( r; rows ) { // start threads to sum rows 48 48 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] }; 49 // adders[r] = new( matrix[r], cols,subtotals[r] );49 // adders[r] = new( matrix[r], cols, &subtotals[r] ); 50 50 } // for 51 52 51 for ( r; rows ) { // wait for threads to finish 53 52 delete( adders[r] ); … … 58 57 59 58 // Local Variables: // 59 // tab-width: 4 // 60 60 // compile-command: "cfa matrixSum.cfa" // 61 61 // End: // -
tests/concurrency/unified_locking/locks.cfa
ra2c2363 re3784a50 1 1 #include <stdio.h> 2 #include <locks.hfa>2 #include "locks.hfa" 3 3 #include <stdlib.hfa> 4 4 #include <thread.hfa> -
tests/concurrency/unified_locking/pthread_locks.cfa
ra2c2363 re3784a50 1 1 #include <stdio.h> 2 #include <locks.hfa>2 #include "locks.hfa" 3 3 #include <stdlib.hfa> 4 4 #include <thread.hfa> -
tests/concurrency/unified_locking/test_debug.cfa
ra2c2363 re3784a50 1 #include <locks.hfa>1 #include "locks.hfa" 2 2 3 3 fast_block_lock f; -
tests/concurrency/unified_locking/thread_test.cfa
ra2c2363 re3784a50 1 1 #include <stdio.h> 2 #include <locks.hfa>2 #include "locks.hfa" 3 3 #include <stdlib.hfa> 4 4 #include <thread.hfa> -
tests/minmax.cfa
ra2c2363 re3784a50 45 45 sout | "double\t\t\t" | 4.0 | 3.1 | "\tmax" | max( 4.0, 3.1 ); 46 46 sout | "long double\t\t" | 4.0l | 3.1l | "\tmax" | max( 4.0l, 3.1l ); 47 48 sout | nl;49 50 sout | "3 arguments";51 sout | 2 | 3 | 4 | "\tmin" | min(2, 3, 4) | "\tmax" | max(2, 3, 4);52 sout | 4 | 2 | 3 | "\tmin" | min(4, 2, 3) | "\tmax" | max(4, 2, 3);53 sout | 3 | 4 | 2 | "\tmin" | min(3, 4, 2) | "\tmax" | max(3, 4, 2);54 55 sout | "4 arguments";56 sout | 3 | 2 | 5 | 4 | "\tmin" | min(3, 2, 5, 4) | "\tmax" | max(3, 2, 5, 4);57 sout | 5 | 3 | 4 | 2 | "\tmin" | min(5, 3, 4, 2) | "\tmax" | max(5, 3, 4, 2);58 47 } // main 59 48
Note:
See TracChangeset
for help on using the changeset viewer.