source: src/tests/tupleFunction.c @ 33a7b6d

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 33a7b6d was 33a7b6d, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

changed use of formal types to actual types for boxing return parameters and passing type variables, fix bug where generic struct's members would change types when a member is accessed on a concrete instantiation

  • Property mode set to 100644
File size: 2.4 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// tupleFunction.c --
8//
9// Author           : Rob Schluntz
10// Created On       : Tue Nov 15 17:24:32 2016
11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Nov 15 17:27:28 2016
13// Update Count     : 3
14//
15
16struct S {
17        int f1, f2;
18        char f3;
19        double f4;
20} v;
21
22[int] foo( [int, int, double, S] x ) {
23        printf("foo([%d, %d, %lg, {%d, %d, %c, %lg}])\n", x.0, x.1, x.2, x.3.[f1, f2, f3, f4]);
24        int a, b;
25        double c;
26        S d;
27        [a, b, c, d] = x;
28        [int, int, double, S] X = x;
29        printf("a=%d b=%d c=%lg d={%d, %d, %c, %lg}\n", a, b, c, d.[f1, f2, f3, f4]);
30        printf("X=[%d, %d, %lg, {%d, %d, %c, %lg}]\n", X.0, X.1, X.2, X.3.[f1, f2, f3, f4]);
31        return b;
32}
33
34[void] bar( [int, double, int] z ) {
35        printf("bar([%d, %lg, %d])\n", z);
36}
37
38[void] baz( int a, double b, int c ) {
39        printf("baz(%d, %lg, %d)\n", a, b, c);
40}
41
42[void] qux( [int, double] n, int m ) {
43        printf("qux([%d, %lg], %d)\n", n, m);
44}
45
46[int, double x, int] quux() {
47        return [3, 5.254, 4];
48}
49[[[int, double, int], [int, double]]] quuux() {
50        return [1, 2, 3, 4, 5];
51}
52
53// forall(otype T | { T ?+?(T, T); })
54// [T, T, T] ?+?([T, T, T] x, [T, T, T] y) {
55//      T x1, x2, x3, y1, y2, y3;
56//      [x1, x2, x3] = x;
57//      [y1, y2, y3] = y;
58//      return [x1+y1, x2+y2, x3+y3];
59// }
60
61int main() {
62  [int, double, int] x = [777, 2.76, 8675];
63  int x1 = 123, x3 = 456;
64  double x2 = 999.123;
65
66  printf("foo(...)=%d\n", foo(x1, x3, x2, (S){ 321, 654, 'Q', 3.14 }));
67
68        // call function with tuple parameter using tuple variable arg
69        bar(x);
70
71        // call function with tuple parameter using multiple values
72        bar(x1, x2, x3);
73
74        // call function with multiple parameters using tuple variable arg
75        baz(x);
76
77        // call function with multiple parameters using multiple args
78        baz(x1, x2, x3);
79
80        // call function with multiple parameters, one of which is a tuple using tuple variable arg
81        qux(x);
82
83        // call function with multiple parameters, one of which is a tuple using multiple args
84        qux(x1, x2, x3);
85
86        // call function with multiple return values and assign into a tuple variable
87        x = quux();
88        printf("x=[%d, %lg, %d]\n", x);
89
90        // call function with multiple return values and assign into a tuple expression
91        [x1, x2, x3] = quux();
92        printf("x1=%d x2=%lg x3=%d\n", x1, x2, x3);
93}
94
95// Local Variables: //
96// tab-width: 4 //
97// End: //
98
Note: See TracBrowser for help on using the repository browser.