Rune - Misc work
[rune.git] / tests / global.d
1 #!/usr/local/bin/rune
2 #
3 # Demonstrate global elements in classes, procedures, and compound
4 # types.
5 #
6
7 import "sys" as self;
8 import "stdio";
9
10 alias stdio.File *stdout = stdio.stdout;
11
12 class Test {
13         int a = 2;
14         global int b = 6;
15         int c;
16         myint_t z;
17
18
19 typedef int myint_t = 99;
20
21 # note that ( 7 ) is not compound, but Rune will always cast a non-compound
22 # expression to compound in the resolver if the resolver needs a compound
23 # expression.
24 #
25 (global int x = 2, int y = 6) A = ( 7 );
26 int B = 8;
27
28 const int xsize = 8192;
29 const int xmask = (xsize - 1);
30
31 public 
32 int
33 main(int ac, char **av)
34 {
35         Fd fd;
36         int i;
37         Test t1 = ( 3, 4 );
38         Test t2;
39         Test t3;
40         Test t4 = ( 8, 9, 10 );
41         void *v;
42
43         fd.setfd(1);
44         stdout->show("sizeof(A) should be 4:", sizeof(A));
45         stdout->show("A.x should be 2:", A.x);
46         stdout->show("A.y should be 7:", A.y);
47         stdout->show("t1.a should be 3:", t1.a);
48         stdout->show("t1.c should be 4:", t1.c);
49         stdout->show("t2.a should be 2:", t2.a);
50         stdout->show("t3.z should be 99:", t3.z);
51         stdout->show("t4.z should be 10:", t4.z);
52         stdout->show("xsize should be 8192:", xsize);
53         stdout->show("xmask should be 8191:", xmask);
54         stdout->show("t4.z should be 10:", t4.z);
55         fd.write("\n", 1);
56         return(0);
57 }