From b7e8406f6cf7f8f83fe9594d06c0861e4068241b Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 3 Nov 2020 14:58:44 +0900 Subject: Add new instructions to handle symbols/literals >255; fix #5109 New instructions: * OP_LOADL16 * OP_LOADSYM16 * OP_STRING16 Size of pools, symbols are `int16_t` but offset representation in the bytecode was 8 bits. Size of child `irep` array is `int16_t`, too but this change does not address it. --- src/codedump.c | 9 +++++++++ src/vm.c | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/codedump.c b/src/codedump.c index dcc196973..9af609264 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -135,7 +135,10 @@ codedump(mrb_state *mrb, const mrb_irep *irep) 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: switch (irep->pool[b].tt) { case IREP_TT_FLOAT: printf("OP_LOADL\tR%d\tL(%d)\t; %f", a, b, (double)irep->pool[b].u.f); @@ -182,7 +185,10 @@ codedump(mrb_state *mrb, const mrb_irep *irep) 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: printf("OP_LOADSYM\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; @@ -438,7 +444,10 @@ codedump(mrb_state *mrb, const mrb_irep *irep) 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: 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); } diff --git a/src/vm.c b/src/vm.c index bcb78c0c9..1d6f82249 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1069,7 +1069,12 @@ 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); @@ -1138,6 +1143,11 @@ 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; @@ -2575,8 +2585,13 @@ RETRY_TRY_BLOCK: NEXT; } + CASE(OP_STRING16, BS) { + goto op_string; + } CASE(OP_STRING, BB) { - size_t len = pool[b].tt >> 2; + 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); } -- cgit v1.2.3