170
|
1 #include "stdio.h"
|
|
2
|
|
3 f0(int i) {
|
|
4 int k,j;
|
|
5 k = 3+i;
|
|
6 j = g0(i+3);
|
|
7 return k+4+j;
|
|
8 }
|
|
9
|
|
10 g0(int i) {
|
|
11 return i+4;
|
|
12 }
|
|
13
|
|
14 typedef char *stack;
|
|
15
|
|
16 struct cont_interface { // General Return Continuation
|
|
17 code (*ret)();
|
|
18 };
|
|
19
|
|
20 code f(int i,stack sp) {
|
|
21 int k,j;
|
|
22 k = 3+i;
|
|
23 goto f_g0(i,k,sp);
|
|
24 }
|
|
25
|
|
26 struct f_g0_interface { // Specialized Return Continuation
|
|
27 code (*ret)();
|
|
28 int i_,k_,j_;
|
|
29 };
|
|
30
|
|
31 code f_g1(int j,stack sp);
|
|
32
|
|
33 code f_g0(int i,int k,stack sp) { // Caller
|
|
34 struct f_g0_interface *c =
|
|
35 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
|
|
36
|
|
37 c->ret = f_g1;
|
|
38 c->k_ = k;
|
|
39 c->i_ = i;
|
|
40
|
|
41 goto g(i+3,sp);
|
|
42 }
|
|
43
|
|
44 code f_g1(int j,stack sp) { // Continuation
|
|
45 struct f_g0_interface *c = sp;
|
|
46 int k = c->k_;
|
|
47 sp += sizeof(struct f_g0_interface);
|
|
48 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp);
|
|
49 }
|
|
50
|
|
51 code g(int i,stack sp) {
|
|
52 goto (( (struct cont_interface *)sp)->ret)(i+4,sp);
|
|
53 }
|
|
54
|
|
55 struct main_continuation { // General Return Continuation
|
|
56 code (*ret)();
|
|
57 code (*main_ret)();
|
|
58 void *env;
|
|
59 };
|
|
60
|
|
61 code main_return(int i,stack sp) {
|
427
|
62 printf("#0061:%d\n",i);
|
170
|
63 goto (( (struct main_continuation *)sp)->main_ret)(0),
|
|
64 ((struct main_continuation *)sp)->env;
|
|
65 }
|
|
66
|
|
67 #define STACK_SIZE 2048
|
|
68 stack main_stack[STACK_SIZE];
|
|
69 #define stack_last (&main_stack[STACK_SIZE])
|
|
70
|
|
71 main()
|
|
72 {
|
|
73 struct main_continuation *cont;
|
|
74 stack sp = stack_last;
|
|
75
|
427
|
76 printf("#0075:%d\n",f0(233));
|
170
|
77
|
|
78 sp -= sizeof(*cont);
|
|
79 cont = (struct main_continuation *)sp;
|
|
80 cont->ret = main_return;
|
|
81 cont->main_ret = return;
|
|
82 cont->env = environment;
|
|
83 goto f(233,sp);
|
|
84 }
|
|
85
|
|
86 /* end */
|