From 09336c5d49481d56587f6e28924014954b4c8dd2 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 3 Oct 2021 17:14:00 +0900 Subject: 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. --- include/mruby/ops.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 9b9fefeb0..7b5ea40ca 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -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 */ -- cgit v1.2.3