# HG changeset patch # User kono # Date 1541627579 -32400 # Node ID 71d4882a9ac3a3462c43d976004c0a4a17d7a101 # Parent 420680fc7707c3ec4216e525becf8a2e9d97858c add cbc-example diff -r 420680fc7707 -r 71d4882a9ac3 CbC-examples/Makefile --- a/CbC-examples/Makefile Sat Nov 03 19:49:09 2018 +0900 +++ b/CbC-examples/Makefile Thu Nov 08 06:52:59 2018 +0900 @@ -1,4 +1,4 @@ -TEST = arg.exe conv1.exe fact-a.exe goto.exe loto6.exe stack1.exe test02.exe test05.exe test1.exe test2.exe test_cs.exe test_csp1.exe test_env.exe test_func2code.exe test_para2.exe test_para3.exe test_para4.exe test_para.exe test_tree.exe tmp1.exe tmp2.exe tmp4.exe tmpa.exe too-long-argument.exe +TEST = arg.exe conv1.exe fact-a.exe goto.exe loto6.exe stack1.exe test02.exe test05.exe test1.exe test2.exe test_cs.exe test_csp1.exe test_func2code.exe test_para2.exe test_para3.exe test_para4.exe test_para.exe test_tree.exe tmp1.exe tmp2.exe tmp4.exe tmpa.exe too-long-argument.exe .SUFFIXES: .exe @@ -9,3 +9,6 @@ for exe in ${TEST} ; do \ ./$${exe} ; \ done + +clean : + rm -f ${TEST} diff -r 420680fc7707 -r 71d4882a9ac3 CbC-examples/c-next.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/c-next.c Thu Nov 08 06:52:59 2018 +0900 @@ -0,0 +1,82 @@ +#define NEXT_OP(i) (i->op = *(MVMuint16 *)(i->cur_op), i->cur_op += 2, i->op) + +typedef unsigned short MVMuint16; +typedef unsigned char MVMuint8; +typedef long* MVMRegister; +typedef void* MVMCompUnit; +typedef void* MVMCallsite; +typedef void* MVMThreadContext; + +typedef struct MVMThreadContext { + MVMuint8 **interp_cur_op; + MVMuint8 **interp_bytecode_start; + MVMRegister **interp_reg_base; + MVMCompUnit **interp_cu; +} MVMThreadContext; + +typedef struct interp { + MVMuint16 op; + /* Points to the place in the bytecode right after the current opcode. */ + /* See the NEXT_OP macro for making sense of this */ + MVMuint8 *cur_op; + + /* The current frame's bytecode start. */ + MVMuint8 *bytecode_start; + + /* Points to the base of the current register set for the frame we + * * are presently in. */ + MVMRegister *reg_base; + + /* Points to the current compilation unit. */ + MVMCompUnit *cu; + + /* The current call site we're constructing. */ + MVMCallsite *cur_callsite; + + MVMThreadContext *tc; + + __code (*ret)(int, void*); + __code (*main_ret)(int, void*); + void *env; + + } INTER,*INTERP; + +__code cbc_no_op(INTERP i){ + goto cbc_next(i); +} + +__code cbc_exit(INTERP i){ + goto i->main_ret(0,i->env); +} + + __code (* CODES[])(INTERP) = { + cbc_no_op, + cbc_no_op, + cbc_exit, +}; + +__code cbc_next(INTERP i){ + __code (*c)(INTERP); + c = CODES[NEXT_OP(i)]; + goto c(i); +} + +int interp_run(MVMThreadContext *tc){ +} + +int main(int argc, char **argv){ + INTER inter = {0,0,0,0,0,0,0,0,0}; + INTERP i = &inter; + MVMuint8 cur_ops = {0,1,2,0,3,2}; + + i->main_ret = _CbC_return; + i->env = _CbC_environment; + i->cur_op = &cur_ops; + + tc->interp_cur_op = &i->cur_op; + tc->interp_bytecode_start = &i->bytecode_start; + tc->interp_reg_base = &i->reg_base; + tc->interp_cu = &i->cu; + goto cbc_next(i); + // return 0; +}