summaryrefslogtreecommitdiffhomepage
path: root/src/vm.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-06-30 14:00:53 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-06-30 22:41:13 +0900
commit99dbcec89c892bc90f36fbf38e46a9ec971e3a77 (patch)
treeb1ccd264473639b8d58d5301c90c204ba62f4aa2 /src/vm.c
parentb2b0329d2983230508fa79766c0651e78f30b99f (diff)
downloadmruby-99dbcec89c892bc90f36fbf38e46a9ec971e3a77.tar.gz
mruby-99dbcec89c892bc90f36fbf38e46a9ec971e3a77.zip
Revert "Remove `OP_EXT[123]` from operands."
This reverts commit fd10c7231906ca48cb35892d2a86460004b62249. I thought it was OK to restrict index value within 1 byte, but in some cases index value could be 16 bits (2 bytes). I had several ideas to address the issue, but reverting `fd10c72` is the easiest way. The biggest reason is `mruby/c` still supports `OP_EXT[123]`, so that they don't need any additional work.
Diffstat (limited to 'src/vm.c')
-rw-r--r--src/vm.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/vm.c b/src/vm.c
index 2b4a21e6c..a8a3f91d7 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1004,7 +1004,7 @@ prepare_tagged_break(mrb_state *mrb, uint32_t tag, const struct RProc *proc, mrb
#ifndef DIRECT_THREADED
#define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) {
-#define CASE(insn,ops) case insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc;
+#define CASE(insn,ops) case insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc; L_ ## insn ## _BODY:
#define NEXT goto L_END_DISPATCH
#define JUMP NEXT
#define END_DISPATCH L_END_DISPATCH:;}}
@@ -1012,7 +1012,7 @@ prepare_tagged_break(mrb_state *mrb, uint32_t tag, const struct RProc *proc, mrb
#else
#define INIT_DISPATCH JUMP; return mrb_nil_value();
-#define CASE(insn,ops) L_ ## insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc;
+#define CASE(insn,ops) L_ ## insn: pc++; FETCH_ ## ops (); mrb->c->ci->pc = pc; L_ ## insn ## _BODY:
#define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn]
#define JUMP NEXT
@@ -1137,11 +1137,7 @@ RETRY_TRY_BLOCK:
NEXT;
}
- CASE(OP_LOADL16, BS) {
- goto op_loadl;
- }
CASE(OP_LOADL, BB) {
- op_loadl:
switch (pool[b].tt) { /* number */
case IREP_TT_INT32:
regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i32);
@@ -1213,11 +1209,6 @@ RETRY_TRY_BLOCK:
NEXT;
}
- CASE(OP_LOADSYM16, BS) {
- SET_SYM_VALUE(regs[a], syms[b]);
- NEXT;
- }
-
CASE(OP_LOADNIL, B) {
SET_NIL_VALUE(regs[a]);
NEXT;
@@ -1616,7 +1607,7 @@ RETRY_TRY_BLOCK:
mrb->c->ci->stack[0] = mrb_nil_value();
a = 0;
c = OP_R_NORMAL;
- goto L_RETURN;
+ goto L_OP_RETURN_BODY;
}
pool = irep->pool;
syms = irep->syms;
@@ -2661,12 +2652,9 @@ RETRY_TRY_BLOCK:
NEXT;
}
- CASE(OP_STRING16, BS) {
- goto op_string;
- }
CASE(OP_STRING, BB) {
size_t len;
- op_string:
+
len = pool[b].tt >> 2;
if (pool[b].tt & IREP_TT_SFLAG) {
regs[a] = mrb_str_new_static(mrb, pool[b].u.str, len);
@@ -2744,18 +2732,6 @@ RETRY_TRY_BLOCK:
c = OP_L_METHOD;
goto L_MAKE_LAMBDA;
}
- CASE(OP_LAMBDA16, BS) {
- c = OP_L_LAMBDA;
- goto L_MAKE_LAMBDA;
- }
- CASE(OP_BLOCK16, BS) {
- c = OP_L_BLOCK;
- goto L_MAKE_LAMBDA;
- }
- CASE(OP_METHOD16, BS) {
- c = OP_L_METHOD;
- goto L_MAKE_LAMBDA;
- }
CASE(OP_RANGE_INC, B) {
mrb_value val = mrb_range_new(mrb, regs[a], regs[a+1], FALSE);
@@ -2811,10 +2787,7 @@ RETRY_TRY_BLOCK:
NEXT;
}
- CASE(OP_EXEC16, BS)
- goto L_EXEC;
CASE(OP_EXEC, BB)
- L_EXEC:
{
mrb_value recv = regs[a];
struct RProc *p;
@@ -2911,6 +2884,37 @@ RETRY_TRY_BLOCK:
NEXT;
}
+ CASE(OP_EXT1, Z) {
+ insn = READ_B();
+ switch (insn) {
+#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _1(); goto L_OP_ ## insn ## _BODY;
+#include "mruby/ops.h"
+#undef OPCODE
+ }
+ pc--;
+ NEXT;
+ }
+ CASE(OP_EXT2, Z) {
+ insn = READ_B();
+ switch (insn) {
+#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _2(); goto L_OP_ ## insn ## _BODY;
+#include "mruby/ops.h"
+#undef OPCODE
+ }
+ pc--;
+ NEXT;
+ }
+ CASE(OP_EXT3, Z) {
+ uint8_t insn = READ_B();
+ switch (insn) {
+#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _3(); goto L_OP_ ## insn ## _BODY;
+#include "mruby/ops.h"
+#undef OPCODE
+ }
+ pc--;
+ NEXT;
+ }
+
CASE(OP_STOP, Z) {
/* stop VM */
CHECKPOINT_RESTORE(RBREAK_TAG_STOP) {