# HG changeset patch # User Shinji KONO # Date 1626500309 -32400 # Node ID a94136a6edb2eb5249ed5f3a288e58bb1f9ddb8b # Parent 51f8521bc5d112c4c1eac8819a6ef50d88f95044 fix for LLVM12 diff -r 51f8521bc5d1 -r a94136a6edb2 conv1.c --- a/conv1.c Sat May 23 07:31:02 2020 +0900 +++ b/conv1.c Sat Jul 17 14:38:29 2021 +0900 @@ -42,7 +42,7 @@ __code (*ret)(int, void *); }; -#ifndef __llvm__ +//#ifndef __llvm__ __code f_g0(int i,int k,stack sp); __code f_g1(int j,stack sp); __code g(int i,stack sp); @@ -53,7 +53,7 @@ __code main_return2(int i,stack sp); __code g2_1(int k,int i,stack *sp); __code h2_11(int i,int k,stack *sp); -#endif +//#endif __code f(int i,stack sp) { int k,j; diff -r 51f8521bc5d1 -r a94136a6edb2 fact-a.c --- a/fact-a.c Sat May 23 07:31:02 2020 +0900 +++ b/fact-a.c Sat Jul 17 14:38:29 2021 +0900 @@ -1,8 +1,13 @@ #define __environment _CbC_environment -#define __return _CbC_return +#define __return _CbC_return #include "stdio.h" +/* + * This is a first example of CbC, but it is not work on LLVM now + * because of a variadic function + */ + __code factorial(int n,int result,int orig,__code(*print)(),__code(*exit1)(), void *exit1env) { if (n<0) { diff -r 51f8521bc5d1 -r a94136a6edb2 goto.c --- a/goto.c Sat May 23 07:31:02 2020 +0900 +++ b/goto.c Sat Jul 17 14:38:29 2021 +0900 @@ -3,94 +3,104 @@ extern int printf(const char *,...); -__code (*conv)(int,__code (*)()); -__code a2(int i,__code conv()); -__code a3(int i,__code conv()); -__code a4(int i,__code conv()); -__code a5(int i,__code conv()); -__code a6(); -__code a7(); -__code a8(); -__code a9(); +/* + * using __code a2(int i,__code conv()); + * make conv valiadic. It complains TCE. + * use struct instead + */ -char* print_conv(__code conv()); +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(int i,__code conv()) -{ - printf("#0023:a2 %d %s\n",i,print_conv(conv)); - goto conv(i+1,a4); +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(int i,__code (*conv)()) -{ - printf("#0030:a3 %d %s\n",i,print_conv(conv)); - goto conv(i+1,a5); +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(int i,__code conv()) -{ - printf("#0037:a4 %d %s\n",i,print_conv(conv)); - goto (*conv)(i+1,a6); +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 -a5(int i,__code (*conv)()) -{ - printf("#0044:a5 %d %s\n",i,print_conv(conv)); - goto (*conv)(i+1,i+2,i+3,a7); -} - -__code -a6(int i,int j,int k,__code conv()) -{ - printf("#0051:a6 %d %s\n",i,print_conv(conv)); - goto conv(i+1,j,k,a8); +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(int i,int j,int k,__code (*conv)()) -{ - printf("#0058:a7 %d %s\n",i,print_conv(conv)); - goto conv(i+1,j,k,a9); +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(int i,int j,int k,__code conv()) -{ - printf("#0065:a8 %d %s\n",i,print_conv(conv)); - goto (*conv)(i+1,j,k,exit0); +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(int i,int j,int k,__code (*conv)()) -{ - printf("#0072:a9 %d %s\n",i,print_conv(conv)); - goto (*conv)(0,env); +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; - conv = a2; - goto conv(1,a3); + 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(__code conv()) -{ - if(conv==a2) return "a2"; - if(conv==a3) return "a3"; - if(conv==a4) return "a4"; - if(conv==a5) return "a5"; - if(conv==a6) return "a6"; - if(conv==a7) return "a7"; - if(conv==a8) return "a8"; - if(conv==a9) return "a9"; +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"; }