Ignore:
Timestamp:
Jul 10, 2024, 3:39:37 AM (21 months ago)
Author:
JiadaL <j82liang@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa

    rbb336a6 rdbff8ec  
    22#include <stdlib.hfa>
    33#include <array.hfa>
     4#include <locale.h>                                                     // setlocale
    45
    56
     
    78
    89
    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;
     10forall( T, @[NprovTerty]@, @[Nmunicipalities]@ )
     11struct CanadaPop {
     12        array( T, @NprovTerty@ ) provTerty; $\C{// nested VLA}$
     13        array( T, @Nmunicipalities@ ) municipalities; $\C{// nested VLA}$
     14        int total_pt, total_mun;
    1715};
    1816
     
    2018// TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?)
    2119
    22 forall( T, [Nclients], [Ncosts] )
    23         void ?{}( T &, request( T, Nclients, Ncosts ) & this ) {}
     20forall( T, [NprovTerty], [Nmunicipalities] )
     21        void ?{}( T &, CanadaPop( T, NprovTerty, Nmunicipalities ) & this ) {}
    2422
    25 forall( T &, [Nclients], [Ncosts] )
    26         void ^?{}( request( T, Nclients, Ncosts ) & this ) {}
     23forall( T &, [NprovTerty], [Nmunicipalities] )
     24        void ^?{}( CanadaPop( T, NprovTerty, Nmunicipalities ) & this ) {}
    2725
    2826
     
    3937
    4038
    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
     40forall( T, [NprovTerty], [Nmunicipalities] )
     41void 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];
    4845}
    4946
     
    5956
    6057
     58
     59
    6160int 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;
    7168}
    7269/*
    73 $\$$ ./a.out 5
    74 Total cost: 500.5
    75 $\$$ ./a.out 6
    76 Total cost: 600.6
     70$\$$ ./a.out  13  3573
     71Total province/territory: 36,991,981
     72Total municipalities: 36,991,981
    7773*/
     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.