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