Mercurial > hg > CbC > CbC_gcc
comparison CbC-examples/c-next.c @ 135:d23615825742
fix _CbC_return for c-next.c
author | anatofuz |
---|---|
date | Thu, 08 Nov 2018 14:06:47 +0900 |
parents | 71d4882a9ac3 |
children | fc828634a951 |
comparison
equal
deleted
inserted
replaced
134:71d4882a9ac3 | 135:d23615825742 |
---|---|
3 typedef unsigned short MVMuint16; | 3 typedef unsigned short MVMuint16; |
4 typedef unsigned char MVMuint8; | 4 typedef unsigned char MVMuint8; |
5 typedef long* MVMRegister; | 5 typedef long* MVMRegister; |
6 typedef void* MVMCompUnit; | 6 typedef void* MVMCompUnit; |
7 typedef void* MVMCallsite; | 7 typedef void* MVMCallsite; |
8 typedef void* MVMThreadContext; | 8 //typedef void* MVMThreadContext; |
9 | 9 |
10 typedef struct MVMThreadContext { | 10 typedef struct MVMThreadContext { |
11 MVMuint8 **interp_cur_op; | 11 MVMuint8 **interp_cur_op; |
12 MVMuint8 **interp_bytecode_start; | 12 MVMuint8 **interp_bytecode_start; |
13 MVMRegister **interp_reg_base; | 13 MVMRegister **interp_reg_base; |
14 MVMCompUnit **interp_cu; | 14 MVMCompUnit **interp_cu; |
15 } MVMThreadContext; | 15 } MVMThreadContext; |
16 | |
16 | 17 |
17 typedef struct interp { | 18 typedef struct interp { |
18 MVMuint16 op; | 19 MVMuint16 op; |
19 /* Points to the place in the bytecode right after the current opcode. */ | 20 /* Points to the place in the bytecode right after the current opcode. */ |
20 /* See the NEXT_OP macro for making sense of this */ | 21 /* See the NEXT_OP macro for making sense of this */ |
33 /* The current call site we're constructing. */ | 34 /* The current call site we're constructing. */ |
34 MVMCallsite *cur_callsite; | 35 MVMCallsite *cur_callsite; |
35 | 36 |
36 MVMThreadContext *tc; | 37 MVMThreadContext *tc; |
37 | 38 |
39 //__code (*ret)(); | |
40 //__code (*main_ret)(); | |
38 __code (*ret)(int, void*); | 41 __code (*ret)(int, void*); |
39 __code (*main_ret)(int, void*); | 42 __code (*main_ret)(int, void*); |
40 void *env; | 43 void *env; |
41 | 44 |
42 } INTER,*INTERP; | 45 } INTER,*INTERP; |
43 | 46 |
44 __code cbc_no_op(INTERP i){ | 47 __code cbc_no_op(INTERP); |
45 goto cbc_next(i); | 48 __code cbc_exit(INTERP); |
46 } | |
47 | 49 |
48 __code cbc_exit(INTERP i){ | 50 __code (* CODES[])(INTERP) = { |
49 goto i->main_ret(0,i->env); | |
50 } | |
51 | |
52 __code (* CODES[])(INTERP) = { | |
53 cbc_no_op, | 51 cbc_no_op, |
54 cbc_no_op, | 52 cbc_no_op, |
55 cbc_exit, | 53 cbc_exit, |
56 }; | 54 }; |
57 | 55 |
59 __code (*c)(INTERP); | 57 __code (*c)(INTERP); |
60 c = CODES[NEXT_OP(i)]; | 58 c = CODES[NEXT_OP(i)]; |
61 goto c(i); | 59 goto c(i); |
62 } | 60 } |
63 | 61 |
64 int interp_run(MVMThreadContext *tc){ | 62 __code cbc_no_op(INTERP i){ |
63 goto cbc_next(i); | |
65 } | 64 } |
66 | 65 |
67 int main(int argc, char **argv){ | 66 __code cbc_exit(INTERP i){ |
67 goto i->main_ret(0,i->env); | |
68 } | |
69 | |
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){ | |
68 INTER inter = {0,0,0,0,0,0,0,0,0}; | 79 INTER inter = {0,0,0,0,0,0,0,0,0}; |
69 INTERP i = &inter; | 80 INTERP i = &inter; |
70 MVMuint8 cur_ops = {0,1,2,0,3,2}; | 81 MVMuint8 cur_op[] = {0,1,1,0,1,2}; |
71 | 82 // i->ret = main_return; |
72 i->main_ret = _CbC_return; | 83 i->main_ret = _CbC_return; |
73 i->env = _CbC_environment; | 84 i->env = _CbC_environment; |
74 i->cur_op = &cur_ops; | 85 i->cur_op = cur_op; |
75 | 86 |
76 tc->interp_cur_op = &i->cur_op; | 87 tc->interp_cur_op = &i->cur_op; |
77 tc->interp_bytecode_start = &i->bytecode_start; | 88 tc->interp_bytecode_start = &i->bytecode_start; |
78 tc->interp_reg_base = &i->reg_base; | 89 tc->interp_reg_base = &i->reg_base; |
79 tc->interp_cu = &i->cu; | 90 tc->interp_cu = &i->cu; |
80 goto cbc_next(i); | 91 goto cbc_next(i); |
81 // return 0; | 92 return 0; |
82 } | 93 } |
94 | |
95 int main(int argc, char **argv){ | |
96 MVMThreadContext tct = {0,0,0,0}; | |
97 MVMThreadContext* tc = &tct; | |
98 interp_run(tc); | |
99 } |