source: src/tests/tupleFunction.c @ 6a1bdfd

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 6a1bdfd was a29be37, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

add a few test cases for tuples

  • Property mode set to 100644
File size: 1.9 KB
Line 
1struct S {
2        int f1, f2;
3        char f3;
4        double f4;
5} v;
6
7[int] foo( [int, int, double, S] x ) {
8        printf("foo([%d, %d, %lg, {%d, %d, %c, %lg}])\n", x.0, x.1, x.2, x.3.[f1, f2, f3, f4]);
9        int a, b;
10        double c;
11        S d;
12        [a, b, c, d] = x;
13        [int, int, double, S] X = x;
14        printf("a=%d b=%d c=%lg d={%d, %d, %c, %lg}\n", a, b, c, d.[f1, f2, f3, f4]);
15        printf("X=[%d, %d, %lg, {%d, %d, %c, %lg}]\n", X.0, X.1, X.2, X.3.[f1, f2, f3, f4]);
16        return b;
17}
18
19[void] bar( [int, double, int] z ) {
20        printf("bar([%d, %lg, %d])\n", z);
21}
22
23[void] baz( int a, double b, int c ) {
24        printf("baz(%d, %lg, %d)\n", a, b, c);
25}
26
27[void] qux( [int, double] n, int m ) {
28        printf("qux([%d, %lg], %d)\n", n, m);
29}
30
31[int, double x, int] quux() {
32        return [3, 5.254, 4];
33}
34[[[int, double, int], [int, double]]] quuux() {
35        return [1, 2, 3, 4, 5];
36}
37
38// forall(otype T | { T ?+?(T, T); })
39// [T, T, T] ?+?([T, T, T] x, [T, T, T] y) {
40//      T x1, x2, x3, y1, y2, y3;
41//      [x1, x2, x3] = x;
42//      [y1, y2, y3] = y;
43//      return [x1+y1, x2+y2, x3+y3];
44// }
45
46int main() {
47  [int, double, int] x = [777, 2.76, 8675];
48  int x1 = 123, x3 = 456;
49  double x2 = 999.123;
50
51  printf("foo(...)=%d\n", foo(x1, x3, x2, (S){ 321, 654, 'Q', 3.14 }));
52
53        // call function with tuple parameter using tuple variable arg
54        bar(x);
55
56        // call function with tuple parameter using multiple values
57        bar(x1, x2, x3);
58
59        // call function with multiple parameters using tuple variable arg
60        baz(x);
61
62        // call function with multiple parameters using multiple args
63        baz(x1, x2, x3);
64
65        // call function with multiple parameters, one of which is a tuple using tuple variable arg
66        qux(x);
67
68        // call function with multiple parameters, one of which is a tuple using multiple args
69        qux(x1, x2, x3);
70
71        // call function with multiple return values and assign into a tuple variable
72        x = quux();
73        printf("x=[%d, %lg, %d]\n", x);
74
75        // call function with multiple return values and assign into a tuple expression
76        [x1, x2, x3] = quux();
77        printf("x1=%d x2=%lg x3=%d\n", x1, x2, x3);
78}
Note: See TracBrowser for help on using the repository browser.