diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-06-30 14:00:53 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-06-30 22:41:13 +0900 |
| commit | 99dbcec89c892bc90f36fbf38e46a9ec971e3a77 (patch) | |
| tree | b1ccd264473639b8d58d5301c90c204ba62f4aa2 | |
| parent | b2b0329d2983230508fa79766c0651e78f30b99f (diff) | |
| download | mruby-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.
| -rw-r--r-- | doc/mruby3.md | 9 | ||||
| -rw-r--r-- | doc/opcode.md | 10 | ||||
| -rw-r--r-- | include/mruby/opcode.h | 30 | ||||
| -rw-r--r-- | include/mruby/ops.h | 10 | ||||
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 159 | ||||
| -rw-r--r-- | src/codedump.c | 255 | ||||
| -rw-r--r-- | src/vm.c | 66 |
7 files changed, 315 insertions, 224 deletions
diff --git a/doc/mruby3.md b/doc/mruby3.md index c5da856d1..a64e3c73e 100644 --- a/doc/mruby3.md +++ b/doc/mruby3.md @@ -111,14 +111,9 @@ $ bin/mruby -r lib1.rb -r lib2.rb < app.mrb `mruby3` introduces a few new instructions. -Instructions that access pool[i]/syms[i] where i>255. - -* `OP_LOADL16` -* `OP_STRING16` -* `OP_LOADSYM16` - -Instructions that load a 32-bit integer. +Instructions that load a 16/32-bit integer. +* `OP_LOADI16` * `OP_LOADI32` Instruction that unwinds jump table for rescue/ensure. diff --git a/doc/opcode.md b/doc/opcode.md index 4e9a3292e..21dc2ef9d 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -27,7 +27,6 @@ sign) of operands. | `OP_NOP` | `-` | `no operation` | | `OP_MOVE` | `BB` | `R(a) = R(b)` | | `OP_LOADL` | `BB` | `R(a) = Pool(b)` | -| `OP_LOADL16` | `BS` | `R(a) = Pool(b)` | | `OP_LOADI` | `BB` | `R(a) = mrb_int(b)` | | `OP_LOADINEG` | `BB` | `R(a) = mrb_int(-b)` | | `OP_LOADI__1` | `B` | `R(a) = mrb_int(-1)` | @@ -42,7 +41,6 @@ sign) of operands. | `OP_LOADI16` | `BS` | `R(a) = mrb_int(b)` | | `OP_LOADI32` | `BSS` | `R(a) = mrb_int((b<<16)+c)` | | `OP_LOADSYM` | `BB` | `R(a) = Syms(b)` | -| `OP_LOADSYM16` | `BS` | `R(a) = Syms(b)` | | `OP_LOADNIL` | `B` | `R(a) = nil` | | `OP_LOADSELF` | `B` | `R(a) = self` | | `OP_LOADT` | `B` | `R(a) = true` | @@ -106,24 +104,19 @@ sign) of operands. | `OP_APOST` | `BBB` | `*R(a),R(a+1)..R(a+c) = R(a)[b..]` | | `OP_INTERN` | `B` | `R(a) = intern(R(a))` | | `OP_STRING` | `BB` | `R(a) = str_dup(Lit(b))` | -| `OP_STRING16` | `BS` | `R(a) = str_dup(Lit(b))` | | `OP_STRCAT` | `B` | `str_cat(R(a),R(a+1))` | | `OP_HASH` | `BB` | `R(a) = hash_new(R(a),R(a+1)..R(a+b*2-1))` | | `OP_HASHADD` | `BB` | `R(a) = hash_push(R(a),R(a+1)..R(a+b*2))` | | `OP_HASHCAT` | `B` | `R(a) = hash_cat(R(a),R(a+1))` | | `OP_LAMBDA` | `BB` | `R(a) = lambda(SEQ[b],OP_L_LAMBDA)` | -| `OP_LAMBDA16` | `BS` | `R(a) = lambda(SEQ[b],OP_L_LAMBDA)` | | `OP_BLOCK` | `BB` | `R(a) = lambda(SEQ[b],OP_L_BLOCK)` | -| `OP_BLOCK16` | `BS` | `R(a) = lambda(SEQ[b],OP_L_BLOCK)` | | `OP_METHOD` | `BB` | `R(a) = lambda(SEQ[b],OP_L_METHOD)` | -| `OP_METHOD16` | `BS` | `R(a) = lambda(SEQ[b],OP_L_METHOD)` | | `OP_RANGE_INC` | `B` | `R(a) = range_new(R(a),R(a+1),FALSE)` | | `OP_RANGE_EXC` | `B` | `R(a) = range_new(R(a),R(a+1),TRUE)` | | `OP_OCLASS` | `B` | `R(a) = ::Object` | | `OP_CLASS` | `BB` | `R(a) = newclass(R(a),Syms(b),R(a+1))` | | `OP_MODULE` | `BB` | `R(a) = newmodule(R(a),Syms(b))` | | `OP_EXEC` | `BB` | `R(a) = blockexec(R(a),SEQ[b])` | -| `OP_EXEC16` | `BS` | `R(a) = blockexec(R(a),SEQ[b])` | | `OP_DEF` | `BB` | `R(a).newmethod(Syms(b),R(a+1))` | | `OP_ALIAS` | `BB` | `alias_method(target_class,Syms(a),Syms(b))` | | `OP_UNDEF` | `B` | `undef_method(target_class,Syms(a))` | @@ -131,5 +124,8 @@ sign) of operands. | `OP_TCLASS` | `B` | `R(a) = target_class` | | `OP_DEBUG` | `BBB` | `print a,b,c` | | `OP_ERR` | `B` | `raise(LocalJumpError, Lit(a))` | +| `OP_EXT1` | `-` | `make 1st operand 16bit` | +| `OP_EXT2` | `-` | `make 2nd operand 16bit` | +| `OP_EXT3` | `-` | `make 1st and 2nd operands 16bit` | | `OP_STOP` | `-` | `stop VM` | |------------------|--------------|--------------------------------------------------------| diff --git a/include/mruby/opcode.h b/include/mruby/opcode.h index 987c5ad8f..249598161 100644 --- a/include/mruby/opcode.h +++ b/include/mruby/opcode.h @@ -40,4 +40,34 @@ enum mrb_insn { #define FETCH_S() do {a=READ_S();} while (0) #define FETCH_W() do {a=READ_W();} while (0) +/* with OP_EXT1 (1st 16bit) */ +#define FETCH_Z_1() FETCH_Z() +#define FETCH_B_1() FETCH_S() +#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0) +#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0) +#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0) +#define FETCH_BSS_1() do {a=READ_S(); b=READ_S();c=READ_S();} while (0) +#define FETCH_S_1() FETCH_S() +#define FETCH_W_1() FETCH_W() + +/* with OP_EXT2 (2nd 16bit) */ +#define FETCH_Z_2() FETCH_Z() +#define FETCH_B_2() FETCH_B() +#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0) +#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0) +#define FETCH_BS_2() FETCH_BS() +#define FETCH_BSS_2() FETCH_BSS() +#define FETCH_S_2() FETCH_S() +#define FETCH_W_2() FETCH_W() + +/* with OP_EXT3 (1st & 2nd 16bit) */ +#define FETCH_Z_3() FETCH_Z() +#define FETCH_B_3() FETCH_B() +#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0) +#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0) +#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0) +#define FETCH_BSS_3() FETCH_BSS_1() +#define FETCH_S_3() FETCH_S() +#define FETCH_W_3() FETCH_W() + #endif /* MRUBY_OPCODE_H */ diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 98f447aab..8d62f007f 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -15,7 +15,6 @@ operation code operands semantics OPCODE(NOP, Z) /* no operation */ OPCODE(MOVE, BB) /* R(a) = R(b) */ OPCODE(LOADL, BB) /* R(a) = Pool(b) */ -OPCODE(LOADL16, BS) /* R(a) = Pool(b) */ OPCODE(LOADI, BB) /* R(a) = mrb_int(b) */ OPCODE(LOADINEG, BB) /* R(a) = mrb_int(-b) */ OPCODE(LOADI__1, B) /* R(a) = mrb_int(-1) */ @@ -30,7 +29,6 @@ OPCODE(LOADI_7, B) /* R(a) = mrb_int(7) */ OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */ OPCODE(LOADI32, BSS) /* R(a) = mrb_int((b<<16)+c) */ OPCODE(LOADSYM, BB) /* R(a) = Syms(b) */ -OPCODE(LOADSYM16, BS) /* R(a) = Syms(b) */ OPCODE(LOADNIL, B) /* R(a) = nil */ OPCODE(LOADSELF, B) /* R(a) = self */ OPCODE(LOADT, B) /* R(a) = true */ @@ -94,24 +92,19 @@ OPCODE(ASET, BBB) /* R(a)[c] = R(b) */ OPCODE(APOST, BBB) /* *R(a),R(a+1)..R(a+c) = R(a)[b..] */ OPCODE(INTERN, B) /* R(a) = intern(R(a)) */ OPCODE(STRING, BB) /* R(a) = str_dup(Pool(b)) */ -OPCODE(STRING16, BS) /* R(a) = str_dup(Pool(b)) */ OPCODE(STRCAT, B) /* str_cat(R(a),R(a+1)) */ OPCODE(HASH, BB) /* R(a) = hash_new(R(a),R(a+1)..R(a+b*2-1)) */ OPCODE(HASHADD, BB) /* R(a) = hash_push(R(a),R(a+1)..R(a+b*2)) */ OPCODE(HASHCAT, B) /* R(a) = hash_cat(R(a),R(a+1)) */ OPCODE(LAMBDA, BB) /* R(a) = lambda(SEQ[b],L_LAMBDA) */ -OPCODE(LAMBDA16, BS) /* R(a) = lambda(SEQ[b],L_LAMBDA) */ OPCODE(BLOCK, BB) /* R(a) = lambda(SEQ[b],L_BLOCK) */ -OPCODE(BLOCK16, BS) /* R(a) = lambda(SEQ[b],L_BLOCK) */ OPCODE(METHOD, BB) /* R(a) = lambda(SEQ[b],L_METHOD) */ -OPCODE(METHOD16, BS) /* R(a) = lambda(SEQ[b],L_METHOD) */ OPCODE(RANGE_INC, B) /* R(a) = range_new(R(a),R(a+1),FALSE) */ OPCODE(RANGE_EXC, B) /* R(a) = range_new(R(a),R(a+1),TRUE) */ OPCODE(OCLASS, B) /* R(a) = ::Object */ OPCODE(CLASS, BB) /* R(a) = newclass(R(a),Syms(b),R(a+1)) */ OPCODE(MODULE, BB) /* R(a) = newmodule(R(a),Syms(b)) */ OPCODE(EXEC, BB) /* R(a) = blockexec(R(a),SEQ[b]) */ -OPCODE(EXEC16, BS) /* R(a) = blockexec(R(a),SEQ[b]) */ OPCODE(DEF, BB) /* R(a).newmethod(Syms(b),R(a+1)) */ OPCODE(ALIAS, BB) /* alias_method(target_class,Syms(a),Syms(b)) */ OPCODE(UNDEF, B) /* undef_method(target_class,Syms(a)) */ @@ -119,4 +112,7 @@ OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */ OPCODE(TCLASS, B) /* R(a) = target_class */ OPCODE(DEBUG, BBB) /* print a,b,c */ OPCODE(ERR, B) /* raise(LocalJumpError, Pool(a)) */ +OPCODE(EXT1, Z) /* make 1st operand (a) 16bit */ +OPCODE(EXT2, Z) /* make 2nd operand (b) 16bit */ +OPCODE(EXT3, Z) /* make 1st and 2nd operands 16bit */ OPCODE(STOP, Z) /* stop VM */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index e429ffc0b..62ed4e77d 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -237,7 +237,9 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a) { s->lastpc = s->pc; if (a > 0xff) { - codegen_error(s, "too big operand"); + gen_B(s, OP_EXT1); + gen_B(s, i); + gen_S(s, a); } else { gen_B(s, i); @@ -249,30 +251,24 @@ static void genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b) { s->lastpc = s->pc; - if (a > 0xff || b > 0xff) { - codegen_error(s, "too big operand"); - } - else { + if (a > 0xff && b > 0xff) { + gen_B(s, OP_EXT3); gen_B(s, i); - gen_B(s, (uint8_t)a); - gen_B(s, (uint8_t)b); - } -} - -/* similar to `genop_2` but generate `genop_2S` with `i+1` */ -/* works for OP_LOADL, OP_LOADSYM, OP_STRING */ -static void -genop_bs(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b) -{ - s->lastpc = s->pc; - if (a > 0xff || b > 0xffff) { - codegen_error(s, "too big operand"); + gen_S(s, a); + gen_S(s, b); } - if (b > 0xff) { - gen_B(s, i+1); + else if (b > 0xff) { + gen_B(s, OP_EXT2); + gen_B(s, i); gen_B(s, (uint8_t)a); gen_S(s, b); } + else if (a > 0xff) { + gen_B(s, OP_EXT1); + gen_B(s, i); + gen_S(s, a); + gen_B(s, (uint8_t)b); + } else { gen_B(s, i); gen_B(s, (uint8_t)a); @@ -341,6 +337,32 @@ mrb_decode_insn(const mrb_code *pc) #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; } @@ -419,8 +441,11 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, uint32_t pc, int val) s->lastpc = s->pc; if (a > 0xff) { - codegen_error(s, "too big operand"); - pos = 0; + gen_B(s, OP_EXT1); + gen_B(s, i); + gen_S(s, a); + pos = s->pc; + gen_S(s, pc); } else { gen_B(s, i); @@ -460,11 +485,9 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep) break; case OP_LOADI: case OP_LOADINEG: case OP_LOADL: case OP_LOADSYM: - case OP_LOADL16: case OP_LOADSYM16: case OP_GETGV: case OP_GETSV: case OP_GETIV: case OP_GETCV: - case OP_GETCONST: case OP_STRING: case OP_STRING16: + case OP_GETCONST: case OP_STRING: case OP_LAMBDA: case OP_BLOCK: case OP_METHOD: case OP_BLKPUSH: - case OP_LAMBDA16: case OP_BLOCK16: case OP_METHOD16: if (nopeep || data.a != src || data.a < s->nlocals) goto normal; s->pc = s->lastpc; genop_2(s, data.insn, dst, data.b); @@ -1667,7 +1690,7 @@ codegen(codegen_scope *s, node *tree, int val) if (val) { int idx = lambda_body(s, tree, 1); - genop_bs(s, OP_LAMBDA, cursp(), idx); + genop_2(s, OP_LAMBDA, cursp(), idx); push(); } break; @@ -1676,7 +1699,7 @@ codegen(codegen_scope *s, node *tree, int val) if (val) { int idx = lambda_body(s, tree, 1); - genop_bs(s, OP_BLOCK, cursp(), idx); + genop_2(s, OP_BLOCK, cursp(), idx); push(); } break; @@ -2535,7 +2558,7 @@ codegen(codegen_scope *s, node *tree, int val) i = readint(s, p, base, &overflow); if (overflow) { int off = new_litbn(s, p, base, FALSE); - genop_bs(s, OP_LOADL, cursp(), off); + genop_2(s, OP_LOADL, cursp(), off); } else { if (i < 0) { @@ -2553,7 +2576,7 @@ codegen(codegen_scope *s, node *tree, int val) int off; lit_int: off = new_lit(s, mrb_int_value(s->mrb, i)); - genop_bs(s, OP_LOADL, cursp(), off); + genop_2(s, OP_LOADL, cursp(), off); } } push(); @@ -2567,7 +2590,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_float f = mrb_float_read(p, NULL); int off = new_lit(s, mrb_float_value(s->mrb, f)); - genop_bs(s, OP_LOADL, cursp(), off); + genop_2(s, OP_LOADL, cursp(), off); push(); } break; @@ -2584,7 +2607,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_float f = mrb_float_read(p, NULL); int off = new_lit(s, mrb_float_value(s->mrb, -f)); - genop_bs(s, OP_LOADL, cursp(), off); + genop_2(s, OP_LOADL, cursp(), off); push(); } break; @@ -2600,7 +2623,7 @@ codegen(codegen_scope *s, node *tree, int val) i = readint(s, p, base, &overflow); if (overflow) { int off = new_litbn(s, p, base, TRUE); - genop_bs(s, OP_LOADL, cursp(), off); + genop_2(s, OP_LOADL, cursp(), off); } else { i = -i; @@ -2616,7 +2639,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { int off = new_lit(s, mrb_int_value(s->mrb, i)); - genop_bs(s, OP_LOADL, cursp(), off); + genop_2(s, OP_LOADL, cursp(), off); } } push(); @@ -2647,7 +2670,7 @@ codegen(codegen_scope *s, node *tree, int val) int off = new_lit(s, mrb_str_new(s->mrb, p, len)); mrb_gc_arena_restore(s->mrb, ai); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); push(); } break; @@ -2734,7 +2757,7 @@ codegen(codegen_scope *s, node *tree, int val) genop_1(s, OP_LOADSELF, cursp()); push(); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); push(); push(); pop_n(3); sym = new_sym(s, MRB_OPSYM_2(s->mrb, tick)); /* ` */ @@ -2757,12 +2780,12 @@ codegen(codegen_scope *s, node *tree, int val) genop_1(s, OP_OCLASS, cursp()); genop_2(s, OP_GETMCNST, cursp(), sym); push(); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); push(); if (p2 || p3) { if (p2) { /* opt */ off = new_lit(s, mrb_str_new_cstr(s->mrb, p2)); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); } else { genop_1(s, OP_LOADNIL, cursp()); @@ -2771,7 +2794,7 @@ codegen(codegen_scope *s, node *tree, int val) argc++; if (p3) { /* enc */ off = new_lit(s, mrb_str_new(s->mrb, p3, 1)); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); push(); argc++; } @@ -2811,7 +2834,7 @@ codegen(codegen_scope *s, node *tree, int val) p = (char*)n->car; off = new_lit(s, mrb_str_new_cstr(s->mrb, p)); codegen(s, tree->car, VAL); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); pop(); genop_1(s, OP_STRCAT, cursp()); push(); @@ -2819,14 +2842,14 @@ codegen(codegen_scope *s, node *tree, int val) if (n->cdr->car) { /* opt */ char *p2 = (char*)n->cdr->car; off = new_lit(s, mrb_str_new_cstr(s->mrb, p2)); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); push(); argc++; } if (n->cdr->cdr) { /* enc */ char *p2 = (char*)n->cdr->cdr; off = new_lit(s, mrb_str_new_cstr(s->mrb, p2)); - genop_bs(s, OP_STRING, cursp(), off); + genop_2(s, OP_STRING, cursp(), off); push(); argc++; } @@ -2853,7 +2876,7 @@ codegen(codegen_scope *s, node *tree, int val) if (val) { int sym = new_sym(s, nsym(tree)); - genop_bs(s, OP_LOADSYM, cursp(), sym); + genop_2(s, OP_LOADSYM, cursp(), sym); push(); } break; @@ -2954,7 +2977,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { idx = scope_body(s, body, val); - genop_bs(s, OP_EXEC, cursp(), idx); + genop_2(s, OP_EXEC, cursp(), idx); } if (val) { push(); @@ -2986,7 +3009,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { idx = scope_body(s, tree->cdr->car, val); - genop_bs(s, OP_EXEC, cursp(), idx); + genop_2(s, OP_EXEC, cursp(), idx); } if (val) { push(); @@ -3007,7 +3030,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { idx = scope_body(s, tree->cdr->car, val); - genop_bs(s, OP_EXEC, cursp(), idx); + genop_2(s, OP_EXEC, cursp(), idx); } if (val) { push(); @@ -3022,12 +3045,12 @@ codegen(codegen_scope *s, node *tree, int val) genop_1(s, OP_TCLASS, cursp()); push(); - genop_bs(s, OP_METHOD, cursp(), idx); + genop_2(s, OP_METHOD, cursp(), idx); push(); pop(); pop(); genop_2(s, OP_DEF, cursp(), sym); if (val) { - genop_bs(s, OP_LOADSYM, cursp(), sym); + genop_2(s, OP_LOADSYM, cursp(), sym); push(); } } @@ -3043,11 +3066,11 @@ codegen(codegen_scope *s, node *tree, int val) pop(); genop_1(s, OP_SCLASS, cursp()); push(); - genop_bs(s, OP_METHOD, cursp(), idx); + genop_2(s, OP_METHOD, cursp(), idx); pop(); genop_2(s, OP_DEF, cursp(), sym); if (val) { - genop_bs(s, OP_LOADSYM, cursp(), sym); + genop_2(s, OP_LOADSYM, cursp(), sym); push(); } } @@ -3360,6 +3383,7 @@ mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep) #define Z 1 #define S 3 #define W 4 +#define OPCODE(_,x) x, /* instruction sizes */ uint8_t mrb_insn_size[] = { #define B 2 @@ -3367,14 +3391,43 @@ uint8_t mrb_insn_size[] = { #define BBB 4 #define BS 4 #define BSS 6 -#define SB 4 -#define OPCODE(_,x) x, #include "mruby/ops.h" -#undef OPCODE #undef B #undef BB +#undef BBB +#undef BS +#undef BSS +}; +/* EXT1 instruction sizes */ +uint8_t mrb_insn_size1[] = { +#define B 3 +#define BB 4 +#define BBB 5 +#define BS 5 +#define BSS 7 +#include "mruby/ops.h" +#undef B #undef BS #undef BSS -#undef SB +}; +/* EXT2 instruction sizes */ +uint8_t mrb_insn_size2[] = { +#define B 2 +#define BS 4 +#define BSS 6 +#include "mruby/ops.h" +#undef B +#undef BB #undef BBB +#undef BS +#undef BSS +}; +/* EXT3 instruction sizes */ +#define B 3 +#define BB 5 +#define BBB 6 +#define BS 5 +#define BSS 7 +uint8_t mrb_insn_size3[] = { +#include "mruby/ops.h" }; diff --git a/src/codedump.c b/src/codedump.c index 0556d724d..4d1d96171 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -57,7 +57,7 @@ print_header(mrb_state *mrb, const mrb_irep *irep, uint32_t i) printf("%03d ", (int)i); } -#define CASE(insn,ops) case insn: FETCH_ ## ops (); +#define CASE(insn,ops) case insn: FETCH_ ## ops (); L_ ## insn static void codedump(mrb_state *mrb, const mrb_irep *irep) @@ -128,17 +128,15 @@ codedump(mrb_state *mrb, const mrb_irep *irep) print_header(mrb, irep, (uint32_t)i); ins = READ_B(); switch (ins) { - CASE(OP_NOP, Z); + CASE(OP_NOP, Z): printf("OP_NOP\n"); break; - CASE(OP_MOVE, BB); + CASE(OP_MOVE, BB): printf("OP_MOVE\tR%d\tR%d\t", a, b); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_LOADL16, BS); - goto op_loadl; - CASE(OP_LOADL, BB); - op_loadl: + + CASE(OP_LOADL, BB): switch (irep->pool[b].tt) { #ifndef MRB_NO_FLOAT case IREP_TT_FLOAT: @@ -159,159 +157,159 @@ codedump(mrb_state *mrb, const mrb_irep *irep) } print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI, BB); + CASE(OP_LOADI, BB): printf("OP_LOADI\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADINEG, BB); + CASE(OP_LOADINEG, BB): printf("OP_LOADI\tR%d\t-%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI16, BS); + CASE(OP_LOADI16, BS): printf("OP_LOADI16\tR%d\t%d\t", a, (int)(int16_t)b); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI32, BSS); + CASE(OP_LOADI32, BSS): printf("OP_LOADI32\tR%d\t%d\t", a, (int32_t)(((uint32_t)b<<16)+c)); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI__1, B); + CASE(OP_LOADI__1, B): printf("OP_LOADI__1\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI_0, B); goto L_LOADI; - CASE(OP_LOADI_1, B); goto L_LOADI; - CASE(OP_LOADI_2, B); goto L_LOADI; - CASE(OP_LOADI_3, B); goto L_LOADI; - CASE(OP_LOADI_4, B); goto L_LOADI; - CASE(OP_LOADI_5, B); goto L_LOADI; - CASE(OP_LOADI_6, B); goto L_LOADI; - CASE(OP_LOADI_7, B); + CASE(OP_LOADI_0, B): goto L_LOADI; + CASE(OP_LOADI_1, B): goto L_LOADI; + CASE(OP_LOADI_2, B): goto L_LOADI; + CASE(OP_LOADI_3, B): goto L_LOADI; + CASE(OP_LOADI_4, B): goto L_LOADI; + CASE(OP_LOADI_5, B): goto L_LOADI; + CASE(OP_LOADI_6, B): goto L_LOADI; + CASE(OP_LOADI_7, B): L_LOADI: printf("OP_LOADI_%d\tR%d\t\t", ins-(int)OP_LOADI_0, a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADSYM16, BS); - goto op_loadsym; - CASE(OP_LOADSYM, BB); - op_loadsym: + CASE(OP_LOADSYM, BB): printf("OP_LOADSYM\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADNIL, B); + CASE(OP_LOADNIL, B): printf("OP_LOADNIL\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADSELF, B); + CASE(OP_LOADSELF, B): printf("OP_LOADSELF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADT, B); + CASE(OP_LOADT, B): printf("OP_LOADT\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADF, B); + CASE(OP_LOADF, B): printf("OP_LOADF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETGV, BB); + CASE(OP_GETGV, BB): printf("OP_GETGV\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETGV, BB); + CASE(OP_SETGV, BB): printf("OP_SETGV\t:%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETSV, BB); + CASE(OP_GETSV, BB): printf("OP_GETSV\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETSV, BB); + CASE(OP_SETSV, BB): printf("OP_SETSV\t:%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETCONST, BB); + CASE(OP_GETCONST, BB): printf("OP_GETCONST\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETCONST, BB); + CASE(OP_SETCONST, BB): printf("OP_SETCONST\t:%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETMCNST, BB); + CASE(OP_GETMCNST, BB): printf("OP_GETMCNST\tR%d\tR%d::%s", a, a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETMCNST, BB); + CASE(OP_SETMCNST, BB): printf("OP_SETMCNST\tR%d::%s\tR%d", a+1, mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETIV, BB); + CASE(OP_GETIV, BB): printf("OP_GETIV\tR%d\t%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETIV, BB); + CASE(OP_SETIV, BB): printf("OP_SETIV\t%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETUPVAR, BBB); + CASE(OP_GETUPVAR, BBB): printf("OP_GETUPVAR\tR%d\t%d\t%d", a, b, c); print_lv_a(mrb, irep, a); break; - CASE(OP_SETUPVAR, BBB); + CASE(OP_SETUPVAR, BBB): printf("OP_SETUPVAR\tR%d\t%d\t%d", a, b, c); print_lv_a(mrb, irep, a); break; - CASE(OP_GETCV, BB); + CASE(OP_GETCV, BB): printf("OP_GETCV\tR%d\t%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETCV, BB); + CASE(OP_SETCV, BB): printf("OP_SETCV\t%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_JMP, S); + CASE(OP_JMP, S): i = pc - irep->iseq; printf("OP_JMP\t\t%03d\n", (int)i+(int16_t)a); break; - CASE(OP_JMPUW, S); + CASE(OP_JMPUW, S): i = pc - irep->iseq; printf("OP_JMPUW\t\t%03d\n", (int)i+(int16_t)a); break; - CASE(OP_JMPIF, BS); + CASE(OP_JMPIF, BS): i = pc - irep->iseq; printf("OP_JMPIF\tR%d\t%03d\t", a, (int)i+(int16_t)b); print_lv_a(mrb, irep, a); break; - CASE(OP_JMPNOT, BS); + CASE(OP_JMPNOT, BS): i = pc - irep->iseq; printf("OP_JMPNOT\tR%d\t%03d\t", a, (int)i+(int16_t)b); print_lv_a(mrb, irep, a); break; - CASE(OP_JMPNIL, BS); + CASE(OP_JMPNIL, BS): i = pc - irep->iseq; printf("OP_JMPNIL\tR%d\t%03d\t", a, (int)i+(int16_t)b); print_lv_a(mrb, irep, a); break; - CASE(OP_SENDV, BB); + CASE(OP_SENDV, BB): printf("OP_SENDV\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_SENDVB, BB); + CASE(OP_SENDVB, BB): printf("OP_SENDVB\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_SEND, BBB); + CASE(OP_SEND, BBB): printf("OP_SEND\tR%d\t:%s\t%d\n", a, mrb_sym_dump(mrb, irep->syms[b]), c); break; - CASE(OP_SENDB, BBB); + CASE(OP_SENDB, BBB): printf("OP_SENDB\tR%d\t:%s\t%d\n", a, mrb_sym_dump(mrb, irep->syms[b]), c); break; - CASE(OP_CALL, Z); + CASE(OP_SENDVK, BB): + printf("OP_SENDVK\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); + break; + CASE(OP_CALL, Z): printf("OP_CALL\n"); break; - CASE(OP_SUPER, BB); + CASE(OP_SUPER, BB): printf("OP_SUPER\tR%d\t%d\n", a, b); break; - CASE(OP_ARGARY, BS); + CASE(OP_ARGARY, BS): printf("OP_ARGARY\tR%d\t%d:%d:%d:%d (%d)", a, (b>>11)&0x3f, (b>>10)&0x1, @@ -320,7 +318,7 @@ codedump(mrb_state *mrb, const mrb_irep *irep) (b>>0)&0xf); print_lv_a(mrb, irep, a); break; - CASE(OP_ENTER, W); + CASE(OP_ENTER, W): printf("OP_ENTER\t%d:%d:%d:%d:%d:%d:%d\n", MRB_ASPEC_REQ(a), MRB_ASPEC_OPT(a), @@ -330,30 +328,30 @@ codedump(mrb_state *mrb, const mrb_irep *irep) MRB_ASPEC_KDICT(a), MRB_ASPEC_BLOCK(a)); break; - CASE(OP_KEY_P, BB); + CASE(OP_KEY_P, BB): printf("OP_KEY_P\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_KEYEND, Z); + CASE(OP_KEYEND, Z): printf("OP_KEYEND\n"); break; - CASE(OP_KARG, BB); + CASE(OP_KARG, BB): printf("OP_KARG\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_RETURN, B); + CASE(OP_RETURN, B): printf("OP_RETURN\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_RETURN_BLK, B); + CASE(OP_RETURN_BLK, B): printf("OP_RETURN_BLK\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_BREAK, B); + CASE(OP_BREAK, B): printf("OP_BREAK\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_BLKPUSH, BS); + CASE(OP_BLKPUSH, BS): printf("OP_BLKPUSH\tR%d\t%d:%d:%d:%d (%d)", a, (b>>11)&0x3f, (b>>10)&0x1, @@ -362,112 +360,100 @@ codedump(mrb_state *mrb, const mrb_irep *irep) (b>>0)&0xf); print_lv_a(mrb, irep, a); break; - CASE(OP_LAMBDA, BB); - printf("OP_LAMBDA\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); - break; - CASE(OP_BLOCK, BB); - printf("OP_BLOCK\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); - break; - CASE(OP_METHOD, BB); - printf("OP_METHOD\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); - break; - CASE(OP_LAMBDA16, BS); + CASE(OP_LAMBDA, BB): printf("OP_LAMBDA\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); break; - CASE(OP_BLOCK16, BS); + CASE(OP_BLOCK, BB): printf("OP_BLOCK\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); break; - CASE(OP_METHOD16, BS); + CASE(OP_METHOD, BB): printf("OP_METHOD\tR%d\tI(%d:%p)\n", a, b, (void*)irep->reps[b]); break; - CASE(OP_RANGE_INC, B); + CASE(OP_RANGE_INC, B): printf("OP_RANGE_INC\tR%d\n", a); break; - CASE(OP_RANGE_EXC, B); + CASE(OP_RANGE_EXC, B): printf("OP_RANGE_EXC\tR%d\n", a); break; - CASE(OP_DEF, BB); + CASE(OP_DEF, BB): printf("OP_DEF\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_UNDEF, B); + CASE(OP_UNDEF, B): printf("OP_UNDEF\t:%s\n", mrb_sym_dump(mrb, irep->syms[a])); break; - CASE(OP_ALIAS, BB); + CASE(OP_ALIAS, BB): printf("OP_ALIAS\t:%s\t%s\n", mrb_sym_dump(mrb, irep->syms[a]), mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_ADD, B); + CASE(OP_ADD, B): printf("OP_ADD\tR%d\tR%d\n", a, a+1); break; - CASE(OP_ADDI, BB); + CASE(OP_ADDI, BB): printf("OP_ADDI\tR%d\t%d\n", a, b); break; - CASE(OP_SUB, B); + CASE(OP_SUB, B): printf("OP_SUB\tR%d\tR%d\n", a, a+1); break; - CASE(OP_SUBI, BB); + CASE(OP_SUBI, BB): printf("OP_SUBI\tR%d\t%d\n", a, b); break; - CASE(OP_MUL, B); + CASE(OP_MUL, B): printf("OP_MUL\tR%d\tR%d\n", a, a+1); break; - CASE(OP_DIV, B); + CASE(OP_DIV, B): printf("OP_DIV\tR%d\tR%d\n", a, a+1); break; - CASE(OP_LT, B); + CASE(OP_LT, B): printf("OP_LT\t\tR%d\tR%d\n", a, a+1); break; - CASE(OP_LE, B); + CASE(OP_LE, B): printf("OP_LE\t\tR%d\tR%d\n", a, a+1); break; - CASE(OP_GT, B); + CASE(OP_GT, B): printf("OP_GT\t\tR%d\tR%d\n", a, a+1); break; - CASE(OP_GE, B); + CASE(OP_GE, B): printf("OP_GE\t\tR%d\tR%d\n", a, a+1); break; - CASE(OP_EQ, B); + CASE(OP_EQ, B): printf("OP_EQ\t\tR%d\tR%d\n", a, a+1); break; - CASE(OP_ARRAY, BB); + CASE(OP_ARRAY, BB): printf("OP_ARRAY\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_ARRAY2, BBB); + CASE(OP_ARRAY2, BBB): printf("OP_ARRAY\tR%d\tR%d\t%d\t", a, b, c); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_ARYCAT, B); + CASE(OP_ARYCAT, B): printf("OP_ARYCAT\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_ARYPUSH, B); + CASE(OP_ARYPUSH, B): printf("OP_ARYPUSH\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_ARYDUP, B); + CASE(OP_ARYDUP, B): printf("OP_ARYDUP\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_AREF, BBB); + CASE(OP_AREF, BBB): printf("OP_AREF\tR%d\tR%d\t%d", a, b, c); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_ASET, BBB); + CASE(OP_ASET, BBB): printf("OP_ASET\tR%d\tR%d\t%d", a, b, c); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_APOST, BBB); + CASE(OP_APOST, BBB): printf("OP_APOST\tR%d\t%d\t%d", a, b, c); print_lv_a(mrb, irep, a); break; - CASE(OP_INTERN, B); + CASE(OP_INTERN, B): printf("OP_INTERN\tR%d", a); print_lv_a(mrb, irep, a); break; - CASE(OP_STRING16, BS); - goto op_string; - CASE(OP_STRING, BB); - op_string: + CASE(OP_STRING, BB): if ((irep->pool[b].tt & IREP_TT_NFLAG) == 0) { printf("OP_STRING\tR%d\tL(%d)\t; %s", a, b, irep->pool[b].u.str); } @@ -476,48 +462,48 @@ codedump(mrb_state *mrb, const mrb_irep *irep) } print_lv_a(mrb, irep, a); break; - CASE(OP_STRCAT, B); + CASE(OP_STRCAT, B): printf("OP_STRCAT\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_HASH, BB); + CASE(OP_HASH, BB): printf("OP_HASH\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_HASHADD, BB); + CASE(OP_HASHADD, BB): printf("OP_HASHADD\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_HASHCAT, B); + CASE(OP_HASHCAT, B): printf("OP_HASHCAT\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_OCLASS, B); + CASE(OP_OCLASS, B): printf("OP_OCLASS\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_CLASS, BB); + CASE(OP_CLASS, BB): printf("OP_CLASS\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_MODULE, BB); + CASE(OP_MODULE, BB): printf("OP_MODULE\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_EXEC, BB); + CASE(OP_EXEC, BB): printf("OP_EXEC\tR%d\tI(%d:%p)", a, b, (void*)irep->reps[b]); print_lv_a(mrb, irep, a); break; - CASE(OP_SCLASS, B); + CASE(OP_SCLASS, B): printf("OP_SCLASS\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_TCLASS, B); + CASE(OP_TCLASS, B): printf("OP_TCLASS\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_ERR, B); + CASE(OP_ERR, B): if ((irep->pool[a].tt & IREP_TT_NFLAG) == 0) { printf("OP_ERR\t%s\n", irep->pool[a].u.str); } @@ -525,27 +511,58 @@ codedump(mrb_state *mrb, const mrb_irep *irep) printf("OP_ERR\tL(%d)\n", a); } break; - CASE(OP_EXCEPT, B); + CASE(OP_EXCEPT, B): printf("OP_EXCEPT\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_RESCUE, BB); + CASE(OP_RESCUE, BB): printf("OP_RESCUE\tR%d\tR%d", a, b); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_RAISEIF, B); + CASE(OP_RAISEIF, B): printf("OP_RAISEIF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_DEBUG, BBB); + CASE(OP_DEBUG, BBB): printf("OP_DEBUG\t%d\t%d\t%d\n", a, b, c); break; - CASE(OP_STOP, Z); + CASE(OP_STOP, Z): printf("OP_STOP\n"); break; + CASE(OP_EXT1, Z): + ins = READ_B(); + printf("OP_EXT1\n"); + print_header(mrb, irep, pc-irep->iseq-2); + switch (ins) { +#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); goto L_OP_ ## i; +#include "mruby/ops.h" +#undef OPCODE + } + break; + CASE(OP_EXT2, Z): + ins = READ_B(); + printf("OP_EXT2\n"); + print_header(mrb, irep, pc-irep->iseq-2); + switch (ins) { +#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); goto L_OP_ ## i; +#include "mruby/ops.h" +#undef OPCODE + } + break; + CASE(OP_EXT3, Z): + ins = READ_B(); + printf("OP_EXT3\n"); + print_header(mrb, irep, pc-irep->iseq-2); + switch (ins) { +#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); goto L_OP_ ## i; +#include "mruby/ops.h" +#undef OPCODE + } + break; + default: printf("OP_unknown (0x%x)\n", ins); break; @@ -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) { |
