449
|
1 /*
|
|
2 test for CbC converted code from C
|
|
3 */
|
|
4
|
17
|
5 #include "stdio.h"
|
|
6
|
172
|
7 typedef void *stack;
|
17
|
8
|
449
|
9 void *stack0; /* size of void* == 1 */
|
|
10
|
172
|
11 struct cont_save { /* General Return Continuation */
|
|
12 code (*ret)();
|
|
13 };
|
17
|
14
|
|
15 /*
|
|
16 code g(int,void *);
|
|
17 code f_g0(int ,int ,void *);
|
|
18 code f_g1(int,void *);
|
172
|
19 */
|
17
|
20
|
172
|
21 struct f_g0_save { /* Specialized Return Continuation */
|
|
22 code (*ret)();
|
|
23 int ii,kk,jj;
|
|
24 };
|
17
|
25
|
172
|
26 code g(int i,void *sp) {
|
|
27 goto (* ((struct cont_save *)sp)->ret)(i+4,sp);
|
|
28 }
|
17
|
29
|
172
|
30 code f_g1(int j,void *sp) { /* Continuation */
|
|
31 int k;
|
|
32 struct f_g0_save *c;
|
17
|
33
|
172
|
34 c = sp;
|
|
35 k = c->kk;
|
|
36 sp += sizeof(struct f_g0_save);
|
|
37 goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp);
|
|
38 }
|
17
|
39
|
172
|
40 code f(int i,void *sp) {
|
|
41 int k,j;
|
|
42 struct f_g0_save *c;
|
449
|
43 printf("#0036:f 0 sp: %x\n",sp-stack0);
|
17
|
44
|
172
|
45 k = 3+i;
|
17
|
46
|
449
|
47 printf("#0040:f 1 sp: %x\n",sp-stack0);
|
172
|
48 sp -= sizeof(struct f_g0_save);
|
449
|
49 printf("#0042:f 2 sp: %x\n",sp-stack0);
|
172
|
50 c = sp;
|
|
51 c->kk = k;
|
|
52 c->ii = i;
|
|
53 c->jj = j;
|
|
54 c->ret = f_g1;
|
|
55 goto g(i,sp);
|
|
56 }
|
17
|
57
|
|
58
|
|
59
|
|
60 struct f0_save { /* Specialized Return Continuation */
|
|
61 code (*ret)();
|
|
62 code (*exit1)();
|
|
63 void *exit1env;
|
|
64 int jj;
|
|
65 };
|
|
66
|
|
67 code f0(int i,int j,code(*exit2)(), void *exit2env,void *sp)
|
|
68 {
|
|
69 struct f0_save *c;
|
449
|
70 printf("#0065:f0 1 sp: %x\n",sp-stack0);
|
17
|
71 sp -= sizeof(struct f0_save);
|
449
|
72 printf("#0067:f0 2 sp: %x\n",sp-stack0);
|
17
|
73 c = sp;
|
|
74 c->jj = j;
|
|
75 c->exit1 = exit2;
|
|
76 c->exit1env = exit2env;
|
|
77 c->ret = f1;
|
449
|
78 printf("#0073:f0 3 sp: %x\n",sp-stack0);
|
17
|
79 goto f(i,sp);
|
|
80 }
|
|
81
|
|
82 code f1(int i,void *sp) {
|
|
83 int j;
|
|
84 int *exit2env;
|
|
85 code (*exit2)();
|
|
86 struct f0_save *c;
|
|
87
|
|
88 c = sp;
|
|
89 j = c->jj;
|
|
90 exit2 = c->exit1;
|
|
91 exit2env = c->exit1env;
|
|
92
|
|
93 sp += sizeof(struct f0_save);
|
|
94 goto print(i,j,exit2,exit2env);
|
|
95 }
|
|
96
|
|
97 int main( int ac, char *av[])
|
|
98 {
|
|
99 int i,j;
|
|
100 int *sp;
|
|
101
|
172
|
102 // i = atoi(av[1]);
|
|
103 i = 1;
|
17
|
104 stack0 = ((char *)malloc(1024)+1024);
|
|
105 sp = stack0;
|
|
106 j = i;
|
|
107
|
449
|
108 printf("#0103:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0));
|
17
|
109 goto f0(i,j,return,environment,sp);
|
|
110 }
|
|
111
|
|
112 code print(int i,int j,(*exit1)(),void*exit1env)
|
|
113 {
|
427
|
114 printf("#0109:%d %d\n",i,j);
|
172
|
115 goto (*exit1)(0),exit1env;
|
17
|
116 }
|
|
117
|