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 a32b204 was
51b7345,
checked in by Peter A. Buhr <pabuhr@…>, 10 years ago
|
initial commit
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | typedef forall ( type T ) int (*f)( int ); |
---|
2 | |
---|
3 | forall( type T ) |
---|
4 | void swap( T left, T right ) { |
---|
5 | T temp = left; |
---|
6 | left = right; |
---|
7 | right = temp; |
---|
8 | } |
---|
9 | |
---|
10 | context sumable( type T ) { |
---|
11 | const T 0; |
---|
12 | T ?+?(T, T); |
---|
13 | T ?++(T*); |
---|
14 | [T] ?+=?(T*,T); |
---|
15 | }; |
---|
16 | |
---|
17 | type T1 | { const T1 0; T1 ?+?(T1, T1); T1 ?++(T1); [T1] ?+=?(T1,T1); }, |
---|
18 | T2(type P1, type P2 ) | (type Q, type W){ const Q 0; W ?+?(W, W); Q ?++(W); [Q] ?+=?(W,W); }(T1,T2(T1,f)), |
---|
19 | T3 | sumable(T3); |
---|
20 | |
---|
21 | type T2(type P1, type P2) | sumable(T2(P1,P2)) = struct { P1 i; P2 j; }; |
---|
22 | |
---|
23 | T2(int, int) w1; |
---|
24 | typedef T2(int, int) w2; |
---|
25 | w2 g2; |
---|
26 | type w3 = T2(int, int); |
---|
27 | w3 g3; |
---|
28 | |
---|
29 | forall( type T | sumable( T ) ) |
---|
30 | T 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 | |
---|
38 | forall( type T | { T ?+?(T, T); T ?++(T*); [T] ?+=?(T*,T); } ) |
---|
39 | T twice( T t ) { |
---|
40 | return t + t; |
---|
41 | } |
---|
42 | |
---|
43 | forall( type T | { const T 0; int ?!=?(T, T); int ?<?(T, T); } ) |
---|
44 | T min( T t1, T t2 ) { |
---|
45 | return t1 < t2 ? t1 : t2; |
---|
46 | } |
---|
47 | |
---|
48 | int main() { |
---|
49 | int x = 1, y = 2, a[10]; |
---|
50 | float f; |
---|
51 | |
---|
52 | swap( x, y ); |
---|
53 | twice( x ); |
---|
54 | f = min( 4.0, 3.0 ); |
---|
55 | sum( 10, a ); |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.