source: tests/tuple/tupleAssign.cfa @ a25bcf8

ADTast-experimental
Last change on this file since a25bcf8 was 57ccff1, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Missed printing change

  • Property mode set to 100644
File size: 2.0 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// tupleAssign.c --
8//
9// Author           : Rob Schluntz
10// Created On       : Tue Nov 15 17:24:32 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Dec  4 22:03:48 2018
13// Update Count     : 35
14//
15
16#include <fstream.hfa>
17
18int main() {
19        {
20                // test multiple assignment and cascading assignment
21                int u = 5, v = 6, x = 10, y = 11;
22                [int, int] z = [100, 200];
23
24                // swap x, y and store the new [x, y] in [u, v] and in z;
25                printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z );
26                sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]";
27                z = [u, v] = [x, y] = [y, x];
28                printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z );
29                sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]";
30
31                // shuffle elements -- v = z.0, z.0 = z.1, z.1 = u, u = v
32                [v, z, u] = [z, u, v];
33                printf( "u=%d v=%d z=[%d, %d]\n", u, v, z );
34                sout | "u=" | u | "v=" | v | "z=[" | z | "]";
35
36                // multiple assignment with tuple expression on right
37                z = [111, 222];
38                [u, v] = [123, 456];
39                printf( "u=%d v=%d z=[%d, %d]\n", u, v, z );
40                sout | "u=" | u | "v=" | v | "z=[" | z | "]";
41        }
42        {
43                // test mass assignment
44                double d = 0.0;
45                int i = 0;
46                signed char c = '\0';
47                struct X {
48                        int z;
49                } x;
50                X ?=?(X & x, double d) { return x; }
51                [int, double, int] t;
52
53                // no conversion from X to integral types, so this serves as a santiy
54                // check that as long as this compiles, ?=?(_, x) is not generated.
55                [t, x, d, i, c, x] = (double)94.12;
56                printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, (int)c, t );
57                sout | "d=" | d | "i=" | i | "c=" | (char)c | ' ' | "t=[" | t | "]";
58                [x, c, i, d, x, t] = (double)-94.12;
59                printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, c, t );
60                sout | "d=" | d | "i=" | i | "c=" | (char)c | ' ' | "t=[" | t | "]";
61        }
62}
63
64// Local Variables: //
65// tab-width: 4 //
66// End: //
Note: See TracBrowser for help on using the repository browser.