Rune - Fix array passing, optimize constant array indices
[rune.git] / tests / array.d
1 #!/usr/local/bin/rune -x -d
2 #
3 # Demonstrate basic arrays.
4 #
5
6 import "sys";
7 import <stdio>;
8
9 public
10 void
11 test(const char *str, ...)
12 {
13         int *v = (int *)self.__vardata[0];
14         stdio.stdout->show("XXXXXXX", v);
15 }
16
17 int g = 5;
18
19 public 
20 int
21 main(int ac, char **av)
22 {
23         int *array[4];
24         int a = 2;
25         int b = 4;
26         int c = 6;
27         int d = 8;
28         global int x = 1;
29         int f1[4];
30         int f2[4];
31
32         f2[3] = 5;
33         f1 = f2;                /* XXX should disallow this */
34         stdio.stdout->show("f2(5):", f1[3]);
35
36         pass_array(array);
37
38         array[0] = &a;
39         array[1] = &b;
40         array[2] = &c;
41         array[3] = &d;
42
43         stdio.stdout->show("Array:", array[0], array[1], array[2], array[3]);
44 #       stdio.stdout->show("Array:", &a);
45 #       stdio.stdout->show("XXX need auto array teardown");
46 #       stdio.stdout->show("XXX deref args on return");
47 #       test("xyua", &a);
48
49 #       array[0] = NULL; # XXX teardown
50 #       array[1] = NULL;
51 #       array[2] = NULL;
52 #       array[3] = NULL;
53
54         return(0);
55 }
56
57 # should be pass-by-copy so our modification here should not have
58 # affected the results.
59 #
60 int
61 pass_array(int *array[4])
62 {
63         array[3] = &g;
64 }