fixup! New bytecode implementation of mruby VM.

parent 49d1b168
......@@ -445,108 +445,8 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
break;
default:
goto normal;
=======
struct mrb_insn_data {
uint8_t insn;
uint16_t a;
uint16_t b;
uint8_t c;
};
struct mrb_insn_data
mrb_decode_insn(codegen_scope *s, mrb_code *pc)
{
struct mrb_insn_data data = { 0 };
mrb_code insn = READ_B();
uint16_t a = 0;
uint16_t b = 0;
uint8_t c = 0;
switch (insn) {
#define FETCH_Z() /* empty */
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break;
#include "mruby/ops.h"
#undef OPCODE
}
switch (insn) {
case OP_EXT1:
insn = READ_B();
switch (insn) {
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break;
case OP_EXT2:
insn = READ_B();
switch (insn) {
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break;
case OP_EXT3:
insn = READ_B();
switch (insn) {
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break;
default:
break;
}
data.insn = insn;
data.a = a;
data.b = b;
data.c = c;
return data;
}
struct mrb_insn_data
mrb_last_insn(codegen_scope *s)
{
if (s->pc == s->lastpc) {
struct mrb_insn_data data;
data.insn = OP_NOP;
return data;
}
return mrb_decode_insn(s, &s->iseq[s->lastpc]);
}
static mrb_bool
no_peephole(codegen_scope *s)
{
return no_optimize(s) || s->lastlabel == s->pc || s->pc == 0 || s->pc == s->lastpc;
}
static uint16_t
genjmp(codegen_scope *s, mrb_code i, uint16_t pc)
{
uint16_t pos;
s->lastpc = s->pc;
gen_B(s, i);
pos = s->pc;
gen_S(s, pc);
return pos;
}
static uint16_t
genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
{
uint16_t pos;
if (!no_peephole(s) && !val) {
struct mrb_insn_data data = mrb_last_insn(s);
if (data.insn == OP_MOVE && data.a == a) {
s->pc = s->lastpc;
a = data.b;
}
}
return genop(s, i);
}
static void
......
......@@ -1069,16 +1069,6 @@ RETRY_TRY_BLOCK:
NEXT;
}
CASE(OP_LOADI, BB) {
SET_INT_VALUE(regs[a], b);
NEXT;
}
CASE(OP_LOADINEG, BB) {
SET_INT_VALUE(regs[a], -b);
NEXT;
}
CASE(OP_LOADI__1,B) goto L_LOADI;
CASE(OP_LOADI_0,B) goto L_LOADI;
CASE(OP_LOADI_1,B) goto L_LOADI;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment