This commit is contained in:
e.gavrin
2014-07-04 23:51:42 +04:00
parent aace544c55
commit 2091bfb9e4
6 changed files with 49 additions and 80 deletions
+16 -39
View File
@@ -18,54 +18,31 @@
void void
gen_bytecode () gen_bytecode ()
{ {
#ifdef __HOST __int_data.pos = 0;
FILE *file = fopen (FILE_NAME, "w+b");
#endif
//TODO REMOVE save_op_data (getop_loop_inf (1));
{ save_op_data (getop_call_1 (0, 12));
save_op_data (file, get_op_loop_inf (1)); save_op_data (getop_call_1 (0, 13));
save_op_data (file, get_op_call_1 (0, 12)); save_op_data (getop_call_1 (0, 14));
save_op_data (file, get_op_call_1 (0, 13)); save_op_data (getop_call_1 (0, 15));
save_op_data (file, get_op_call_1 (0, 14)); //save_op_data (getop_jmp (0));
save_op_data (file, get_op_call_1 (0, 15));
save_op_data (file, get_op_jmp (0)); // mandatory! #ifdef __MCU
} // It's mandatory to restart app!
save_op_data (getop_jmp (0));
#ifdef __HOST
fclose (file);
#endif #endif
} }
void void
run_int () run_int ()
{ {
OPCODE op_curr;
__int_data.pos = 0; __int_data.pos = 0;
printf("size%d", sizeof(OPCODE));
#ifdef __HOST while (true)
FILE *file = fopen (FILE_NAME, "rb");
if (file == NULL)
{ {
fputs ("File error", stderr); OPCODE *curr = &__program[__int_data.pos];
exit (1); curr->opfunc_ptr (*curr);
} }
while (!feof (file))
{
if (!fread (&op_curr, sizeof (OPCODE), 1, file))
{
break;
}
__int_data.pos++;
op_curr.opfunc_ptr (op_curr);
fseek (file, __int_data.pos * sizeof (OPCODE), SEEK_SET);
}
fclose (file);
#endif
} }
+2 -2
View File
@@ -20,12 +20,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define FILE_NAME "application.bin"
#endif #endif
#include "opcodes.h" #include "opcodes.h"
OPCODE __program[20];
struct struct
{ {
int pos; int pos;
+6 -2
View File
@@ -16,6 +16,11 @@
#ifndef OPCODE_STRUCTURES_H #ifndef OPCODE_STRUCTURES_H
#define OPCODE_STRUCTURES_H #define OPCODE_STRUCTURES_H
// Jerry bytecode ver:07/04/2014
//
#define OP_TYPE_IDX uint8_t
OP_DEF (nop) { }; OP_DEF (nop) { };
OP_DEF (jmp) OP_DEF (jmp)
@@ -27,8 +32,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) { };
+17 -26
View File
@@ -17,30 +17,17 @@
#include "interpreter.h" #include "interpreter.h"
void void
#ifdef __HOST
save_op_data (FILE *file, OPCODE opdata)
#elif __MCU
save_op_data (OPCODE opdata) save_op_data (OPCODE opdata)
#endif
{ {
#ifdef __HOST __program[__int_data.pos++] = opdata;
if (file == NULL)
{
return;
}
fwrite (&opdata, sizeof (OPCODE), 1, file);
#elif __MCU
JERRY_STATIC_ASSERT (false);
#endif
} }
void void
opfunc_loop_inf (OPCODE opdata) opfunc_loop_inf (OPCODE opdata)
{ {
#ifdef __HOST #ifdef __HOST
printf ("loop_inf:idx:%d\n", printf ("%d::loop_inf:idx:%d\n",
__int_data.pos,
opdata.data.loop_inf.opcode_idx); opdata.data.loop_inf.opcode_idx);
#endif #endif
@@ -48,20 +35,24 @@ opfunc_loop_inf (OPCODE opdata)
} }
void void
opfunc_op_call_1 (OPCODE opdata) opfunc_call_1 (OPCODE opdata)
{ {
#ifdef __HOST #ifdef __HOST
printf ("op_call_1:idx:%d:%d\n", printf ("%d::op_call_1:idx:%d:%d\n",
__int_data.pos,
opdata.data.call_1.name_literal_idx, opdata.data.call_1.name_literal_idx,
opdata.data.call_1.arg1_literal_idx); opdata.data.call_1.arg1_literal_idx);
#endif #endif
__int_data.pos++;
} }
void void
opfunc_op_jmp (OPCODE opdata) opfunc_jmp (OPCODE opdata)
{ {
#ifdef __HOST #ifdef __HOST
printf ("op_jmp:idx:%d\n", printf ("%d::op_jmp:idx:%d\n",
__int_data.pos,
opdata.data.jmp.opcode_idx); opdata.data.jmp.opcode_idx);
#endif #endif
@@ -69,22 +60,22 @@ opfunc_op_jmp (OPCODE opdata)
} }
OPCODE OPCODE
get_op_jmp (int arg1) getop_jmp (int arg1)
{ {
OPCODE opdata; OPCODE opdata;
opdata.opfunc_ptr = opfunc_op_jmp; opdata.opfunc_ptr = opfunc_jmp;
opdata.data.jmp.opcode_idx = arg1; opdata.data.jmp.opcode_idx = arg1;
return opdata; return opdata;
} }
OPCODE OPCODE
get_op_call_1 (int arg1, int arg2) getop_call_1 (int arg1, int arg2)
{ {
OPCODE opdata; OPCODE opdata;
opdata.opfunc_ptr = opfunc_op_call_1; opdata.opfunc_ptr = opfunc_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;
@@ -92,11 +83,11 @@ get_op_call_1 (int arg1, int arg2)
} }
OPCODE OPCODE
get_op_loop_inf (int arg1) getop_loop_inf (int arg1)
{ {
OPCODE opdata; OPCODE opdata;
opdata.opfunc_ptr = opfunc_op_call_1; opdata.opfunc_ptr = opfunc_loop_inf;
opdata.data.loop_inf.opcode_idx = arg1; opdata.data.loop_inf.opcode_idx = arg1;
return opdata; return opdata;
+6 -9
View File
@@ -26,8 +26,6 @@
#define OP_DEF(name) struct __op_##name #define OP_DEF(name) struct __op_##name
#define OP(name) struct __op_##name name #define OP(name) struct __op_##name name
#define OP_TYPE_IDX uint8_t
OPCODE; OPCODE;
typedef void (*opfunc)(OPCODE); typedef void (*opfunc)(OPCODE);
@@ -51,16 +49,15 @@ OPCODE{
} }
__packed; __packed;
#ifdef __HOST
void save_op_data (FILE*, OPCODE);
#elif __MCU
void save_op_data (OPCODE); void save_op_data (OPCODE);
#endif
void opfunc_loop_inf (OPCODE);
void opfunc_call_1 (OPCODE);
void opfunc_jmp (OPCODE);
OPCODE get_op_loop_inf (int); OPCODE getop_loop_inf (int);
OPCODE get_op_call_1 (int, int); OPCODE getop_call_1 (int, int);
OPCODE get_op_jmp (int arg1); OPCODE getop_jmp (int arg1);
#endif /* OPCODES_H */ #endif /* OPCODES_H */
+2 -2
View File
@@ -72,8 +72,8 @@ main (int argc, char **argv)
} }
//gen_bytecode (generated_source); //gen_bytecode (generated_source);
gen_bytecode (file); gen_bytecode ();
// run_int (); run_int ();
#ifdef __TARGET_MCU #ifdef __TARGET_MCU
fake_exit (); fake_exit ();