Rune - Content-locking work 1/2
[rune.git] / tests / defaults.d
1 #!/usr/local/bin/rune -x
2 #
3 #       Demonstrate the use of defaults for type and procedure arguments.
4 #       elements with defaults are optional.  Use slightly more complex
5 #       expressions to ensure that temporary storage is properly allocated
6 #       to resolve them.
7 #
8 #       Note that as with C, Rune does not guarentee the order of evaluation
9 #       for procedural arguments... or for compound expressions for that
10 #       matter.  XXX we probably should.
11
12 limport "sys";
13 import "stdio";
14
15 alias stdio.File *stdout = stdio.stdout;
16
17 class Fubar {
18         myint_t a;
19         int b = 20 - 0;
20         int c = 3 + 0;
21
22         constructor method
23         void 
24         bleh()
25         {
26                 this.c = 1;
27         }
28 }
29
30 typedef int myint_t = 4 + 0 + (0 * 0);
31
32 int
33 main(int ac, char **av)
34 {
35         int32_t i = 100;
36         (int a = 4, Fubar b) y = (b:(b:1000));
37         Fubar *ptr;
38         Fubar flub;
39
40         stdout->show("This should be 4:", y.b.a);
41         stdout->show("This should be 1000:", y.b.b);
42
43         i = fubar(7);           # b's default will be returned
44         stdout->show("This should be 5:", i);
45         i = fubar(b:9, a:3);
46         stdout->show("This should be 9:", i);
47         ptr.new();
48         stdout->show("This should be 4:", ptr->a);
49         stdout->show("This should be 20:", ptr->b);
50         stdout->show("This should be 1:", ptr->c);
51
52         stdout->show("This should be 4:", flub.a);
53         stdout->show("This should be 20:", flub.b);
54         stdout->show("This should be 1:", flub.c);
55
56         return(0);
57 }
58
59 int
60 fubar(int a, int b = 5)
61 {
62         return(b);
63 }