comparison CbC-examples/c-next.c @ 139:ae07388db637

fix c-next.c segfault
author anatofuz
date Mon, 12 Nov 2018 17:01:46 +0900
parents fc828634a951
children c83ff0b5a2ed
comparison
equal deleted inserted replaced
138:fc828634a951 139:ae07388db637
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;
9 8
10 typedef struct MVMThreadContext { 9 typedef struct MVMThreadContext {
11 MVMuint8 **interp_cur_op; 10 MVMuint8 **interp_cur_op;
12 MVMuint8 **interp_bytecode_start; 11 MVMuint8 **interp_bytecode_start;
13 MVMRegister **interp_reg_base; 12 MVMRegister **interp_reg_base;
34 /* The current call site we're constructing. */ 33 /* The current call site we're constructing. */
35 MVMCallsite *cur_callsite; 34 MVMCallsite *cur_callsite;
36 35
37 MVMThreadContext *tc; 36 MVMThreadContext *tc;
38 37
39 //__code (*ret)();
40 //__code (*main_ret)();
41 __code (*ret)(int, void*);
42 __code (*main_ret)(int, void*); 38 __code (*main_ret)(int, void*);
43 void *env; 39 void *env;
44 40
45 } INTER,*INTERP; 41 } INTER,*INTERP;
46 42
47 __code cbc_no_op(INTERP); 43 __code cbc_no_op(INTERP);
48 __code cbc_exit(INTERP); 44 __code cbc_exit(INTERP);
45 __code cbc_next(INTERP);
49 46
50 __code (* CODES[])(INTERP) = { 47 __code (* CODES[])(INTERP) = {
51 cbc_no_op, 48 cbc_no_op,
52 cbc_no_op, 49 cbc_no_op,
53 cbc_exit, 50 cbc_exit,
65 62
66 __code cbc_exit(INTERP i){ 63 __code cbc_exit(INTERP i){
67 goto i->main_ret(0,i->env); 64 goto i->main_ret(0,i->env);
68 } 65 }
69 66
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 67
78 int interp_run(MVMThreadContext *tc){ 68 int interp_run(MVMThreadContext *tc){
79 INTER inter = {0,0,0,0,0,0,0,0,0}; 69 INTER inter = {0,0,0,0,0,0,0,0};
80 INTERP i = &inter; 70 INTERP i = &inter;
81 MVMuint8 cur_op[] = {0,1,1,0,1,2}; 71 MVMuint16 cur_op[] = {0,1,1,0,1,2};
82 // i->ret = main_return;
83 i->main_ret = _CbC_return; 72 i->main_ret = _CbC_return;
84 i->env = _CbC_environment; 73 i->env = _CbC_environment;
85 i->cur_op = cur_op; 74 i->cur_op = (MVMuint8 *)cur_op;
86 75
87 tc->interp_cur_op = &i->cur_op; 76 tc->interp_cur_op = &i->cur_op;
88 tc->interp_bytecode_start = &i->bytecode_start; 77 tc->interp_bytecode_start = &i->bytecode_start;
89 tc->interp_reg_base = &i->reg_base; 78 tc->interp_reg_base = &i->reg_base;
90 tc->interp_cu = &i->cu; 79 tc->interp_cu = &i->cu;