Mercurial > hg > CbC > CbC_examples
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 |
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 | 2 #define __environment _CbC_environment |
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 | 5 |
6 /* | |
4 | 7 test for CbC converted __code from C |
8 */ | |
0 | 9 |
10 #include <stdio.h> | |
4 | 11 #include <stdlib.h> |
0 | 12 |
13 | |
14 typedef void *stack; | |
15 | |
16 void *stack0; /* size of void* == 1 */ | |
17 | |
18 struct cont_save { /* General Return Continuation */ | |
4 | 19 __code (*ret)(int,void*); |
0 | 20 }; |
21 | |
22 /* | |
4 | 23 __code g(int,void *); |
24 __code f_g0(int ,int ,void *); | |
25 __code f_g1(int,void *); | |
0 | 26 */ |
27 | |
28 struct f_g0_save { /* Specialized Return Continuation */ | |
4 | 29 __code (*ret)(int,void*); |
30 int ii,kk,jj; | |
0 | 31 }; |
32 | |
33 __code g(int i,void *sp) { | |
4 | 34 goto (* ((struct cont_save *)sp)->ret)(i+4,sp); |
0 | 35 } |
36 | |
37 __code f_g1(int j,void *sp) { /* Continuation */ | |
4 | 38 int k; |
39 struct f_g0_save *c; | |
0 | 40 |
4 | 41 c = sp; |
42 k = c->kk; | |
43 sp += sizeof(struct f_g0_save); | |
44 goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp); | |
0 | 45 } |
46 | |
47 __code f(int i,void *sp) { | |
4 | 48 int k,j; |
49 struct f_g0_save *c; | |
50 printf("#0047:f 0 sp: %lx\n",sp-stack0); | |
0 | 51 |
4 | 52 k = 3+i; |
0 | 53 |
4 | 54 printf("#0051:f 1 sp: %lx\n",sp-stack0); |
55 sp -= sizeof(struct f_g0_save); | |
56 printf("#0053:f 2 sp: %lx\n",sp-stack0); | |
57 c = sp; | |
58 c->kk = k; | |
59 c->ii = i; | |
60 c->jj = j; | |
61 c->ret = f_g1; | |
62 goto g(i,sp); | |
0 | 63 } |
64 | |
65 | |
66 | |
67 struct f0_save { /* Specialized Return Continuation */ | |
4 | 68 __code (*ret)(); |
69 __code (*exit1)(); | |
70 void *exit1env; | |
71 int jj; | |
0 | 72 }; |
73 | |
74 __code f1(int i,void *sp) ; | |
75 __code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp) | |
76 { | |
4 | 77 struct f0_save *c; |
78 printf("#0075:f0 1 sp: %lx\n",sp-stack0); | |
79 sp -= sizeof(struct f0_save); | |
80 printf("#0077:f0 2 sp: %lx\n",sp-stack0); | |
81 c = sp; | |
82 c->jj = j; | |
83 c->exit1 = exit2; | |
84 c->exit1env = exit2env; | |
85 c->ret = f1; | |
86 printf("#0083:f0 3 sp: %lx\n",sp-stack0); | |
87 goto f(i,sp); | |
0 | 88 } |
89 | |
90 __code print(int i,int j,__code (*exit1)(),void*exit1env); | |
91 | |
92 __code f1(int i,void *sp) { | |
4 | 93 int j; |
94 int *exit2env; | |
95 __code (*exit2)(); | |
96 struct f0_save *c; | |
0 | 97 |
4 | 98 c = sp; |
99 j = c->jj; | |
100 exit2 = c->exit1; | |
101 exit2env = c->exit1env; | |
0 | 102 |
4 | 103 sp += sizeof(struct f0_save); |
104 goto print(i,j,exit2,exit2env); | |
0 | 105 } |
106 | |
107 int main( int ac, char *av[]) | |
108 { | |
4 | 109 int i,j; |
110 int *sp; | |
0 | 111 |
4 | 112 // i = atoi(av[1]); |
113 i = 1; | |
114 stack0 = ((char *)malloc(1024)+1024); | |
115 sp = stack0; | |
116 j = i; | |
0 | 117 |
4 | 118 printf("#0115:sp: %lx %lx\n",sp-(int*)stack0,sizeof(*stack0)); |
119 goto f0(i,j,__return,__environment,sp); | |
0 | 120 } |
121 | |
4 | 122 __code print(int i,int j,__code (*exit1)(int,void*),void*exit1env) |
0 | 123 { |
4 | 124 printf("#0121:%d %d\n",i,j); |
125 goto (*exit1)(0,exit1env); | |
0 | 126 } |
127 |