source: examples/Tuple.c@ 6f096d2

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 6f096d2 was 7cd8827, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

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

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