~mdw
/
sod
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
doc/: Consistently write `rĂ´le', rather than `role', in prose.
[sod]
/
test
/
chimaera.sod
diff --git
a/test/chimaera.sod
b/test/chimaera.sod
index
018957e
..
b30248c
100644
(file)
--- a/
test/chimaera.sod
+++ b/
test/chimaera.sod
@@
-3,49
+3,52
@@
* A simple SOD module for testing.
*/
* A simple SOD module for testing.
*/
-code c
: includes {
+code c: includes {
#include <stdio.h>
#include "chimaera.h"
}
#include <stdio.h>
#include "chimaera.h"
}
-code h
: includes {
+code h: includes {
#include "sod.h"
}
[nick = nml, link = SodObject]
#include "sod.h"
}
[nick = nml, link = SodObject]
-class Animal
: SodObject {
+class Animal: SodObject {
int tickles = 0;
int tickles = 0;
- void tickle();
-
- [role = before]
- void nml.tickle() { me->nml.tickles++; }
+ [combination = progn] void tickle();
+ [role = before] void nml.tickle() { me->nml.tickles++; }
}
}
-class Lion
: Animal {
+class Lion: Animal {
void bite() { puts("Munch!"); }
void bite() { puts("Munch!"); }
- void nml.tickle() {
me->_vt->lion.
bite(me); }
+ void nml.tickle() {
Lion_
bite(me); }
}
}
-class Goat
: Animal {
+class Goat: Animal {
void butt() { puts("Bonk!"); }
void butt() { puts("Bonk!"); }
- void nml.tickle() {
me->_vt->goat.
butt(me); }
+ void nml.tickle() {
Goat_
butt(me); }
}
}
-class Serpent : Animal {
+class Serpent: Animal {
+ int limit = 2;
+
void hiss() { puts("Sssss!"); }
void bite() { puts("Nom!"); }
void nml.tickle() {
void hiss() { puts("Sssss!"); }
void bite() { puts("Nom!"); }
void nml.tickle() {
- if (SERPENT__CONV_NML(me)->nml.tickles > 2) me->_vt->serpent.bite(me);
- else me->_vt->serpent.hiss(me);
+ if (SERPENT__CONV_NML(me)->nml.tickles <= me->serpent.limit)
+ Serpent_hiss(me);
+ else
+ Serpent_bite(me);
}
}
[nick = sir, link = Animal]
}
}
[nick = sir, link = Animal]
-class Chimaera : Lion, Goat, Serpent {
+class Chimaera: Lion, Goat, Serpent {
+ serpent.limit = 1;
}
}
-code c
: user [classes end, user, epilogue]
{
+code c
: user
{
/*----- Main driver code --------------------------------------------------*/
static void tickle_animal(Animal *a)
/*----- Main driver code --------------------------------------------------*/
static void tickle_animal(Animal *a)
@@
-54,54
+57,50
@@
static void tickle_animal(Animal *a)
for (i = 0; i < 3; i++) {
printf("tickle %s #%d...\n", a->_vt->_class->cls.name, i);
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);
}
}
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);
}
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);
}
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)
{
{
int main(void)
{
{
- SOD_DECL(Lion, l);
+ SOD_DECL(Lion, l
, NO_KWARGS
);
provoke_lion(l);
tickle_animal(LION__CONV_NML(l));
}
{
provoke_lion(l);
tickle_animal(LION__CONV_NML(l));
}
{
- SOD_DECL(Goat, g);
+ SOD_DECL(Goat, g
, NO_KWARGS
);
provoke_goat(g);
tickle_animal(GOAT__CONV_NML(g));
}
{
provoke_goat(g);
tickle_animal(GOAT__CONV_NML(g));
}
{
- SOD_DECL(Serpent, s);
+ SOD_DECL(Serpent, s
, NO_KWARGS
);
provoke_serpent(s);
tickle_animal(SERPENT__CONV_NML(s));
}
{
provoke_serpent(s);
tickle_animal(SERPENT__CONV_NML(s));
}
{
- SOD_DECL(Chimaera, c);
+ SOD_DECL(Chimaera, c
, NO_KWARGS
);
provoke_lion(CHIMAERA__CONV_LION(c));
provoke_goat(CHIMAERA__CONV_GOAT(c));
provoke_serpent(CHIMAERA__CONV_SERPENT(c));
provoke_lion(CHIMAERA__CONV_LION(c));
provoke_goat(CHIMAERA__CONV_GOAT(c));
provoke_serpent(CHIMAERA__CONV_SERPENT(c));