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