ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 45576af9 was
b1d6dd5,
checked in by Peter A. Buhr <pabuhr@…>, 9 years ago
|
fix parsing error for EOF message, change cfa-ccp -x flag to -v, regression testing third attempt: consolidate example programs
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[8a95629] | 1 | int ?=?( int*, int ); |
---|
| 2 | float ?=?( float*, float ); |
---|
| 3 | int * ?=?( int **, int * ); |
---|
| 4 | float * ?=?( float **, float * ); |
---|
| 5 | char ?=?( char*, char ); |
---|
| 6 | void (* ?=?( void (**)(void), void (*)(void) ))(void); |
---|
| 7 | |
---|
| 8 | void g1() { |
---|
| 9 | forall( type T ) T f( T ); |
---|
| 10 | void f( int ); |
---|
| 11 | void h( void (*p)(void) ); |
---|
| 12 | |
---|
| 13 | int x; |
---|
| 14 | void (*y)(void); |
---|
| 15 | char z; |
---|
| 16 | float w; |
---|
| 17 | |
---|
| 18 | f( x ); |
---|
| 19 | f( y ); |
---|
| 20 | f( z ); |
---|
| 21 | f( w ); |
---|
| 22 | h( f( y ) ); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | void g2() { |
---|
| 26 | forall( type T ) void f( T, T ); |
---|
| 27 | forall( type T, type U ) void f( T, U ); |
---|
| 28 | |
---|
| 29 | int x; |
---|
| 30 | float y; |
---|
| 31 | int *z; |
---|
| 32 | float *w; |
---|
| 33 | |
---|
| 34 | f( x, y ); |
---|
| 35 | f( z, w ); |
---|
| 36 | f( x, z ); |
---|
| 37 | } |
---|
| 38 | |
---|
[51b7345] | 39 | typedef forall ( type T ) int (*f)( int ); |
---|
| 40 | |
---|
| 41 | forall( type T ) |
---|
[a65d92e] | 42 | void swap( T left, T right ) { |
---|
[51b7345] | 43 | T temp = left; |
---|
| 44 | left = right; |
---|
| 45 | right = temp; |
---|
[a65d92e] | 46 | } |
---|
[51b7345] | 47 | |
---|
| 48 | context sumable( type T ) { |
---|
[0b2961f] | 49 | const T 0; |
---|
| 50 | T ?+?(T, T); |
---|
| 51 | T ?++(T); |
---|
| 52 | [T] ?+=?(T,T); |
---|
[51b7345] | 53 | }; |
---|
| 54 | |
---|
| 55 | type T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); }, |
---|
[a65d92e] | 56 | T2(type P1, type P2 ), |
---|
| 57 | T3 | sumable(T3); |
---|
[51b7345] | 58 | |
---|
| 59 | type T2(type P1, type P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; }; |
---|
| 60 | |
---|
| 61 | T2(int, int) w1; |
---|
| 62 | typedef T2(int, int) w2; |
---|
| 63 | w2 g2; |
---|
| 64 | type w3 = T2(int, int); |
---|
| 65 | w3 g3; |
---|
| 66 | |
---|
| 67 | forall( type T | sumable( T ) ) |
---|
[a65d92e] | 68 | T sum( int n, T a[] ) { |
---|
[51b7345] | 69 | T total = 0; |
---|
| 70 | int i; |
---|
| 71 | for ( i = 0; i < n; i += 1 ) |
---|
[0b2961f] | 72 | total = total + a[i]; |
---|
[51b7345] | 73 | return total; |
---|
[a65d92e] | 74 | } |
---|
[51b7345] | 75 | |
---|
| 76 | forall( type T | { const T 0; T ?+?(T, T); T ?++(T); [T] ?+=?(T,T); } ) |
---|
[a65d92e] | 77 | T twice( T t ) { |
---|
[51b7345] | 78 | return t + t; |
---|
[a65d92e] | 79 | } |
---|
[51b7345] | 80 | |
---|
[0b2961f] | 81 | forall( type T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } ) |
---|
| 82 | T min( T t1, T t2 ) { |
---|
| 83 | return t1 < t2 ? t1 : t2; |
---|
| 84 | } |
---|
| 85 | |
---|
[51b7345] | 86 | int main() { |
---|
[0b2961f] | 87 | int x = 1, y = 2, a[10]; |
---|
| 88 | float f; |
---|
[51b7345] | 89 | |
---|
[0b2961f] | 90 | swap( x, y ); |
---|
| 91 | twice( x ); |
---|
| 92 | f = min( 4.0, 3.0 ); |
---|
| 93 | sum( 10, a ); |
---|
[51b7345] | 94 | } |
---|
[a65d92e] | 95 | |
---|
| 96 | // Local Variables: // |
---|
| 97 | // tab-width: 4 // |
---|
| 98 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.