test/chimaera.sod: Make `Serpent' tickle tolerance be a slot.
[sod] / test / chimaera.sod
CommitLineData
a07d8d00
MW
1/* -*-sod-*-
2 *
3 * A simple SOD module for testing.
4 */
5
6code c : includes {
7#include <stdio.h>
8#include "chimaera.h"
9}
10
11code h : includes {
12#include "sod.h"
13}
14
a07d8d00
MW
15[nick = nml, link = SodObject]
16class 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
23class Lion : Animal {
94ffe796 24 void bite() { puts("Munch!"); }
61d083c6 25 void nml.tickle() { Lion_bite(me); }
a07d8d00
MW
26}
27
28class Goat : Animal {
94ffe796 29 void butt() { puts("Bonk!"); }
61d083c6 30 void nml.tickle() { Goat_butt(me); }
a07d8d00
MW
31}
32
33class 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]
47class Chimaera : Lion, Goat, Serpent {
48}
49
d437292a 50code c : user {
9ccbddd6
MW
51/*----- Main driver code --------------------------------------------------*/
52
53static void tickle_animal(Animal *a)
54{
55 int i;
56
57 for (i = 0; i < 3; i++) {
58 printf("tickle %s #%d...\n", a->_vt->_class->cls.name, i);
61d083c6 59 Animal_tickle(a);
9ccbddd6
MW
60 }
61}
62
63static void provoke_lion(Lion *l)
64{
65 printf("provoking %s as a lion\n", l->_vt->_class->cls.name);
61d083c6 66 Lion_bite(l);
9ccbddd6
MW
67}
68
69static void provoke_goat(Goat *g)
70{
71 printf("provoking %s as a goat\n", g->_vt->_class->cls.name);
61d083c6 72 Goat_butt(g);
9ccbddd6
MW
73}
74
75static void provoke_serpent(Serpent *s)
76{
77 printf("provoking %s as a serpent\n", s->_vt->_class->cls.name);
61d083c6 78 Serpent_bite(s);
9ccbddd6
MW
79}
80
81int main(void)
82{
83 {
0f1af3cc 84 SOD_DECL(Lion, l);
9ccbddd6
MW
85 provoke_lion(l);
86 tickle_animal(LION__CONV_NML(l));
87 }
88
89 {
0f1af3cc 90 SOD_DECL(Goat, g);
9ccbddd6
MW
91 provoke_goat(g);
92 tickle_animal(GOAT__CONV_NML(g));
93 }
94
95 {
0f1af3cc 96 SOD_DECL(Serpent, s);
9ccbddd6
MW
97 provoke_serpent(s);
98 tickle_animal(SERPENT__CONV_NML(s));
99 }
100
101 {
0f1af3cc 102 SOD_DECL(Chimaera, c);
9ccbddd6
MW
103 provoke_lion(CHIMAERA__CONV_LION(c));
104 provoke_goat(CHIMAERA__CONV_GOAT(c));
105 provoke_serpent(CHIMAERA__CONV_SERPENT(c));
106 tickle_animal(CHIMAERA__CONV_NML(c));
107 }
108
109 return (0);
110}
111
112}