Mercurial > hg > CbC > CbC_examples
view goto.c @ 29:a94136a6edb2 default tip
fix for LLVM12
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 17 Jul 2021 14:38:29 +0900 |
parents | 586096c45873 |
children |
line wrap: on
line source
#define __environment _CbC_environment #define __return _CbC_return extern int printf(const char *,...); /* * using __code a2(int i,__code conv()); * make conv valiadic. It complains TCE. * use struct instead */ struct conv { int i, j, k; __code (*conv)(struct conv c); __code (*exit)(int i, void *e); } g_conv; __code a2(struct conv c); __code a3(struct conv c); __code a4(struct conv c); __code a5(struct conv c); __code a6(struct conv c); __code a7(struct conv c); __code a8(struct conv c); __code a9(struct conv c); char* print_conv(struct conv c); __code (*exit0)(int,void*); void *env; __code a2(struct conv c) { printf("#0023:a2 %d %s\n",c.i,print_conv(c)); goto c.conv((struct conv){.i = c.i+1,.conv = a4}); } __code a3(struct conv c) { printf("#0030:a3 %d %s\n",c.i,print_conv(c)); goto c.conv((struct conv){.i=c.i+1,.conv=a5}); } __code a4(struct conv c) { printf("#0037:a4 %d %s\n",c.i,print_conv(c)); goto (*c.conv)((struct conv){.i=c.i+1,.conv=a6}); } __code a5(struct conv c) { printf("#0044:a5 %d %s\n",c.i,print_conv(c)); goto (*c.conv)((struct conv){.i=c.i+1,.j=c.i+2,.k=c.i+3,.conv=a7}); } __code a6(struct conv c) { printf("#0051:a6 %d %s\n",c.i,print_conv(c)); c.exit = exit0; c.i = c.i+1 ; c.conv = a8; goto c.conv(c); } __code a7(struct conv c) { printf("#0058:a7 %d %s\n",c.i,print_conv(c)); c.exit = exit0; c.i = c.i+1; c.conv = a9; goto c.conv(c); } __code a8(struct conv c) { printf("#0065:a8 %d %s\n",c.i,print_conv(c)); c.i = c.i+1; goto c.exit(c.i,env); } __code a9(struct conv c) { printf("#0072:a9 %d %s\n",c.i,print_conv(c)); goto (*c.exit)(0,env); } int main(int ac,char *av[]) { exit0 = __return; env = __environment; g_conv.conv = a2; g_conv.exit = exit0; g_conv.i = 1; g_conv.j = 2; g_conv.k = 3; goto g_conv.conv(g_conv); } char* print_conv(struct conv c) { if(c.conv==a2) return "a2"; if(c.conv==a3) return "a3"; if(c.conv==a4) return "a4"; if(c.conv==a5) return "a5"; if(c.conv==a6) return "a6"; if(c.conv==a7) return "a7"; if(c.conv==a8) return "a8"; if(c.conv==a9) return "a9"; else return "xx"; }