annotate test/test1.c @ 19:b62230ea38f6

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