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