diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-01 16:07:48 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-01 16:20:58 +0900 |
| commit | d759a73525f2bff367433454e4d2851f7c193693 (patch) | |
| tree | 8b6007bb9a1d90e0a46a0b21cb124147f9eddfec /mrbgems | |
| parent | bd6b48fa3b352bbcb97463dcb95e30db37bff2e4 (diff) | |
| download | mruby-d759a73525f2bff367433454e4d2851f7c193693.tar.gz mruby-d759a73525f2bff367433454e4d2851f7c193693.zip | |
Allow more than 256 child `irep`; fix #5310
We have introduced following new instructions.
* `OP_LAMBDA16`
* `OP_BLOCK16`
* `OP_METHOD16`
* `OP_EXEC16`
Each instruction uses 16 bits operand for `reps` index. Since new
instructions are added, `mruby/c` VM should be updated.
Due to new instructions, dump format compatibility is lost, we have
increased `RITE_BINARY_MAJOR_VER`.
In addition, we have decreased the size of `refcnt` in `mrb_irep` from
`uint32_t` to `uint16_t`, which is reasonably big enough.
Diffstat (limited to 'mrbgems')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 0d7f615e0..555479a7e 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -464,6 +464,7 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep) case OP_GETGV: case OP_GETSV: case OP_GETIV: case OP_GETCV: case OP_GETCONST: case OP_STRING: case OP_STRING16: 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); @@ -1630,7 +1631,7 @@ codegen(codegen_scope *s, node *tree, int val) if (val) { int idx = lambda_body(s, tree, 1); - genop_2(s, OP_LAMBDA, cursp(), idx); + genop_bs(s, OP_LAMBDA, cursp(), idx); push(); } break; @@ -1639,7 +1640,7 @@ codegen(codegen_scope *s, node *tree, int val) if (val) { int idx = lambda_body(s, tree, 1); - genop_2(s, OP_BLOCK, cursp(), idx); + genop_bs(s, OP_BLOCK, cursp(), idx); push(); } break; @@ -2910,7 +2911,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { idx = scope_body(s, body, val); - genop_2(s, OP_EXEC, cursp(), idx); + genop_bs(s, OP_EXEC, cursp(), idx); } if (val) { push(); @@ -2942,7 +2943,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { idx = scope_body(s, tree->cdr->car, val); - genop_2(s, OP_EXEC, cursp(), idx); + genop_bs(s, OP_EXEC, cursp(), idx); } if (val) { push(); @@ -2963,7 +2964,7 @@ codegen(codegen_scope *s, node *tree, int val) } else { idx = scope_body(s, tree->cdr->car, val); - genop_2(s, OP_EXEC, cursp(), idx); + genop_bs(s, OP_EXEC, cursp(), idx); } if (val) { push(); @@ -2978,7 +2979,7 @@ codegen(codegen_scope *s, node *tree, int val) genop_1(s, OP_TCLASS, cursp()); push(); - genop_2(s, OP_METHOD, cursp(), idx); + genop_bs(s, OP_METHOD, cursp(), idx); push(); pop(); pop(); genop_2(s, OP_DEF, cursp(), sym); @@ -2999,7 +3000,7 @@ codegen(codegen_scope *s, node *tree, int val) pop(); genop_1(s, OP_SCLASS, cursp()); push(); - genop_2(s, OP_METHOD, cursp(), idx); + genop_bs(s, OP_METHOD, cursp(), idx); pop(); genop_2(s, OP_DEF, cursp(), sym); if (val) { @@ -3032,7 +3033,7 @@ scope_add_irep(codegen_scope *s) return; } else { - if (prev->irep->rlen == UINT8_MAX) { + if (prev->irep->rlen == UINT16_MAX) { codegen_error(s, "too many nested blocks/methods"); } s->irep = irep = mrb_add_irep(s->mrb); |
