449
|
1 /*
|
622
|
2 test for CbC converted __code from C
|
449
|
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 */
|
622
|
12 __code (*ret)();
|
172
|
13 };
|
17
|
14
|
|
15 /*
|
622
|
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 */
|
622
|
22 __code (*ret)();
|
172
|
23 int ii,kk,jj;
|
|
24 };
|
17
|
25
|
622
|
26 __code g(int i,void *sp) {
|
172
|
27 goto (* ((struct cont_save *)sp)->ret)(i+4,sp);
|
|
28 }
|
17
|
29
|
622
|
30 __code f_g1(int j,void *sp) { /* Continuation */
|
172
|
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
|
622
|
40 __code f(int i,void *sp) {
|
172
|
41 int k,j;
|
|
42 struct f_g0_save *c;
|
491
|
43 printf("#0042:f 0 sp: %x\n",sp-stack0);
|
17
|
44
|
172
|
45 k = 3+i;
|
17
|
46
|
491
|
47 printf("#0046:f 1 sp: %x\n",sp-stack0);
|
172
|
48 sp -= sizeof(struct f_g0_save);
|
491
|
49 printf("#0048: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 */
|
622
|
61 __code (*ret)();
|
|
62 __code (*exit1)();
|
17
|
63 void *exit1env;
|
|
64 int jj;
|
|
65 };
|
|
66
|
622
|
67 __code f1(int i,void *sp) ;
|
|
68 __code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp)
|
17
|
69 {
|
|
70 struct f0_save *c;
|
573
|
71 printf("#0070:f0 1 sp: %x\n",sp-stack0);
|
17
|
72 sp -= sizeof(struct f0_save);
|
573
|
73 printf("#0072:f0 2 sp: %x\n",sp-stack0);
|
17
|
74 c = sp;
|
|
75 c->jj = j;
|
|
76 c->exit1 = exit2;
|
|
77 c->exit1env = exit2env;
|
|
78 c->ret = f1;
|
573
|
79 printf("#0078:f0 3 sp: %x\n",sp-stack0);
|
17
|
80 goto f(i,sp);
|
|
81 }
|
|
82
|
622
|
83 __code f1(int i,void *sp) {
|
17
|
84 int j;
|
|
85 int *exit2env;
|
622
|
86 __code (*exit2)();
|
17
|
87 struct f0_save *c;
|
|
88
|
|
89 c = sp;
|
|
90 j = c->jj;
|
|
91 exit2 = c->exit1;
|
|
92 exit2env = c->exit1env;
|
|
93
|
|
94 sp += sizeof(struct f0_save);
|
|
95 goto print(i,j,exit2,exit2env);
|
|
96 }
|
|
97
|
|
98 int main( int ac, char *av[])
|
|
99 {
|
|
100 int i,j;
|
|
101 int *sp;
|
|
102
|
172
|
103 // i = atoi(av[1]);
|
|
104 i = 1;
|
17
|
105 stack0 = ((char *)malloc(1024)+1024);
|
|
106 sp = stack0;
|
|
107 j = i;
|
|
108
|
573
|
109 printf("#0108:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0));
|
17
|
110 goto f0(i,j,return,environment,sp);
|
|
111 }
|
|
112
|
622
|
113 __code print(int i,int j,(*exit1)(),void*exit1env)
|
17
|
114 {
|
573
|
115 printf("#0114:%d %d\n",i,j);
|
172
|
116 goto (*exit1)(0),exit1env;
|
17
|
117 }
|
|
118
|