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
+2
View File
@@ -47,6 +47,8 @@ OPCODE(GETMCNST, BB) /* R(a) = R(a)::Syms(b) */
OPCODE(SETMCNST, BB) /* R(a+1)::Syms(b) = R(a) */
OPCODE(GETUPVAR, BBB) /* R(a) = uvget(b,c) */
OPCODE(SETUPVAR, BBB) /* uvset(b,c,R(a)) */
OPCODE(GETIDX, B) /* R(a) = R(a)[R(a+1)] */
OPCODE(SETIDX, B) /* R(a)[R(a+1)] = R(a+2) */
OPCODE(JMP, S) /* pc+=a */
OPCODE(JMPIF, BS) /* if R(a) pc+=b */
OPCODE(JMPNOT, BS) /* if !R(a) pc+=b */