diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index aaff75bb2..2ffe68063 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -23,37 +23,18 @@ #include "actuators.h" void -gen_bytecode (FILE *src_file) +gen_bytecode () { - statement *st; - lexer_set_file (src_file); - parser_init (); - st = parser_parse_statement (); - assert (st); - while (st->type != STMT_EOF) - { - //pp_statement (st); - st = parser_parse_statement (); - assert (st); - } - //pp_finish (); + FILE *file = fopen (FILE_NAME, "w+b"); -// 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); -// save_op_call_1 (file, op0, 0, LED_ORANGE); -// save_op_call_1 (file, op0, 0, LED_RED); -// save_op_call_1 (file, op0, 0, LED_GREEN); -// save_op_call_1 (file, op0, 0, LED_BLUE); -// save_op_call_1 (file, op0, 0, LED_ORANGE); -// save_op_call_1 (file, op0, 0, LED_RED); -// save_op_jmp (file, op0, 0); -// -// fclose (file); + save_op_data(file, get_op_loop_inf (1)); + save_op_data(file, get_op_call_1(0, LED_GREEN)); + save_op_data(file, get_op_call_1(0, LED_BLUE)); + save_op_data(file, get_op_call_1(0, LED_ORANGE)); + save_op_data(file, get_op_call_1(0, LED_RED)); + save_op_data(file, get_op_jmp(0)); + + fclose (file); } void diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 0f5a48168..4544e2036 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -30,7 +30,7 @@ struct } __int_data; -void gen_bytecode (FILE*); +void gen_bytecode (); void run_int (); #endif /* INTERPRETER_H */ diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index e8d125819..90261199a 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -45,45 +45,47 @@ opfunc_op_jmp (OPCODE opdata) __int_data.pos = opdata.data.jmp.opcode_idx; } -void -save_op_jmp (FILE *file, OPCODE opdata, int arg1) +OPCODE +get_op_jmp (int arg1) { - if (file == NULL) - { - return; - } + OPCODE opdata; opdata.opfunc_ptr = opfunc_op_jmp; opdata.data.jmp.opcode_idx = arg1; - fwrite (&opdata, sizeof (OPCODE), 1, file); + return opdata; } -void -save_op_call_1 (FILE *file, OPCODE opdata, int arg1, int arg2) +OPCODE +get_op_call_1 (int arg1, int arg2) { - if (file == NULL) - { - return; - } + OPCODE opdata; opdata.opfunc_ptr = opfunc_op_call_1; opdata.data.call_1.name_literal_idx = arg1; opdata.data.call_1.arg1_literal_idx = arg2; - fwrite (&opdata, sizeof (OPCODE), 1, file); + return opdata; +} + +OPCODE +get_op_loop_inf (int arg1) +{ + OPCODE opdata; + + opdata.opfunc_ptr = opfunc_op_call_1; + opdata.data.loop_inf.opcode_idx = arg1; + + return opdata; } void -save_op_loop_inf (FILE *file, OPCODE opdata, int arg1) +save_op_data (FILE *file, OPCODE opdata) { if (file == NULL) { return; } - opdata.opfunc_ptr = opfunc_loop_inf; - opdata.data.loop_inf.opcode_idx = arg1; - fwrite (&opdata, sizeof (OPCODE), 1, file); } \ No newline at end of file diff --git a/src/libcoreint/opcodes.h b/src/libcoreint/opcodes.h index 21a0c9b5f..c304ab0d7 100644 --- a/src/libcoreint/opcodes.h +++ b/src/libcoreint/opcodes.h @@ -42,6 +42,7 @@ OP_DEF (decl) { }; OP_DEF (decl_func_named) { OP_TYPE_IDX name_literal_idx; + }; OP_DEF (decl_func_anon) { }; @@ -117,9 +118,12 @@ OPCODE{ } __packed; -void save_op_jmp (FILE *, OPCODE, int); -void save_op_call_1 (FILE *, OPCODE, int, int); -void save_op_loop_inf (FILE *, OPCODE, int); + +void save_op_data (FILE *, OPCODE); + +OPCODE get_op_loop_inf (int); +OPCODE get_op_call_1 (int, int); +OPCODE get_op_jmp (int arg1); #endif /* OPCODES_H */ diff --git a/src/main.c b/src/main.c index 9bb7b5cf6..0c0ba42e0 100644 --- a/src/main.c +++ b/src/main.c @@ -73,7 +73,7 @@ main (int argc, char **argv) //gen_bytecode (generated_source); gen_bytecode (file); - //run_int (); + run_int (); #ifdef __TARGET_MCU fake_exit ();