Changeset e26a842 for doc/theses
- Timestamp:
- Jul 8, 2024, 9:03:12 AM (5 months ago)
- Branches:
- master
- Children:
- 061b001
- Parents:
- 5a553e2
- Location:
- doc/theses/mike_brooks_MMath/programs
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/bkgd-carray-arrty.c
r5a553e2 re26a842 148 148 void stx2() { const T x[10]; 149 149 // x[5] = 3.14; // bad 150 150 } 151 151 void stx3() { T const x[10]; 152 152 // x[5] = 3.14; // bad 153 153 } 154 154 155 155 // Local Variables: // -
doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa
r5a553e2 re26a842 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: // -
doc/theses/mike_brooks_MMath/programs/hello-array.cfa
r5a553e2 re26a842 8 8 9 9 10 forall( [ N] ) // array bound11 array( bool, N) & f( array(float, N) & a, array(float, N) & b) {12 array( bool, N) & ret = *alloc(); // sizeof used by alloc13 for ( i; N) {14 ret[i] = 0.005 > 2 * (abs( a[i] - b[i])) / (abs(a[i]) + abs(b[i]));10 forall( [@N@] ) $\C{// array dimension}$ 11 array( bool, @N@) & f( array( float, @N@ ) & x, array( float, @N@ ) & y ) { 12 array( bool, @N@ ) & ret = *@alloc@(); $\C{// sizeof ret used by alloc}$ 13 for ( i; @N@ ) { 14 ret[i] = 0.005 > 2 * (abs( x[i] - y[i] )) / (abs( x[i]) + abs(y[i] )); 15 15 } 16 16 return ret; … … 29 29 30 30 int main( int argc, char * argv[] ) { 31 int n = ato( argv[1] );32 array( float, n) a, b; // VLA33 for ( i; n ) { 34 a[i] = 3.14 / (i + 1);35 b[i] = a[i] + 0.005 ;31 const int @n@ = ato( argv[1] ); $\C{// deduce conversion type}$ 32 array( float, @n@ ) x, y; $\C{// VLAs}$ 33 for ( i; n ) { $\C{// initialize arrays}$ 34 x[i] = 3.14 / (i + 1); 35 y[i] = x[i] + 0.005 ; 36 36 } 37 array( bool, n) & result = f( a, b ); // call38 sout | "result: " | nonl; 37 array( bool, @n@ ) & result = @f( x, y )@; $\C{// call}$ 38 sout | "result: " | nonl; $\C{// print result}$ 39 39 for ( i; n ) 40 40 sout | result[i] | nonl; 41 41 sout | nl; 42 free( &result ); // free returned storage42 free( &result ); $\C{// free result storage}$ 43 43 } 44 44 /* … … 50 50 51 51 void fred() { 52 array( float, 10) a;53 array( float, 20) b;54 f( a, a);55 f( b, b);56 f( a, b);52 array( float, @10@ ) x; 53 array( float, @20@ ) y; 54 f( x, x ); 55 f( y, y ); 56 // f( x, y ); 57 57 } 58 58 59 59 #ifdef SHOWERR1 60 60 forall( [M], [N] ) 61 void bad( array(float, M) & a, array(float, N) &b) {62 f( a, a ); // ok63 f( b, b ); // ok64 f( a, b ); // error61 void bad( array(float, M) &x, array(float, N) &y ) { 62 f( x, x ); $\C[1.5in]{// ok}$ 63 f( y, y ); $\C{// ok}$ 64 f( x, y ); $\C{// error}\CRT$ 65 65 } 66 66 #endif … … 69 69 70 70 forall( [M], [N] ) 71 void bad_fixed( array(float, M) & a, array(float, N) & b ) { 72 if ( M == N ) { 73 f( a, (array(float, M) &)b ); // cast b to matching type 74 } 71 void bad_fixed( array( float, M ) & x, array( float, N ) & y ) { 72 if ( M == N ) 73 f( x, @(array( float, M ) &)@y ); $\C{// cast y to matching type}$ 75 74 } 75 76 // Local Variables: // 77 // compile-command: "sed -f sedcmd hello-array.cfa > ../build/tmp.cfa; cfa ../build/tmp.cfa -Wall -Wextra" // 78 // End: // -
doc/theses/mike_brooks_MMath/programs/hello-md.cfa
r5a553e2 re26a842 39 39 40 40 forall( [N] ) 41 void print1d_cstyle( array( float, N) & c );41 void print1d_cstyle( array( float, N ) & r ); $\C{// C style}$ 42 42 43 forall( [N], C & | ar( C, float, N ) )43 forall( [N], C & @| ar( C, float, N )@ ) $\C{// add trait}$ 44 44 void print1d( C & c ); 45 45 … … 59 59 60 60 forall( [N] ) 61 void print1d_cstyle( array(float, N) & c ) { 62 for ( i; N ) { 63 sout | c[i] | nonl; 64 } 61 void print1d_cstyle( array( float, N ) & r ) { $\C{// C style}$ 62 for ( i; N ) sout | r[i] | nonl; 65 63 sout | nl; 66 64 } 65 66 67 67 68 68 … … 98 98 99 99 100 void fill( array( float, 5, 7) & a ) {100 void fill( array( float, 5, 7 ) & a ) { 101 101 for ( i; (ptrdiff_t) 5 ) { 102 102 for ( j; 7 ) { … … 116 116 117 117 118 array( float, 5, 7 ) a;119 fill( a);118 array( float, 5, 7 ) m; 119 fill( m ); 120 120 /* 121 0.0 0.1 0.2 0.3 0.4 0.5 0.6 122 1.0 1.1 1.2 1.3 1.4 1.5 1.6 123 2.0 2.1 2.2 2.3 2.4 2.5 2.6 124 3.0 3.1 3.2 3.3 3.4 3.5 3.6 125 4.0 4.1 4.2 4.3 4.4 4.5 4.6 121 r/c 0 1 2 3 4 5 6 122 0 0.0 0.1 0.2 @0.3@ 0.4 0.5 0.6 123 1 1.0 1.1 1.2 @1.3@ 1.4 1.5 1.6 124 2 @2.0 2.1 2.2 2.3 2.4 2.5 2.6@ 125 3 3.0 3.1 3.2 @3.3@ 3.4 3.5 3.6 126 4 4.0 4.1 4.2 @4.3@ 4.4 4.5 4.6 126 127 */ 127 128 … … 137 138 138 139 139 140 print1d_cstyle( a[ 2 ] ); // 2.0 2.1 2.2 2.3 2.4 2.5 2.6 140 print1d_cstyle( m[ 2 ] ); $\C{// row 2: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ 141 141 142 142 143 143 144 144 145 print1d( a[ 2 ] ); // 2.0 2.1 2.2 2.3 2.4 2.5 2.6145 print1d( m[ 2 ] ); $\C{// row: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ 146 146 147 147 148 148 149 149 150 print1d( a[ 2, all ] ); // 2.0 2.1 2.2 2.3 2.4 2.5 2.6151 print1d( a[ all, 3 ] ); // 0.3 1.3 2.3 3.3 4.3150 print1d( m[ 2, all ] ); $\C{// row 2: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ 151 print1d( m[ all, 3 ] ); $\C{// column 3: 0.3 1.3 2.3 3.3 4.3}$ 152 152 153 153 154 154 155 print1d_cstyle( a[ 2, all ] );155 print1d_cstyle( m[ 2, all ] ); 156 156 157 157 … … 163 163 #ifdef SHOW_ERROR_1 164 164 165 print1d_cstyle( a[ all, 2 ] ); // bad165 print1d_cstyle( m[ all, 2 ] ); $\C{// bad}$ 166 166 167 167 #endif -
doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction.hpp
r5a553e2 re26a842 101 101 class list { 102 102 struct node { 103 @LIST_ENTRY(node) links;@104 @El elem;@103 LIST_ENTRY(node) links; 104 El elem; 105 105 }; 106 106 LIST_HEAD(Impl, node); … … 111 111 } 112 112 void push_front( const El & src ) { 113 node * n = @new node()@;113 node * n = new node(); 114 114 n->elem = src; 115 115 LIST_INSERT_HEAD(&impl, n, links); -
doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-byref.run.cpp
r5a553e2 re26a842 49 49 for (auto const& cur : reqs) 50 50 printf("{%d %d} ", cur->pri, cur->rqr); 51 printf("\n");51 printf("\n"); 52 52 53 53 }
Note: See TracChangeset
for help on using the changeset viewer.