source: src/tests/tupleAssign.c @ 4a3334cf

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4a3334cf was 7fe2498, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

add sout prints and adjust char print values

  • 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 : Mon Mar  6 21:23:58 2017
13// Update Count     : 34
14//
15
16#include <fstream>
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 | "]" | endl;
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 | "]" | endl;
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 | "]" | endl;
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 | "]" | endl;
41        }
42        {
43                // test mass assignment
44                double d = 0.0;
45                int i = 0;
46                char c = '\0';
47                struct X {
48                        int z;
49                } x;
50                X ?=?(X * x, double d) {}
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=" | c | ' ' | "t=[" | t | "]" | endl;
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=" | c | ' ' | "t=[" | t | "]" | endl;
61        }
62}
63
64// Local Variables: //
65// tab-width: 4 //
66// End: //
Note: See TracBrowser for help on using the repository browser.