source: translator/Tests/Syntax/Tuple.c @ 51b7345

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 51b7345 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

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