mruby/ops.h: add new instructions OP_GETIDX and OP_SETIDX.

Which represent `obj[int]` and `obj[int]=val` respectively where `obj`
is either `string`, `array` or `hash`, so that index access could be
faster. When `obj` is not assumed type or `R(a+1)` is not integer, the
instructions fallback to method calls.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-10-03 17:14:00 +09:00
parent d64d8ca8e4
commit 09336c5d49
5 changed files with 42 additions and 1 deletions
+6
View File
@@ -265,6 +265,12 @@ codedump(mrb_state *mrb, const mrb_irep *irep)
printf("OP_SETCV\t%s\tR%d\t", mrb_sym_dump(mrb, irep->syms[b]), a);
print_lv_a(mrb, irep, a);
break;
CASE(OP_GETIDX, B):
printf("OP_GETIDX\tR%d\tR%d\n", a, a+1);
break;
CASE(OP_SETIDX, B):
printf("OP_SETIDX\tR%d\tR%d\tR%d\n", a, a+1, a+2);
break;
CASE(OP_JMP, S):
i = pc - irep->iseq;
printf("OP_JMP\t\t%03d\n", (int)i+(int16_t)a);