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