From: Mark Wooding Date: Mon, 17 Aug 2015 16:33:26 +0000 (+0100) Subject: test/chimaera.sod: Introduce a macro for stack-allocating instances. X-Git-Tag: 0.2.0~77 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/0f1af3ccf7cf20bd8e1bbc3518e91bf8ebf2079a?ds=inline test/chimaera.sod: Introduce a macro for stack-allocating instances. --- diff --git a/test/chimaera.sod b/test/chimaera.sod index 63602d8..ca775bc 100644 --- a/test/chimaera.sod +++ b/test/chimaera.sod @@ -76,32 +76,32 @@ static void provoke_serpent(Serpent *s) s->_vt->serpent.bite(s); } +#define SOD_DECL(cls_, var_) \ + struct cls_##__ilayout var_##__layout; \ + cls_ *var_ = cls_##__class->cls.init(&var_##__layout) + int main(void) { { - struct Lion__ilayout ll; - Lion *l = Lion__class->cls.init(&ll); + SOD_DECL(Lion, l); provoke_lion(l); tickle_animal(LION__CONV_NML(l)); } { - struct Goat__ilayout gg; - Goat *g = Goat__class->cls.init(&gg); + SOD_DECL(Goat, g); provoke_goat(g); tickle_animal(GOAT__CONV_NML(g)); } { - struct Serpent__ilayout ss; - Serpent *s = Serpent__class->cls.init(&ss); + SOD_DECL(Serpent, s); provoke_serpent(s); tickle_animal(SERPENT__CONV_NML(s)); } { - struct Chimaera__ilayout cc; - Chimaera *c = Chimaera__class->cls.init(&cc); + SOD_DECL(Chimaera, c); provoke_lion(CHIMAERA__CONV_LION(c)); provoke_goat(CHIMAERA__CONV_GOAT(c)); provoke_serpent(CHIMAERA__CONV_SERPENT(c));