diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 2be1beb3f..2c2a090f7 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -39,9 +39,9 @@ gen_bytecode (FILE *src_file) pp_finish (); FILE *file = fopen (FILE_NAME, "w+b"); - + OPCODE op0; - + save_op_loop_inf (file, op0, 1); save_op_call_1 (file, op0, 0, LED_GREEN); save_op_call_1 (file, op0, 0, LED_BLUE); @@ -61,6 +61,8 @@ run_int () { FILE *file = fopen (FILE_NAME, "rb"); OPCODE op_curr; + __int_data.pos = 0; + if (file == NULL) { @@ -74,8 +76,11 @@ run_int () { break; } - + + __int_data.pos++; + op_curr.opfunc_ptr (op_curr); + fseek (file, __int_data.pos * sizeof (OPCODE), SEEK_SET); } fclose (file); diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index ca0410143..0f5a48168 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -24,8 +24,14 @@ #define FILE_NAME "application.bin" -void gen_bytecode(FILE*); -void run_int(); +struct +{ + int pos; +} __int_data; + + +void gen_bytecode (FILE*); +void run_int (); #endif /* INTERPRETER_H */ diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index dba9c4397..e8d125819 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -14,6 +14,7 @@ */ #include "opcodes.h" +#include "interpreter.h" #include #include @@ -23,6 +24,8 @@ opfunc_loop_inf (OPCODE opdata) { printf ("loop_inf:idx:%d\n", opdata.data.loop_inf.opcode_idx); + + __int_data.pos = opdata.data.loop_inf.opcode_idx; } void @@ -38,11 +41,10 @@ opfunc_op_jmp (OPCODE opdata) { printf ("op_jmp:idx:%d\n", opdata.data.jmp.opcode_idx); + + __int_data.pos = opdata.data.jmp.opcode_idx; } - - - void save_op_jmp (FILE *file, OPCODE opdata, int arg1) { @@ -65,7 +67,7 @@ save_op_call_1 (FILE *file, OPCODE opdata, int arg1, int arg2) return; } - opdata.opfunc_ptr = opfunc_op_call_1; + opdata.opfunc_ptr = opfunc_op_call_1; opdata.data.call_1.name_literal_idx = arg1; opdata.data.call_1.arg1_literal_idx = arg2; @@ -79,7 +81,7 @@ save_op_loop_inf (FILE *file, OPCODE opdata, int arg1) { return; } - + opdata.opfunc_ptr = opfunc_loop_inf; opdata.data.loop_inf.opcode_idx = arg1;