This commit is contained in:
e.gavrin
2014-07-04 19:08:21 +04:00
parent e3e0167249
commit 7759e4b99f
5 changed files with 39 additions and 52 deletions
+10 -29
View File
@@ -23,37 +23,18 @@
#include "actuators.h" #include "actuators.h"
void void
gen_bytecode (FILE *src_file) gen_bytecode ()
{ {
statement *st; FILE *file = fopen (FILE_NAME, "w+b");
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"); save_op_data(file, get_op_loop_inf (1));
// save_op_data(file, get_op_call_1(0, LED_GREEN));
// OPCODE op0; save_op_data(file, get_op_call_1(0, LED_BLUE));
// save_op_data(file, get_op_call_1(0, LED_ORANGE));
// save_op_loop_inf (file, op0, 1); save_op_data(file, get_op_call_1(0, LED_RED));
// save_op_call_1 (file, op0, 0, LED_GREEN); save_op_data(file, get_op_jmp(0));
// save_op_call_1 (file, op0, 0, LED_BLUE);
// save_op_call_1 (file, op0, 0, LED_ORANGE); fclose (file);
// 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);
} }
void void
+1 -1
View File
@@ -30,7 +30,7 @@ struct
} __int_data; } __int_data;
void gen_bytecode (FILE*); void gen_bytecode ();
void run_int (); void run_int ();
#endif /* INTERPRETER_H */ #endif /* INTERPRETER_H */
+20 -18
View File
@@ -45,45 +45,47 @@ opfunc_op_jmp (OPCODE opdata)
__int_data.pos = opdata.data.jmp.opcode_idx; __int_data.pos = opdata.data.jmp.opcode_idx;
} }
void OPCODE
save_op_jmp (FILE *file, OPCODE opdata, int arg1) get_op_jmp (int arg1)
{ {
if (file == NULL) OPCODE opdata;
{
return;
}
opdata.opfunc_ptr = opfunc_op_jmp; opdata.opfunc_ptr = opfunc_op_jmp;
opdata.data.jmp.opcode_idx = arg1; opdata.data.jmp.opcode_idx = arg1;
fwrite (&opdata, sizeof (OPCODE), 1, file); return opdata;
} }
void OPCODE
save_op_call_1 (FILE *file, OPCODE opdata, int arg1, int arg2) get_op_call_1 (int arg1, int arg2)
{ {
if (file == NULL) OPCODE opdata;
{
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.name_literal_idx = arg1;
opdata.data.call_1.arg1_literal_idx = arg2; 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 void
save_op_loop_inf (FILE *file, OPCODE opdata, int arg1) save_op_data (FILE *file, OPCODE opdata)
{ {
if (file == NULL) if (file == NULL)
{ {
return; return;
} }
opdata.opfunc_ptr = opfunc_loop_inf;
opdata.data.loop_inf.opcode_idx = arg1;
fwrite (&opdata, sizeof (OPCODE), 1, file); fwrite (&opdata, sizeof (OPCODE), 1, file);
} }
+7 -3
View File
@@ -42,6 +42,7 @@ OP_DEF (decl) { };
OP_DEF (decl_func_named) OP_DEF (decl_func_named)
{ {
OP_TYPE_IDX name_literal_idx; OP_TYPE_IDX name_literal_idx;
}; };
OP_DEF (decl_func_anon) { }; OP_DEF (decl_func_anon) { };
@@ -117,9 +118,12 @@ OPCODE{
} }
__packed; __packed;
void save_op_jmp (FILE *, OPCODE, int);
void save_op_call_1 (FILE *, OPCODE, int, int); void save_op_data (FILE *, OPCODE);
void save_op_loop_inf (FILE *, OPCODE, int);
OPCODE get_op_loop_inf (int);
OPCODE get_op_call_1 (int, int);
OPCODE get_op_jmp (int arg1);
#endif /* OPCODES_H */ #endif /* OPCODES_H */
+1 -1
View File
@@ -73,7 +73,7 @@ main (int argc, char **argv)
//gen_bytecode (generated_source); //gen_bytecode (generated_source);
gen_bytecode (file); gen_bytecode (file);
//run_int (); run_int ();
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
fake_exit (); fake_exit ();