comparison CbC-examples/c-next.c @ 137:d22083d7f10b

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:16:42 +0900
parents 4627f235cf2a
children fc828634a951
comparison
equal deleted inserted replaced
136:4627f235cf2a 137:d22083d7f10b
3 typedef unsigned short MVMuint16; 3 typedef unsigned short MVMuint16;
4 typedef unsigned char MVMuint8; 4 typedef unsigned char MVMuint8;
5 typedef long* MVMRegister; 5 typedef long* MVMRegister;
6 typedef void* MVMCompUnit; 6 typedef void* MVMCompUnit;
7 typedef void* MVMCallsite; 7 typedef void* MVMCallsite;
8 //typedef void* MVMThreadContext;
8 9
9 typedef struct MVMThreadContext { 10 typedef struct MVMThreadContext {
10 MVMuint8 **interp_cur_op; 11 MVMuint8 **interp_cur_op;
11 MVMuint8 **interp_bytecode_start; 12 MVMuint8 **interp_bytecode_start;
12 MVMRegister **interp_reg_base; 13 MVMRegister **interp_reg_base;
13 MVMCompUnit **interp_cu; 14 MVMCompUnit **interp_cu;
14 } MVMThreadContext; 15 } MVMThreadContext;
16
15 17
16 typedef struct interp { 18 typedef struct interp {
17 MVMuint16 op; 19 MVMuint16 op;
18 /* Points to the place in the bytecode right after the current opcode. */ 20 /* Points to the place in the bytecode right after the current opcode. */
19 /* See the NEXT_OP macro for making sense of this */ 21 /* See the NEXT_OP macro for making sense of this */
32 /* The current call site we're constructing. */ 34 /* The current call site we're constructing. */
33 MVMCallsite *cur_callsite; 35 MVMCallsite *cur_callsite;
34 36
35 MVMThreadContext *tc; 37 MVMThreadContext *tc;
36 38
39 //__code (*ret)();
40 //__code (*main_ret)();
37 __code (*ret)(int, void*); 41 __code (*ret)(int, void*);
38 __code (*main_ret)(int, void*); 42 __code (*main_ret)(int, void*);
39 void *env; 43 void *env;
40 44
41 } INTER,*INTERP; 45 } INTER,*INTERP;
42 46
43 __code cbc_next(INTERP i); 47 __code cbc_no_op(INTERP);
48 __code cbc_exit(INTERP);
44 49
45 __code cbc_no_op(INTERP i){ 50 __code (* CODES[])(INTERP) = {
46 goto cbc_next(i);
47 }
48
49 __code cbc_exit(INTERP i){
50 goto i->main_ret(0,i->env);
51 }
52
53 __code (* CODES[])(INTERP) = {
54 cbc_no_op, 51 cbc_no_op,
55 cbc_no_op, 52 cbc_no_op,
56 cbc_exit, 53 cbc_exit,
57 }; 54 };
58 55
60 __code (*c)(INTERP); 57 __code (*c)(INTERP);
61 c = CODES[NEXT_OP(i)]; 58 c = CODES[NEXT_OP(i)];
62 goto c(i); 59 goto c(i);
63 } 60 }
64 61
65 int interp_run(MVMThreadContext *tc){ 62 __code cbc_no_op(INTERP i){
66 return 0; 63 goto cbc_next(i);
67 } 64 }
68 65
69 int main(int argc, char **argv){ 66 __code cbc_exit(INTERP i){
67 goto i->main_ret(0,i->env);
68 }
69
70 //__code main_return(int i,stack sp) {
71 // if (loop-->0)
72 // goto f(233,sp);
73 // printf("#0103:%d\n",i);
74 // goto (( (struct main_continuation *)sp)->main_ret)(0,
75 // ((struct main_continuation *)sp)->env);
76 //}
77
78 int interp_run(MVMThreadContext *tc){
70 INTER inter = {0,0,0,0,0,0,0,0,0}; 79 INTER inter = {0,0,0,0,0,0,0,0,0};
71 INTERP i = &inter; 80 INTERP i = &inter;
72 MVMuint8 cur_ops[] = {0,1,2,0,3,2}; 81 MVMuint8 cur_op[] = {0,1,1,0,1,2};
73 82 // i->ret = main_return;
74 i->main_ret = _CbC_return; 83 i->main_ret = _CbC_return;
75 i->env = _CbC_environment; 84 i->env = _CbC_environment;
76 i->cur_op = cur_ops; 85 i->cur_op = cur_op;
77
78 MVMThreadContext tc0, *tc;
79 tc = &tc0;
80 86
81 tc->interp_cur_op = &i->cur_op; 87 tc->interp_cur_op = &i->cur_op;
82 tc->interp_bytecode_start = &i->bytecode_start; 88 tc->interp_bytecode_start = &i->bytecode_start;
83 tc->interp_reg_base = &i->reg_base; 89 tc->interp_reg_base = &i->reg_base;
84 tc->interp_cu = &i->cu; 90 tc->interp_cu = &i->cu;
85 goto cbc_next(i); 91 goto cbc_next(i);
86 // return 0; 92 return 0;
87 } 93 }
94
95 int main(int argc, char **argv){
96 MVMThreadContext tct = {0,0,0,0};
97 MVMThreadContext* tc = &tct;
98 interp_run(tc);
99 }