Rune - Content-locking work 1/2
[rune.git] / tests / const.d
1 #!/usr/local/bin/rune -x
2 #
3 # Demonstrate constant types.   Constants in Rune are effectively what
4 # '#define BLAH 23' would be in C, except they are specifically typed.
5 #
6
7 limport "sys";
8 import "stdio";
9
10 alias stdio.File *stdout = stdio.stdout;
11 const char NIL = 0UB;
12
13 const int FUTZ = 55;
14
15 class TestClass {
16         global const int ELEMENTS = 64;
17         global const int Y = ELEMENTS + 1;
18         global const int Z = ELEMENTS + 1;
19         char buf[ELEMENTS];
20 }
21
22 subclass TestClass as SubTestClass {
23         refine global const int Z = 99;
24 }
25
26 public 
27 int
28 main(int ac, char **av)
29 {
30         int len;
31         int i;
32         const char *str;
33         TestClass test;
34         SubTestClass test2;
35
36         stdout->show("Eval global constant (65) ", test.Z);
37         stdout->show("Eval global constant (99) ", test2.Z);
38         stdout->show("Eval global constant (55) ", FUTZ);
39
40         for (i = 0; i < 10; ++i) {
41                 len = 1 + 2 * 3;
42         }
43         stdout->show("Array size (64): ", arysize(test.buf));
44         stdout->show("Constant evaluated to (7): ", len);
45         stdout->show("Testclass Y (65): ", TestClass.Y);
46
47         stdout->show("ac = ", ac);
48         str = av[ac - 1];
49         for (len = 0; str[len] != NIL; ++len)
50                 ;
51         stdout->show("argv[argc-1] = ", str);
52         return(len);
53 }