source: examples/Tuple.c @ 7cd8827

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 7cd8827 was 7cd8827, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

Merge branch 'master' of plg2:software/cfa/cfa-cc

  • Property mode set to 100644
File size: 1.6 KB
Line 
1int f( int, int );
2int g( int, int, int );
3static
4[ int, int *, * int, int ] h( int a, int b, * int c, [] char d );
5
6struct inner {
7        int f2, f3;
8};
9
10struct outer {
11        int f1;
12        struct inner i;
13        double f4;
14} s, *sp;
15
16const volatile [ int, int ] t1;
17static const [ int, int ] t2;
18const static [ int, const int ] t3;
19
20[ int rc ] printf( * char fmt, ... );
21int printf( char *fmt, ... );
22
23[ short x, unsigned y ] f1( int w ) {
24//      return [ y, x ] = [ x, y ] = [ w, 23 ];
25}
26
27[ [ int, char, long, int ] r ] g1() {
28        short int x, p;
29        unsigned int y;
30        [ int, int ] z;
31
32        [ x, y, z ] = [ p, f( 17, 18 ), 4, 3 ];
33//      [ x, y, z ] = ([short, unsigned int, [int, int]])([ p, f( 17, 18 ), 4, 3 ]);
34        r = [ x, y, z ];
35}
36
37[ int rc ] main( int argc, ** char argv ) {
38        int a, b, c, d;
39//      struct outer t = { .[ f1, f4 ] : [ 1, 7.0 ] };
40        f( [ 3,5 ] );
41        g( [ 3,5 ], 3 );
42        f( t1 );
43        g( t1, 3 );
44
45//      [ , , , ];                                              /* empty tuple */
46        [ 3, 5 ];
47        [ a, b ] = 3;
48//      [ a, b ] = [ 4.6 ];
49        [ a, b ] = 4.6;
50        [ a, b ] = [ c, d ] = [ 3, 5 ];
51//      [ a, b, [ c ] ] = [ 2, [ a, b ] ];
52        [ a, b, c ] = [ 2, [ a, b ] ];
53        [ a, b ] = 3 > 4 ? [ b, 6 ] : [ 7, 8 ];
54
55        t1 = [ a, b ];
56        t1 = t2 = [ a, b ];
57        [ a, b ] = [ c, d ] = d += c += 1;
58        [ a, b ] = [ c, d ] = t1;
59        [ a, b ] = t1 = [ c, d ];
60        [ a, b ] = t1 = t2 = [ c, d ];
61//      t1 = [ 3, 4 ] = [ 3, 4 ] = t1 = [ 3, 4 ];
62
63        s.[ f1, i.[ f2, f3 ], f4 ] = [ 11, 12, 13, 3.14159 ];
64//      s.[ f1, i.[ f2, f3 ], f4 ] = h( 3, 3, (* int)0, "abc" );
65//      [ a, , b, ] = h( 3, 3, 0, "abc" );                      /* ignore some results */
66        sp->[ f4, f1 ] = sp->[ f1, f4 ];
67        printf( "expecting 3, 17, 23, 4; got %d, %d, %d, %d\n", s.[ f4, i.[ f3, f2 ], f1 ] );
68        rc = 0;
69}
70
71// Local Variables: //
72// tab-width: 4 //
73// End: //
Note: See TracBrowser for help on using the repository browser.