source: src/tests/forall.c@ b1e63ac5

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since b1e63ac5 was e757af2, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

renamed all tests to lower-case leading character

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[8a95629]1int ?=?( int*, int );
2float ?=?( float*, float );
3int * ?=?( int **, int * );
4float * ?=?( float **, float * );
5char ?=?( char*, char );
6void (* ?=?( void (**)(void), void (*)(void) ))(void);
7
8void g1() {
[55ba7339]9 forall( otype T ) T f( T );
[8a95629]10 void f( int );
11 void h( void (*p)(void) );
[e5b96bf]12
[8a95629]13 int x;
14 void (*y)(void);
15 char z;
16 float w;
[e5b96bf]17
[8a95629]18 f( x );
19 f( y );
20 f( z );
21 f( w );
22 h( f( y ) );
23}
24
25void g2() {
[55ba7339]26 forall( otype T ) void f( T, T );
27 forall( otype T, otype U ) void f( T, U );
[e5b96bf]28
[8a95629]29 int x;
30 float y;
31 int *z;
32 float *w;
[e5b96bf]33
[8a95629]34 f( x, y );
35 f( z, w );
36 f( x, z );
37}
38
[55ba7339]39typedef forall ( otype T ) int (*f)( int );
[51b73452]40
[55ba7339]41forall( otype T )
[a65d92e]42void swap( T left, T right ) {
[51b73452]43 T temp = left;
44 left = right;
45 right = temp;
[a65d92e]46}
[51b73452]47
[e5b96bf]48trait sumable( otype T ) {
[0b2961f]49 const T 0;
50 T ?+?(T, T);
51 T ?++(T);
52 [T] ?+=?(T,T);
[51b73452]53};
54
[55ba7339]55otype T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
56 T2(otype P1, otype P2 ),
[a65d92e]57 T3 | sumable(T3);
[51b73452]58
[55ba7339]59otype T2(otype P1, otype P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; };
[51b73452]60
61T2(int, int) w1;
62typedef T2(int, int) w2;
63w2 g2;
[55ba7339]64otype w3 = T2(int, int);
[51b73452]65w3 g3;
66
[55ba7339]67forall( otype T | sumable( T ) )
[a65d92e]68T sum( int n, T a[] ) {
[51b73452]69 T total = 0;
70 int i;
71 for ( i = 0; i < n; i += 1 )
[0b2961f]72 total = total + a[i];
[51b73452]73 return total;
[a65d92e]74}
[51b73452]75
[55ba7339]76forall( otype T | { const T 0; T ?+?(T, T); T ?++(T); [T] ?+=?(T,T); } )
[a65d92e]77T twice( T t ) {
[51b73452]78 return t + t;
[a65d92e]79}
[51b73452]80
[55ba7339]81forall( otype T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } )
[0b2961f]82T min( T t1, T t2 ) {
83 return t1 < t2 ? t1 : t2;
84}
85
[51b73452]86int main() {
[0b2961f]87 int x = 1, y = 2, a[10];
88 float f;
[51b73452]89
[0b2961f]90 swap( x, y );
91 twice( x );
92 f = min( 4.0, 3.0 );
93 sum( 10, a );
[51b73452]94}
[a65d92e]95
96// Local Variables: //
97// tab-width: 4 //
98// End: //
Note: See TracBrowser for help on using the repository browser.