Mercurial > hg > CbC > CbC_gcc
annotate CbC-examples/c-next.c @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 8f4e72ab4e11 |
children |
rev | line source |
---|---|
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 | |
143 | 27 * are presently in. */ |
134 | 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); |
143 | 46 __code cbc_gc(INTERP); |
134 | 47 |
135 | 48 __code (* CODES[])(INTERP) = { |
134 | 49 cbc_no_op, |
50 cbc_no_op, | |
143 | 51 cbc_gc, |
134 | 52 cbc_exit, |
53 }; | |
54 | |
143 | 55 void gc(int * p, INTERP i){ |
56 i->reg_base = (MVMRegister *)p; | |
57 return; | |
58 } | |
59 | |
60 __code cbc_gc(INTERP i){ | |
61 int test = 3; | |
62 gc(&test,i); | |
63 goto cbc_next(i); | |
64 } | |
65 | |
134 | 66 __code cbc_next(INTERP i){ |
67 __code (*c)(INTERP); | |
68 c = CODES[NEXT_OP(i)]; | |
143 | 69 // c(i); |
134 | 70 goto c(i); |
71 } | |
72 | |
135 | 73 __code cbc_no_op(INTERP i){ |
74 goto cbc_next(i); | |
75 } | |
76 | |
77 __code cbc_exit(INTERP i){ | |
78 goto i->main_ret(0,i->env); | |
134 | 79 } |
80 | |
135 | 81 |
82 int interp_run(MVMThreadContext *tc){ | |
144
8f4e72ab4e11
fix segmentation fault caused by nothing next cur_op to end
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
83 INTER inter = {0,0,0,0,0,0,0,0,0}; |
134 | 84 INTERP i = &inter; |
144
8f4e72ab4e11
fix segmentation fault caused by nothing next cur_op to end
Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
85 MVMuint16 cur_op[] = {0,1,1,0,1,2,3}; |
134 | 86 i->main_ret = _CbC_return; |
87 i->env = _CbC_environment; | |
139 | 88 i->cur_op = (MVMuint8 *)cur_op; |
134 | 89 |
90 tc->interp_cur_op = &i->cur_op; | |
91 tc->interp_bytecode_start = &i->bytecode_start; | |
92 tc->interp_reg_base = &i->reg_base; | |
93 tc->interp_cu = &i->cu; | |
94 goto cbc_next(i); | |
135 | 95 return 0; |
134 | 96 } |
135 | 97 |
98 int main(int argc, char **argv){ | |
99 MVMThreadContext tct = {0,0,0,0}; | |
100 MVMThreadContext* tc = &tct; | |
101 interp_run(tc); | |
102 } |