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 1db2c5be was
a0d9f94,
checked in by Peter A. Buhr <pabuhr@…>, 10 years ago
|
add compiler flag to driver, update examples, fix unnamed bit fields
|
-
Property mode set to
100644
|
File size:
796 bytes
|
Line | |
---|
1 | // "./cfa forall.c" |
---|
2 | |
---|
3 | typedef forall ( type T ) int (*f)( int ); |
---|
4 | |
---|
5 | forall( type T ) |
---|
6 | void swap( T left, T right ) { |
---|
7 | T temp = left; |
---|
8 | left = right; |
---|
9 | right = temp; |
---|
10 | } |
---|
11 | |
---|
12 | context sumable( type T ) { |
---|
13 | const T 0; |
---|
14 | T ?+?(T, T); |
---|
15 | T ?++(T*); |
---|
16 | [T] ?+=?(T*,T); |
---|
17 | }; |
---|
18 | |
---|
19 | forall( type T | sumable( T ) ) |
---|
20 | T sum( int n, T a[] ) { |
---|
21 | T total = 0; |
---|
22 | int i; |
---|
23 | for ( i = 0; i < n; i += 1 ) |
---|
24 | total = total + a[i]; |
---|
25 | return total; |
---|
26 | } |
---|
27 | |
---|
28 | forall( type T | { T ?+?(T, T); T ?++(T*); [T] ?+=?(T*,T); } ) |
---|
29 | T twice( T t ) { |
---|
30 | return t + t; |
---|
31 | } |
---|
32 | |
---|
33 | forall( type T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } ) |
---|
34 | T min( T t1, T t2 ) { |
---|
35 | return t1 < t2 ? t1 : t2; |
---|
36 | } |
---|
37 | |
---|
38 | int main() { |
---|
39 | int x = 1, y = 2, a[10]; |
---|
40 | float f; |
---|
41 | |
---|
42 | swap( x, y ); |
---|
43 | twice( x ); |
---|
44 | f = min( 4.0, 3.0 ); |
---|
45 | sum( 10, a ); |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.