source: src/tests/tupleFunction.c@ 262f085f

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 262f085f was d9fa60a, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

moved substituion into MemberExpr constructor, change generated tuple structs to generic structs, tuples containing type variables almost works

  • Property mode set to 100644
File size: 2.6 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
53int main() {
54 [int, double, int] x = [777, 2.76, 8675];
55 int x1 = 123, x3 = 456;
56 double x2 = 999.123;
57
58 printf("foo(...)=%d\n", foo(x1, x3, x2, (S){ 321, 654, 'Q', 3.14 }));
59
60 // call function with tuple parameter using tuple variable arg
61 bar(x);
62
63 // call function with tuple parameter using multiple values
64 bar(x1, x2, x3);
65
66 // call function with multiple parameters using tuple variable arg
67 baz(x);
68
69 // call function with multiple parameters using multiple args
70 baz(x1, x2, x3);
71
72 // call function with multiple parameters, one of which is a tuple using tuple variable arg
73 qux(x);
74
75 // call function with multiple parameters, one of which is a tuple using multiple args
76 qux(x1, x2, x3);
77
78 // call function with multiple return values and assign into a tuple variable
79 x = quux();
80 printf("x=[%d, %lg, %d]\n", x);
81
82 // call function with multiple return values and assign into a tuple expression
83 [x1, x2, x3] = quux();
84 printf("x1=%d x2=%lg x3=%d\n", x1, x2, x3);
85
86 // xxx - tuples of type parameters should come out as generic types?
87 // [x1, x2, x3] = ([(int)x1, (int)x2, (int)x3]) + ([(int)1, (int)2, (int)3]);
88 // ([(int)x1, (int)x2, (int)x3]) + ([(int)1, (int)2, (int)3]);
89 // printf("%d %g %d\n", x1, x2, x3);
90
91 // xxx - comes out the back as a cast, but should come out as a tuple expression of the first n fields cast to each of the result types
92 // ([int, double])x;
93}
94
95// Local Variables: //
96// tab-width: 4 //
97// End: //
98
Note: See TracBrowser for help on using the repository browser.