Rune - Fix array passing, optimize constant array indices
[rune.git] / tests / compound.d
1 #!/usr/local/bin/rune -x
2 #
3 #       Demonstrate the use of compound types.
4 #
5
6 import "sys";
7 import <stdio>;
8
9 class Test {
10         int a;
11         int b = 7;
12 }
13
14 int
15 main(int ac, char **av)
16 {
17         Fs fs;
18         (int a, int b) x;
19         (int a, int b = 7) t1 = (a:99);
20         (int a, int b) t2 = (b:90);
21         Test y;
22         Test z;
23         int i;
24
25         stdio.stdout->show(" x should be (0, 0): ", x.a, x.b);
26         stdio.stdout->show("t1 should be (99, 7): ", t1.a, t1.b);
27         stdio.stdout->show("t2 should be (0, 90): ", t2.a, t2.b);
28         stdio.stdout->show(" y should be (0, 7): ", y.a, y.b);
29
30         fs.setfd(1);
31         x = fubar(2);
32         for (i = 0; i < x.b; ++i)
33                 fs.write("x", 1);
34
35         y = fubar2(10);
36         for (i = 0; i < y.b; ++i)
37                 fs.write("y", 1);
38         fs.write("\n", 1);
39         fs.write("xxxyyyyyyyyyyyyyyyyyyyy  <-- should match\n", 42);
40
41         z = fubar3(50);
42         stdio.stdout->show(" x should be (55, 57): ", z.a, z.b);
43
44         return(0);
45 }
46
47 (int a, int b = 3)
48 fubar(int v)
49 {
50         # allow default for b to be returned
51         #
52         return(a:10);
53 }
54
55 Test
56 fubar2(int v)
57 {
58         # maps to compound equivalance for Test (a, b),
59         # overrides default.
60         #
61         return(v*1, v*2);
62 }
63
64 Test
65 fubar3(int v)
66 {
67         # maps to compound equivalance for Test (a, b),
68         # modifies default.
69         #
70         #return(a:5);
71         return(a:v+3, b:v+7);
72 }