chiark / gitweb /
test/chimaera.sod: Reorder Serpent tickling decision.
[sod] / test / chimaera.sod
index ca775bc569985631b22c706229143305771521b4..e9b9077adb5bf107a3c68750bc66efc3b9d5beba 100644 (file)
@@ -16,28 +16,29 @@ code h : includes {
 class Animal : SodObject {
   int tickles = 0;
 
-  void tickle(void) { }
+  [combination = progn]
+  void tickle();
 
   [role = before]
-  void nml.tickle(void) { me->nml.tickles++; }
+  void nml.tickle() { me->nml.tickles++; }
 }
 
 class Lion : Animal {
-  void bite(void) { puts("Munch!"); }
-  void nml.tickle(void) { me->_vt->lion.bite(me); }
+  void bite() { puts("Munch!"); }
+  void nml.tickle() { Lion_bite(me); }
 }
 
 class Goat : Animal {
-  void butt(void) { puts("Bonk!"); }
-  void nml.tickle(void) { me->_vt->goat.butt(me); }
+  void butt() { puts("Bonk!"); }
+  void nml.tickle() { Goat_butt(me); }
 }
 
 class Serpent : Animal {
-  void hiss(void) { puts("Sssss!"); }
-  void bite(void) { puts("Nom!"); }
-  void nml.tickle(void) {
-    if (SERPENT__CONV_NML(me)->nml.tickles > 2) me->_vt->serpent.bite(me);
-    else me->_vt->serpent.hiss(me);
+  void hiss() { puts("Sssss!"); }
+  void bite() { puts("Nom!"); }
+  void nml.tickle() {
+    if (SERPENT__CONV_NML(me)->nml.tickles <= 2) Serpent_hiss(me);
+    else Serpent_bite(me);
   }
 }
 
@@ -54,32 +55,28 @@ static void tickle_animal(Animal *a)
 
   for (i = 0; i < 3; i++) {
     printf("tickle %s #%d...\n", a->_vt->_class->cls.name, i);
-    a->_vt->nml.tickle(a);
+    Animal_tickle(a);
   }
 }
 
 static void provoke_lion(Lion *l)
 {
   printf("provoking %s as a lion\n", l->_vt->_class->cls.name);
-  l->_vt->lion.bite(l);
+  Lion_bite(l);
 }
 
 static void provoke_goat(Goat *g)
 {
   printf("provoking %s as a goat\n", g->_vt->_class->cls.name);
-  g->_vt->goat.butt(g);
+  Goat_butt(g);
 }
 
 static void provoke_serpent(Serpent *s)
 {
   printf("provoking %s as a serpent\n", s->_vt->_class->cls.name);
-  s->_vt->serpent.bite(s);
+  Serpent_bite(s);
 }
 
-#define SOD_DECL(cls_, var_)                                           \
-  struct cls_##__ilayout var_##__layout;                               \
-  cls_ *var_ = cls_##__class->cls.init(&var_##__layout)
-
 int main(void)
 {
   {