134
|
1 #define NEXT_OP(i) (i->op = *(MVMuint16 *)(i->cur_op), i->cur_op += 2, i->op)
|
|
2
|
|
3 typedef unsigned short MVMuint16;
|
|
4 typedef unsigned char MVMuint8;
|
|
5 typedef long* MVMRegister;
|
|
6 typedef void* MVMCompUnit;
|
|
7 typedef void* MVMCallsite;
|
135
|
8 //typedef void* MVMThreadContext;
|
134
|
9
|
|
10 typedef struct MVMThreadContext {
|
|
11 MVMuint8 **interp_cur_op;
|
|
12 MVMuint8 **interp_bytecode_start;
|
|
13 MVMRegister **interp_reg_base;
|
|
14 MVMCompUnit **interp_cu;
|
|
15 } MVMThreadContext;
|
|
16
|
135
|
17
|
134
|
18 typedef struct interp {
|
|
19 MVMuint16 op;
|
|
20 /* Points to the place in the bytecode right after the current opcode. */
|
|
21 /* See the NEXT_OP macro for making sense of this */
|
|
22 MVMuint8 *cur_op;
|
|
23
|
|
24 /* The current frame's bytecode start. */
|
|
25 MVMuint8 *bytecode_start;
|
|
26
|
|
27 /* Points to the base of the current register set for the frame we
|
|
28 * * are presently in. */
|
|
29 MVMRegister *reg_base;
|
|
30
|
|
31 /* Points to the current compilation unit. */
|
|
32 MVMCompUnit *cu;
|
|
33
|
|
34 /* The current call site we're constructing. */
|
|
35 MVMCallsite *cur_callsite;
|
|
36
|
|
37 MVMThreadContext *tc;
|
|
38
|
135
|
39 //__code (*ret)();
|
|
40 //__code (*main_ret)();
|
134
|
41 __code (*ret)(int, void*);
|
|
42 __code (*main_ret)(int, void*);
|
|
43 void *env;
|
|
44
|
|
45 } INTER,*INTERP;
|
|
46
|
135
|
47 __code cbc_no_op(INTERP);
|
|
48 __code cbc_exit(INTERP);
|
134
|
49
|
135
|
50 __code (* CODES[])(INTERP) = {
|
134
|
51 cbc_no_op,
|
|
52 cbc_no_op,
|
|
53 cbc_exit,
|
|
54 };
|
|
55
|
|
56 __code cbc_next(INTERP i){
|
|
57 __code (*c)(INTERP);
|
|
58 c = CODES[NEXT_OP(i)];
|
|
59 goto c(i);
|
|
60 }
|
|
61
|
135
|
62 __code cbc_no_op(INTERP i){
|
|
63 goto cbc_next(i);
|
|
64 }
|
|
65
|
|
66 __code cbc_exit(INTERP i){
|
|
67 goto i->main_ret(0,i->env);
|
134
|
68 }
|
|
69
|
135
|
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){
|
134
|
79 INTER inter = {0,0,0,0,0,0,0,0,0};
|
|
80 INTERP i = &inter;
|
135
|
81 MVMuint8 cur_op[] = {0,1,1,0,1,2};
|
|
82 // i->ret = main_return;
|
134
|
83 i->main_ret = _CbC_return;
|
|
84 i->env = _CbC_environment;
|
135
|
85 i->cur_op = cur_op;
|
134
|
86
|
|
87 tc->interp_cur_op = &i->cur_op;
|
|
88 tc->interp_bytecode_start = &i->bytecode_start;
|
|
89 tc->interp_reg_base = &i->reg_base;
|
|
90 tc->interp_cu = &i->cu;
|
|
91 goto cbc_next(i);
|
135
|
92 return 0;
|
134
|
93 }
|
135
|
94
|
|
95 int main(int argc, char **argv){
|
|
96 MVMThreadContext tct = {0,0,0,0};
|
|
97 MVMThreadContext* tc = &tct;
|
|
98 interp_run(tc);
|
|
99 }
|