Commit | Line | Data |
---|---|---|
a07d8d00 MW |
1 | /* -*-sod-*- |
2 | * | |
3 | * A simple SOD module for testing. | |
4 | */ | |
5 | ||
6 | code c : includes { | |
7 | #include <stdio.h> | |
8 | #include "chimaera.h" | |
9 | } | |
10 | ||
11 | code h : includes { | |
12 | #include "sod.h" | |
13 | } | |
14 | ||
a07d8d00 MW |
15 | [nick = nml, link = SodObject] |
16 | class Animal : SodObject { | |
17 | int tickles = 0; | |
18 | ||
01b1aacd MW |
19 | [combination = progn] void tickle(); |
20 | [role = before] void nml.tickle() { me->nml.tickles++; } | |
a07d8d00 MW |
21 | } |
22 | ||
23 | class Lion : Animal { | |
94ffe796 | 24 | void bite() { puts("Munch!"); } |
61d083c6 | 25 | void nml.tickle() { Lion_bite(me); } |
a07d8d00 MW |
26 | } |
27 | ||
28 | class Goat : Animal { | |
94ffe796 | 29 | void butt() { puts("Bonk!"); } |
61d083c6 | 30 | void nml.tickle() { Goat_butt(me); } |
a07d8d00 MW |
31 | } |
32 | ||
33 | class Serpent : Animal { | |
b2cb5c85 MW |
34 | int limit = 2; |
35 | ||
94ffe796 MW |
36 | void hiss() { puts("Sssss!"); } |
37 | void bite() { puts("Nom!"); } | |
38 | void nml.tickle() { | |
b2cb5c85 MW |
39 | if (SERPENT__CONV_NML(me)->nml.tickles <= me->serpent.limit) |
40 | Serpent_hiss(me); | |
41 | else | |
42 | Serpent_bite(me); | |
a07d8d00 MW |
43 | } |
44 | } | |
45 | ||
46 | [nick = sir, link = Animal] | |
47 | class Chimaera : Lion, Goat, Serpent { | |
3f03c3af | 48 | serpent.limit = 1; |
a07d8d00 MW |
49 | } |
50 | ||
d437292a | 51 | code c : user { |
9ccbddd6 MW |
52 | /*----- Main driver code --------------------------------------------------*/ |
53 | ||
54 | static void tickle_animal(Animal *a) | |
55 | { | |
56 | int i; | |
57 | ||
58 | for (i = 0; i < 3; i++) { | |
59 | printf("tickle %s #%d...\n", a->_vt->_class->cls.name, i); | |
61d083c6 | 60 | Animal_tickle(a); |
9ccbddd6 MW |
61 | } |
62 | } | |
63 | ||
64 | static void provoke_lion(Lion *l) | |
65 | { | |
66 | printf("provoking %s as a lion\n", l->_vt->_class->cls.name); | |
61d083c6 | 67 | Lion_bite(l); |
9ccbddd6 MW |
68 | } |
69 | ||
70 | static void provoke_goat(Goat *g) | |
71 | { | |
72 | printf("provoking %s as a goat\n", g->_vt->_class->cls.name); | |
61d083c6 | 73 | Goat_butt(g); |
9ccbddd6 MW |
74 | } |
75 | ||
76 | static void provoke_serpent(Serpent *s) | |
77 | { | |
78 | printf("provoking %s as a serpent\n", s->_vt->_class->cls.name); | |
61d083c6 | 79 | Serpent_bite(s); |
9ccbddd6 MW |
80 | } |
81 | ||
82 | int main(void) | |
83 | { | |
84 | { | |
a142609c | 85 | SOD_DECL(Lion, l, NO_KWARGS); |
9ccbddd6 MW |
86 | provoke_lion(l); |
87 | tickle_animal(LION__CONV_NML(l)); | |
88 | } | |
89 | ||
90 | { | |
a142609c | 91 | SOD_DECL(Goat, g, NO_KWARGS); |
9ccbddd6 MW |
92 | provoke_goat(g); |
93 | tickle_animal(GOAT__CONV_NML(g)); | |
94 | } | |
95 | ||
96 | { | |
a142609c | 97 | SOD_DECL(Serpent, s, NO_KWARGS); |
9ccbddd6 MW |
98 | provoke_serpent(s); |
99 | tickle_animal(SERPENT__CONV_NML(s)); | |
100 | } | |
101 | ||
102 | { | |
a142609c | 103 | SOD_DECL(Chimaera, c, NO_KWARGS); |
9ccbddd6 MW |
104 | provoke_lion(CHIMAERA__CONV_LION(c)); |
105 | provoke_goat(CHIMAERA__CONV_GOAT(c)); | |
106 | provoke_serpent(CHIMAERA__CONV_SERPENT(c)); | |
107 | tickle_animal(CHIMAERA__CONV_NML(c)); | |
108 | } | |
109 | ||
110 | return (0); | |
111 | } | |
112 | ||
113 | } |