source: tests/tuple/tupleVariadic.cfa @ 474d610

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 474d610 was fd54fef, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[da6dec23]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// tuplePolymorphism.c --
8//
9// Author           : Rob Schluntz
10// Created On       : Fri Dec 16 10:25:35 2016
[b3763ca]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Aug  2 09:24:04 2018
13// Update Count     : 6
[da6dec23]14//
15
[fc846ae]16#include <stdlib.hfa>
[b3763ca]17
[1e3d5b6]18void func(void) {
19        printf("called func(void)\n");
20}
[fd54fef]21forall(T, Params... | { void process(T); void func(Params); })
[1e3d5b6]22void func(T arg1, Params p) {
23        process(arg1);
24        func(p);
25}
26void process(int x) {
27        printf("called process(int) %d\n", x);
28}
29void process(double x) {
30        printf("called process(double) %g\n", x);
31}
32
[da6dec23]33struct array {
34        int * data;
35        int size;
36};
37
38// xxx - eventually this will be collapsed...x
[2afec66]39void ?{}(array & a) {
40        a.size = 0;
41        a.data = 0;
[da6dec23]42        printf("called ?{} with no a\n");
43}
44
[2afec66]45void ?{}(array & a, int a0) {
46        a.size = 1;
47        a.data = (int*)malloc(sizeof(int)*a.size);
48        a.data[0] = a0;
[da6dec23]49        printf("called ?{} with a: %d\n", a0);
50}
51
[2afec66]52void ?{}(array & a, int a0, int a1) {
53        a.size = 2;
54        a.data = (int*)malloc(sizeof(int)*a.size);
55        a.data[0] = a0;
56        a.data[1] = a1;
[da6dec23]57        printf("called ?{} with a: %d %d\n", a0, a1);
58}
59
[2afec66]60void ?{}(array & a, int a0, int a1, int a2) {
61        a.size = 3;
62        a.data = (int*)malloc(sizeof(int)*a.size);
63        a.data[0] = a0;
64        a.data[1] = a1;
65        a.data[2] = a2;
[da6dec23]66        printf("called ?{} with a: %d %d %d\n", a0, a1, a2);
67}
68
[b3763ca]69void ^?{}(array & a) {
70        free(a.data);
71}
72
[64eae56]73// test use of a tuple argument
[2afec66]74[void] ?{}(array & a, [int, int, int, int] args) {
[64eae56]75        int a0, a1, a2, a3;
76        [a0, a1, a2, a3] = args;
[2afec66]77        a.size = 4;
[cdbfab0]78        a.data = (int *)malloc(sizeof(int)*a.size);
[2afec66]79        a.data[0] = a0;
80        a.data[1] = a1;
81        a.data[2] = a2;
82        a.data[3] = a3;
[da6dec23]83        printf("called ?{} with a: %d %d %d %d\n", a0, a1, a2, a3);
84}
85
86void print(array * x) {
87        printf("array = { ");
88        for (int i = 0; i < x->size; ++i) {
89                printf("%d, ", x->data[i]);
90        }
91        printf("}\n");
92}
93
[fd54fef]94forall(T)
[dd0c97b]95T * copy(T x) {
96        // test calling new inside a polymorphic function
97        return new(x);
98}
99
[fd54fef]100forall(T... | { void foo(T); }) void bar(T x) {}
[1dcd52a3]101void foo(int) {}
102
[da6dec23]103int main() {
[0c286cf]104        array * x0 = new();
105        print(x0);
[da6dec23]106
[0c286cf]107        array * x1 = new(999);
108        print(x1);
[da6dec23]109
110        array * x2 = new(123, 456);
111        print(x2);
112
113        array * x3 = new(100, 200, 300);
114        print(x3);
115
116        array * x4 = new(10, 2, 3, 4);
117        print(x4);
[dd0c97b]118
119        int * ptr = copy(111111);
120        printf("copy=%d\n", *ptr);
121
[1e3d5b6]122        printf("calling func\n");
123        func(3, 2.0, 111, 4.145);
124        printf("finished func\n");
[1dcd52a3]125
126        {
127                // T = [const int] -- this ensures that void(*)(int) satisfies void(*)(const int)
128                const int x;
129                bar(x);
130        }
[b3763ca]131
132        delete(ptr);
133        delete(x4);
134        delete(x3);
135        delete(x2);
136        delete(x1);
137        delete(x0);
[da6dec23]138}
139
140// Local Variables: //
141// tab-width: 4 //
142// End: //
Note: See TracBrowser for help on using the repository browser.