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