comparison CbC-examples/tmp1.c @ 128:fe568345ddd5

fix CbC-example
author mir3636
date Wed, 11 Apr 2018 19:32:28 +0900
parents 5d30d517ebed
children
comparison
equal deleted inserted replaced
127:4c56639505ff 128:fe568345ddd5
3 #define __return _CbC_return 3 #define __return _CbC_return
4 4
5 5
6 extern int printf(const char *,...); 6 extern int printf(const char *,...);
7 7
8 __code code0(int ac,char *av[],__code (*ret)()); 8 #if 0 //currently gcc version dose not support void type full continuation.
9 __code code1(int ac,char *av[],__code (*exit)(int,void*))
10 9
11 __code (*ret)(); 10 __code code0(int ac,char *av[],__code (*ret)(void*));
11 __code code1(int ac,char *av[],__code (*exit)(void*));
12 __code code3(char a,char b,int c,int d,int e,int f);
13 __code code4(char a,char b,int c,int d,int e,int f);
14
15 __code (*ret)(void *);
12 void *env; 16 void *env;
13 __code exit1(int ac,void *); 17 __code exit1(void *);
14 18
15 void main0(ac,av) 19 void main0(ac,av)
16 int ac; 20 int ac;
17 char *av[]; 21 char *av[];
18 { 22 {
24 goto code1(ac,av,exit1); 28 goto code1(ac,av,exit1);
25 // not reached. (warning?) 29 // not reached. (warning?)
26 printf("#0022:main0 %d end.\n",ac); 30 printf("#0022:main0 %d end.\n",ac);
27 } 31 }
28 32
29 __code exit1(int ac) 33 __code exit1(void *env)
30 { 34 {
31 // exit(0); 35 // exit(0);
32 goto code3(0,1,2,3,4,5); 36 goto code3(0,1,2,3,4,5);
33 } 37 }
34 38
55 goto code3(a,b,c,d,e,f); 59 goto code3(a,b,c,d,e,f);
56 else if(a<40) // cyclic dependency 60 else if(a<40) // cyclic dependency
57 goto code3(b,c,a,e,f,d); 61 goto code3(b,c,a,e,f,d);
58 else if(a<50) 62 else if(a<50)
59 goto code4(a+i,b+j,c+i,d+3,e+3,f+3); 63 goto code4(a+i,b+j,c+i,d+3,e+3,f+3);
60 else goto ret(0,env); 64 else goto ret(env);
61 } 65 }
62 66
63 __code code0(ac,av,ret) 67 __code code0(ac,av,ret)
64 int ac; 68 int ac;
65 char *av[]; 69 char *av[];
66 __code (*ret)(int); 70 __code (*ret)(void *env);
67 { 71 {
68 goto code1(ac,av,ret); 72 goto code1(ac,av,ret);
69 } 73 }
70 74
71 __code code1(ac,av,exit) 75 __code code1(ac,av,exit)
72 int ac; 76 int ac;
73 __code (*exit)(int,void*); 77 __code (*exit)(void*);
74 char *av[]; 78 char *av[];
75 { 79 {
76 __code (*f)(int,void *); 80 __code (*f)(void *);
77 printf("#0073:code1: %d\n",ac); 81 printf("#0073:code1: %d\n",ac);
78 f = exit; 82 f = exit;
79 if (ac>3) 83 if (ac>3)
80 goto code1(ac,av,f); 84 goto code1(ac,av,f);
81 else if (ac>2) 85 else if (ac>2)
82 goto code1(av,ac,f); 86 goto code1(ac,av,f);
83 else 87 else
84 goto (*f)(ac,env); 88 goto (*f)(env);
85 } 89 }
86 90
87 int 91 #endif
88 main(int ac,char *av[]) 92
93 int main(int ac,char *av[])
89 { 94 {
90 main0(1,av); 95 // main0(1,av);
91 printf("#0087:main continue.\n"); 96 printf("#0087:main continue.\n");
92 main0(0,av); 97 // main0(0,av);
93 printf("#0089:main end.\n"); 98 printf("#0089:main end.\n");
94 return 0; 99 return 0;
95 } 100 }
96 101
97 /* end */ 102 /* end */