source: src/Tests/SynTree/Forall.c @ 59db689

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 59db689 was a65d92e, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

regression testing, second attempt

  • Property mode set to 100644
File size: 962 bytes
Line 
1typedef forall ( type T ) int (*f)( int );
2
3forall( type T )
4void swap( T left, T right ) {
5        T temp = left;
6        left = right;
7        right = temp;
8}
9
10context sumable( type T ) {
11    const T 0;
12    T ?+?(T, T);
13    T ?++(T);
14    [T] ?+=?(T,T);
15};
16
17type T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
18        T2(type P1, type P2 ),
19        T3 | sumable(T3);
20
21type T2(type P1, type P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; };
22
23T2(int, int) w1;
24typedef T2(int, int) w2;
25w2 g2;
26type w3 = T2(int, int);
27w3 g3;
28
29forall( type T | sumable( T ) )
30T sum( int n, T a[] ) {
31        T total = 0;
32        int i;
33        for ( i = 0; i < n; i += 1 )
34            total = total + a[i];
35        return total;
36}
37
38forall( type T | { const T 0; T ?+?(T, T); T ?++(T); [T] ?+=?(T,T); } )
39T twice( T t ) {
40        return t + t;
41}
42
43int main() {
44    int x = 1, y = 2, a[10];
45    float f;
46
47    swap( x, y );
48    twice( x, y );
49    f = min( 4.0, 3.0 );
50    sum( 10, a );
51}
52
53// Local Variables: //
54// tab-width: 4 //
55// End: //
Note: See TracBrowser for help on using the repository browser.