annotate test1.c @ 14:7d168c1829c9

modify makefile
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Fri, 17 Apr 2015 16:09:28 +0900
parents 175041088754
children 586096c45873
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
35d6eabeadb0 modify Makefile. we can use makefile to compile outside CbC examples. (some examples are not compilable...)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1 #ifdef GCC
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #define __environment _CbC_environment
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #define __return _CbC_return
2
35d6eabeadb0 modify Makefile. we can use makefile to compile outside CbC examples. (some examples are not compilable...)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
4 #endif
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 /*
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
7 test for CbC converted __code from C
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
8 */
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include <stdio.h>
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
11 #include <stdlib.h>
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 typedef void *stack;
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 void *stack0; /* size of void* == 1 */
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 struct cont_save { /* General Return Continuation */
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
19 __code (*ret)(int,void*);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 };
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 /*
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
23 __code g(int,void *);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
24 __code f_g0(int ,int ,void *);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
25 __code f_g1(int,void *);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 */
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 struct f_g0_save { /* Specialized Return Continuation */
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
29 __code (*ret)(int,void*);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
30 int ii,kk,jj;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 };
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 __code g(int i,void *sp) {
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
34 goto (* ((struct cont_save *)sp)->ret)(i+4,sp);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 __code f_g1(int j,void *sp) { /* Continuation */
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
38 int k;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
39 struct f_g0_save *c;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
41 c = sp;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
42 k = c->kk;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
43 sp += sizeof(struct f_g0_save);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
44 goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 __code f(int i,void *sp) {
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
48 int k,j;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
49 struct f_g0_save *c;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
50 printf("#0047:f 0 sp: %lx\n",sp-stack0);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
52 k = 3+i;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
54 printf("#0051:f 1 sp: %lx\n",sp-stack0);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
55 sp -= sizeof(struct f_g0_save);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
56 printf("#0053:f 2 sp: %lx\n",sp-stack0);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
57 c = sp;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
58 c->kk = k;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
59 c->ii = i;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
60 c->jj = j;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
61 c->ret = f_g1;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
62 goto g(i,sp);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 struct f0_save { /* Specialized Return Continuation */
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
68 __code (*ret)();
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
69 __code (*exit1)();
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
70 void *exit1env;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
71 int jj;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 };
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 __code f1(int i,void *sp) ;
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 __code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp)
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 {
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
77 struct f0_save *c;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
78 printf("#0075:f0 1 sp: %lx\n",sp-stack0);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
79 sp -= sizeof(struct f0_save);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
80 printf("#0077:f0 2 sp: %lx\n",sp-stack0);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
81 c = sp;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
82 c->jj = j;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
83 c->exit1 = exit2;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
84 c->exit1env = exit2env;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
85 c->ret = f1;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
86 printf("#0083:f0 3 sp: %lx\n",sp-stack0);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
87 goto f(i,sp);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 __code print(int i,int j,__code (*exit1)(),void*exit1env);
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 __code f1(int i,void *sp) {
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
93 int j;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
94 int *exit2env;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
95 __code (*exit2)();
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
96 struct f0_save *c;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
98 c = sp;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
99 j = c->jj;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
100 exit2 = c->exit1;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
101 exit2env = c->exit1env;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
103 sp += sizeof(struct f0_save);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
104 goto print(i,j,exit2,exit2env);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 int main( int ac, char *av[])
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 {
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
109 int i,j;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
110 int *sp;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
112 // i = atoi(av[1]);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
113 i = 1;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
114 stack0 = ((char *)malloc(1024)+1024);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
115 sp = stack0;
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
116 j = i;
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
118 printf("#0115:sp: %lx %lx\n",sp-(int*)stack0,sizeof(*stack0));
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
119 goto f0(i,j,__return,__environment,sp);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
122 __code print(int i,int j,__code (*exit1)(int,void*),void*exit1env)
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 {
4
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
124 printf("#0121:%d %d\n",i,j);
175041088754 fix examples.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
125 goto (*exit1)(0,exit1env);
0
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
bacef8675607 init repository
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127