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 typedef void* MVMThreadContext;
|
|
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
|
|
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 (*ret)(int, void*);
|
|
39 __code (*main_ret)(int, void*);
|
|
40 void *env;
|
|
41
|
|
42 } INTER,*INTERP;
|
|
43
|
|
44 __code cbc_no_op(INTERP i){
|
|
45 goto cbc_next(i);
|
|
46 }
|
|
47
|
|
48 __code cbc_exit(INTERP i){
|
|
49 goto i->main_ret(0,i->env);
|
|
50 }
|
|
51
|
|
52 __code (* CODES[])(INTERP) = {
|
|
53 cbc_no_op,
|
|
54 cbc_no_op,
|
|
55 cbc_exit,
|
|
56 };
|
|
57
|
|
58 __code cbc_next(INTERP i){
|
|
59 __code (*c)(INTERP);
|
|
60 c = CODES[NEXT_OP(i)];
|
|
61 goto c(i);
|
|
62 }
|
|
63
|
|
64 int interp_run(MVMThreadContext *tc){
|
|
65 }
|
|
66
|
|
67 int main(int argc, char **argv){
|
|
68 INTER inter = {0,0,0,0,0,0,0,0,0};
|
|
69 INTERP i = &inter;
|
|
70 MVMuint8 cur_ops = {0,1,2,0,3,2};
|
|
71
|
|
72 i->main_ret = _CbC_return;
|
|
73 i->env = _CbC_environment;
|
|
74 i->cur_op = &cur_ops;
|
|
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);
|
|
81 // return 0;
|
|
82 }
|