- Timestamp:
- Jul 10, 2024, 3:39:37 AM (21 months ago)
- Branches:
- master, stuck-waitfor-destruct
- Children:
- 725f777f
- Parents:
- bb336a6 (diff), f3811df (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa
rbb336a6 rdbff8ec 2 2 #include <stdlib.hfa> 3 3 #include <array.hfa> 4 #include <locale.h> // setlocale 4 5 5 6 … … 7 8 8 9 9 10 11 forall( T, [Nclients], [Ncosts] ) 12 struct request { 13 unsigned int requestor_id; 14 array( T, Nclients ) impacted_client_ids; // nested VLA 15 array( float, Ncosts ) cost_contribs; // nested VLA 16 float total_cost; 10 forall( T, @[NprovTerty]@, @[Nmunicipalities]@ ) 11 struct CanadaPop { 12 array( T, @NprovTerty@ ) provTerty; $\C{// nested VLA}$ 13 array( T, @Nmunicipalities@ ) municipalities; $\C{// nested VLA}$ 14 int total_pt, total_mun; 17 15 }; 18 16 … … 20 18 // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?) 21 19 22 forall( T, [N clients], [Ncosts] )23 void ?{}( T &, request( T, Nclients, Ncosts ) & this ) {}20 forall( T, [NprovTerty], [Nmunicipalities] ) 21 void ?{}( T &, CanadaPop( T, NprovTerty, Nmunicipalities ) & this ) {} 24 22 25 forall( T &, [N clients], [Ncosts] )26 void ^?{}( request( T, Nclients, Ncosts ) & this ) {}23 forall( T &, [NprovTerty], [Nmunicipalities] ) 24 void ^?{}( CanadaPop( T, NprovTerty, Nmunicipalities ) & this ) {} 27 25 28 26 … … 39 37 40 38 41 forall( T, [Nclients], [Ncosts] ) 42 void summarize( request( T, Nclients, Ncosts ) & r ) { 43 r.total_cost = 0; 44 for( i; Ncosts ) 45 r.total_cost += r.cost_contribs[i]; 46 // say the cost is per-client, to make output vary 47 r.total_cost *= Nclients; 39 40 forall( T, [NprovTerty], [Nmunicipalities] ) 41 void check( CanadaPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) { 42 total_pt = total_mun = 0; 43 for ( i; NprovTerty ) total_pt += provTerty[i]; 44 for ( i; Nmunicipalities ) total_mun += municipalities[i]; 48 45 } 49 46 … … 59 56 60 57 58 59 61 60 int main( int argc, char * argv[] ) { 62 const int ncl = ato( argv[1] ); 63 const int nco = 2; 64 65 request( int, ncl, nco ) r; 66 r.cost_contribs[0] = 100; 67 r.cost_contribs[1] = 0.1; 68 69 summarize(r); 70 sout | "Total cost:" | r.total_cost; 61 const int npt = ato( argv[1] ), nmun = ato( argv[2] ); 62 @CanadaPop( int, npt, nmun ) pop;@ 63 // read in population numbers 64 @check( pop );@ 65 sout | setlocale( LC_NUMERIC, getenv( "LANG" ) ); 66 sout | "Total province/territory:" | pop.total_pt; 67 sout | "Total municipalities:" | pop.total_mun; 71 68 } 72 69 /* 73 $\$$ ./a.out 5 74 Total cost: 500.5 75 $\$$ ./a.out 6 76 Total cost: 600.6 70 $\$$ ./a.out 13 3573 71 Total province/territory: 36,991,981 72 Total municipalities: 36,991,981 77 73 */ 74 75 // Local Variables: // 76 // compile-command: "sed -f sedcmd hello-accordion.cfa > ../build/tmp.cfa; cfa ../build/tmp.cfa -Wall -Wextra" // 77 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.