comparison conv.c @ 1:ba74047a4d78

add Makefile for arg, bug, conv, normal and fix these .c file
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Wed, 22 Oct 2014 00:38:01 +0900
parents bacef8675607
children
comparison
equal deleted inserted replaced
0:bacef8675607 1:ba74047a4d78
1 #include "stdio.h" 1 #include "stdio.h"
2 2
3 f0(int i) { 3 #ifdef CLANG
4 int k,j; 4 #define _CbC_return __return
5 k = 3+i; 5 #define _CbC_environment __environment
6 j = g0(i+3); 6 #endif
7 return k+4+j; 7
8 int g0(int i) {
9 return i+4;
8 } 10 }
9 11
10 g0(int i) { 12 int f0(int i) {
11 return i+4; 13 int k,j;
14 k = 3+i;
15 j = g0(i+3);
16 return k+4+j;
12 } 17 }
13
14 18
15 typedef void *stack; 19 typedef void *stack;
16 20
17 __code f_g0(int i,int k,stack sp) ; 21 __code f_g0(int i,int k,stack sp) ;
18 22
19 struct cont_interface { // General Return Continuation 23 struct cont_interface { // General Return Continuation
20 __code (*ret)(int, void*); 24 __code (*ret)(int, void*);
21 }; 25 };
22 26
23 __code f(int i,stack sp) { 27 __code f(int i,stack sp) {
24 int k,j; 28 int k,j;
25 k = 3+i; 29 k = 3+i;
26 goto f_g0(i,k,sp); 30 goto f_g0(i,k,sp);
27 } 31 }
28 32
29 struct f_g0_interface { // Specialized Return Continuation 33 struct f_g0_interface { // Specialized Return Continuation
30 __code (*ret)(); 34 __code (*ret)();
31 int i_,k_,j_; 35 int i_,k_,j_;
32 }; 36 };
33 37
34 __code f_g1(int j,stack sp); 38 __code f_g1(int j,stack sp);
35 __code g(int i,stack sp) ; 39 __code g(int i,stack sp) ;
36 40
37 __code f_g0(int i,int k,stack sp) { // Caller 41 __code f_g0(int i,int k,stack sp) { // Caller
38 struct f_g0_interface *c = 42 struct f_g0_interface *c =
39 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); 43 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
44
45 c->ret = f_g1;
46 c->k_ = k;
47 c->i_ = i;
40 48
41 c->ret = f_g1; 49 goto g(i+3,sp);
42 c->k_ = k;
43 c->i_ = i;
44
45 goto g(i+3,sp);
46 } 50 }
47 51
48 __code f_g1(int j,stack sp) { // Continuation 52 __code f_g1(int j,stack sp) { // Continuation
49 struct f_g0_interface *c = (struct f_g0_interface *)sp; 53 struct f_g0_interface *c = (struct f_g0_interface *)sp;
50 int k = c->k_; 54 int k = c->k_;
51 sp += sizeof(struct f_g0_interface); 55 sp += sizeof(struct f_g0_interface);
52 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); 56 goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp);
53 } 57 }
54 58
55 __code g(int i,stack sp) { 59 __code g(int i,stack sp) {
56 goto (( (struct cont_interface *)sp)->ret)(i+4,sp); 60 goto (( (struct cont_interface *)sp)->ret)(i+4,sp);
57 } 61 }
58 62
59 struct main_continuation { // General Return Continuation 63 struct main_continuation { // General Return Continuation
60 __code (*ret)(int, void*); 64 __code (*ret)(int, void*);
61 __code (*main_ret)(int, void*); 65 __code (*main_ret)(int, void*);
62 void *env; 66 void *env;
63 }; 67 };
64 68
65 __code main_return(int i,stack sp) { 69 __code main_return(int i,stack sp) {
66 printf("#0061:%d\n",i); 70 printf("#0061:%d\n",i);
67 goto (( (struct main_continuation *)sp)->main_ret)(i, 71 goto (( (struct main_continuation *)sp)->main_ret)(i,
68 ((struct main_continuation *)sp)->env); 72 ((struct main_continuation *)sp)->env);
69 } 73 }
70 74
71 #define STACK_SIZE 2048 75 #define STACK_SIZE 2048
72 char main_stack[STACK_SIZE]; 76 char main_stack[STACK_SIZE];
73 #define stack_last (&main_stack[STACK_SIZE]) 77 #define stack_last (&main_stack[STACK_SIZE])
74 78
75 typedef __code (*return_type)(int, void*); 79 typedef __code (*return_type)(int, void*);
76 int 80 int
77 main(int argc, char **argv) 81 main(int argc, char **argv)
78 { 82 {
79 struct main_continuation *cont; 83 struct main_continuation *cont;
80 stack sp = stack_last; 84 stack sp = stack_last;
81 85
82 printf("#0075:%d\n",f0(233)); 86 printf("#0075:%d\n",f0(233));
83 87
84 sp -= sizeof(*cont); 88 sp -= sizeof(*cont);
85 cont = (struct main_continuation *)sp; 89 cont = (struct main_continuation *)sp;
86 cont->ret = main_return; 90 cont->ret = main_return;
87 cont->main_ret = (return_type) _CbC_return; 91 cont->main_ret = (return_type) _CbC_return;
88 cont->env = _CbC_environment; 92 cont->env = _CbC_environment;
89 goto f(233,sp); 93 goto f(233,sp);
90 } 94 }
91 95
92 /* end */ 96 /* end */