source: tests/forall.cfa @ 954821df

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 954821df was 0c81320, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add one_t constructor to prelude, remove one_t constructor from test programs

  • Property mode set to 100644
File size: 4.1 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// forall.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed May  9 08:48:15 2018
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Mar 19 08:29:38 2019
13// Update Count     : 32
14//
15
16void g1() {
17        forall( otype T ) T f( T ) {};
18        void f( int ) {};
19        void h( void (*p)(void) ) {};
20
21        int x;
22        void (*y)(void);
23        char z;
24        float w;
25
26        f( x );
27        f( y );
28        f( z );
29        f( w );
30        h( f( y ) );
31}
32
33void g2() {
34        forall( otype T ) void f( T, T ) {}
35        forall( otype T, otype U ) void f( T, U ) {}
36
37        int x;
38        float y;
39        int *z;
40        float *w;
41
42        f( x, y );
43        f( z, w );
44        f( x, z );
45}
46
47typedef forall ( otype T ) int (* f)( int );
48
49forall( otype T )
50void swap( T left, T right ) {
51        T temp = left;
52        left = right;
53        right = temp;
54}
55
56trait sumable( otype T ) {
57        void ?{}( T &, zero_t );                                                        // 0 literal constructor
58        T ?+?( T, T );                                                                          // assortment of additions
59        T ?+=?( T &, T );
60        T ++?( T & );
61        T ?++( T & );
62}; // sumable
63
64forall( otype T | sumable( T ) )                                                // use trait
65T sum( size_t size, T a[] ) {
66        T total = 0;                                                                            // initialize by 0 constructor
67        for ( size_t i = 0; i < size; i += 1 )
68                total = total + a[i];                                                   // select appropriate +
69        return total;
70} // sum
71
72forall( otype T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
73T twice( T t ) {
74        return t + t;
75}
76
77forall( otype T | { int ?<?(T, T); } )
78T min( T t1, T t2 ) {
79        return t1 < t2 ? t1 : t2;
80}
81
82int fred() {
83        int x = 1, y = 2, a[10];
84        float f;
85
86        swap( x, y );
87        twice( x );
88        f = min( 4.0, 3.0 );
89        sum( 10, a );
90}
91
92// Multiple forall
93forall( otype T ) forall( otype S ) struct { int i; };
94forall( otype T ) struct { int i; } forall( otype S );
95struct { int i; } forall( otype T ) forall( otype S );
96forall( otype W ) struct { int i; } forall( otype T ) forall( otype S );
97
98// Distribution
99struct P { int i; };
100forall( otype T ) struct Q { T i; };
101forall( otype T ) struct { int i; };
102struct KK { int i; };
103inline static {
104        void RT1() {}
105}
106forall( otype T ) {
107        T RT2( T ) {
108                typedef int TD1;
109                struct S1 { T t; };
110        }
111        forall( otype X ) {
112                typedef int TD2;
113                struct S2 {};
114                X RT2( T, X ) {
115                        int TD2;
116                }
117        }
118        extern "C" {
119                forall( otype W ) {
120                        W RT3( W ) {}
121                        struct S3 {};
122                }
123        }
124        void RT4() {
125                forall( otype W ) struct S4 {};
126                typedef int TD3;
127        }
128        static {
129                struct S5 {};
130                void RT5( T ) {
131                        struct S6 {};
132                        int TD2;
133                }
134        }
135        struct S7 {};
136        typedef int TD4;
137}
138TD2 t2;
139TD4 t4;
140struct Q( int ) t;
141struct S2( int, int ) t;
142struct S5( int ) t;
143struct S7( int ) t;
144
145int i = RT2( 3 );
146double j = RT2( 3, 4.5 );
147
148static inline {
149        forall( otype T ) {
150                int RT6( T p );
151        }
152        forall( otype T, otype U ) {
153                int RT7( T, U );
154        }
155}
156static forall( otype T ) {
157        int RT8( T );
158}
159forall( otype T ) inline static {
160        int RT9( T ) { T t; }
161}
162
163forall( otype T | { T ?+?( T, T ); } ) {
164        forall( otype S | { T ?+?( T, S ); } ) {
165                forall( otype W ) T bar( T t, S s ) { return t + s; }
166                forall( otype W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
167                struct W { T t; } (int,int) ww;
168                struct P pp;
169        }
170}
171
172forall( otype T | { T ?+?( T, T ); } ) forall( otype S | { T ?+?( T, S ); } )
173struct XW { T t; };
174XW(int,int) xww;
175
176forall( otype T ) struct S { T t; } (int) x, y, z;
177forall( otype T ) struct { T t; } (int) a, b, c;
178
179forall( otype T ) static forall( otype S ) {
180    forall( otype X ) struct U {
181                T x;
182    };
183}
184
185forall( otype T ) {
186        extern "C" {
187                struct SS { T t; };
188                T foo( T ) {}
189        }
190}
191
192SS(int) s;
193W(int,int) w;
194
195int jane() {
196//      int j = bar( 3, 4 );
197        int k = baz( 3, 4, 5 );
198        int i = foo( 3 );
199}
200
201//otype T1 | { void xxx( T1 ); };
202
203// otype T1 | { void ?{}( T1 &, zero_t ); T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); },
204//      T2(otype P1, otype P2 ),
205//      T3 | sumable(T3);
206
207//otype T2(otype P1, otype P2) | sumable( T2( P1,P2 ) ) = struct { P1 i; P2 j; };
208
209// T2(int, int) w1;
210// typedef T2(int, int) w2;
211// w2 g2;
212// otype w3 = T2(int, int);
213// w3 g3;
214
215int main( void ) {}
216
217// Local Variables: //
218// tab-width: 4 //
219// compile-command: "cfa forall.cfa" //
220// End: //
Note: See TracBrowser for help on using the repository browser.