aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-14 11:19:16 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-14 11:22:07 -0700
commit661927a4c55232bd070992d47670a7d411820111 (patch)
treeffae82f9d9ebeb977d6a4958fdffed7182e8f99b
parent6ac6de84ac3a5bc4fae8e04d03084696080e1ab2 (diff)
downloadruby-661927a4c55232bd070992d47670a7d411820111.tar.gz
Switch to using a VM stack argument instead of 2nd operand for getconstant
Some tooling depends on the current bytecode, and adding an operand changes the bytecode. While tooling can be updated for new bytecode, this support doesn't warrant such a change.
-rw-r--r--compile.c21
-rw-r--r--insns.def6
2 files changed, 17 insertions, 10 deletions
diff --git a/compile.c b/compile.c
index f9b57c710d..26b580b090 100644
--- a/compile.c
+++ b/compile.c
@@ -4404,18 +4404,21 @@ compile_const_prefix(rb_iseq_t *iseq, const NODE *const node,
switch (nd_type(node)) {
case NODE_CONST:
debugi("compile_const_prefix - colon", node->nd_vid);
- ADD_INSN2(body, nd_line(node), getconstant, ID2SYM(node->nd_vid), Qtrue);
+ ADD_INSN1(body, nd_line(node), putobject, Qtrue);
+ ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_vid));
break;
case NODE_COLON3:
debugi("compile_const_prefix - colon3", node->nd_mid);
ADD_INSN(body, nd_line(node), pop);
ADD_INSN1(body, nd_line(node), putobject, rb_cObject);
- ADD_INSN2(body, nd_line(node), getconstant, ID2SYM(node->nd_mid), Qtrue);
+ ADD_INSN1(body, nd_line(node), putobject, Qtrue);
+ ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid));
break;
case NODE_COLON2:
CHECK(compile_const_prefix(iseq, node->nd_head, pref, body));
debugi("compile_const_prefix - colon2", node->nd_mid);
- ADD_INSN2(body, nd_line(node), getconstant, ID2SYM(node->nd_mid), Qfalse);
+ ADD_INSN1(body, nd_line(node), putobject, Qfalse);
+ ADD_INSN1(body, nd_line(node), getconstant, ID2SYM(node->nd_mid));
break;
default:
CHECK(COMPILE(pref, "const colon2 prefix", node));
@@ -7154,7 +7157,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
ADD_INSNL(ret, line, branchunless, lassign); /* cref */
}
ADD_INSN(ret, line, dup); /* cref cref */
- ADD_INSN2(ret, line, getconstant, ID2SYM(mid), Qtrue); /* cref obj */
+ ADD_INSN1(ret, line, putobject, Qtrue);
+ ADD_INSN1(ret, line, getconstant, ID2SYM(mid)); /* cref obj */
if (node->nd_aid == idOROP || node->nd_aid == idANDOP) {
lfin = NEW_LABEL(line);
@@ -7500,13 +7504,15 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
int ic_index = body->is_size++;
ADD_INSN2(ret, line, opt_getinlinecache, lend, INT2FIX(ic_index));
- ADD_INSN2(ret, line, getconstant, ID2SYM(node->nd_vid), Qtrue);
+ ADD_INSN1(ret, line, putobject, Qtrue);
+ ADD_INSN1(ret, line, getconstant, ID2SYM(node->nd_vid));
ADD_INSN1(ret, line, opt_setinlinecache, INT2FIX(ic_index));
ADD_LABEL(ret, lend);
}
else {
ADD_INSN(ret, line, putnil);
- ADD_INSN2(ret, line, getconstant, ID2SYM(node->nd_vid), Qtrue);
+ ADD_INSN1(ret, line, putobject, Qtrue);
+ ADD_INSN1(ret, line, getconstant, ID2SYM(node->nd_vid));
}
if (popped) {
@@ -7893,7 +7899,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
}
ADD_INSN1(ret, line, putobject, rb_cObject);
- ADD_INSN2(ret, line, getconstant, ID2SYM(node->nd_mid), Qtrue);
+ ADD_INSN1(ret, line, putobject, Qtrue);
+ ADD_INSN1(ret, line, getconstant, ID2SYM(node->nd_mid));
if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
ADD_INSN1(ret, line, opt_setinlinecache, INT2FIX(ic_index));
diff --git a/insns.def b/insns.def
index 77ffa81abf..02330147c4 100644
--- a/insns.def
+++ b/insns.def
@@ -252,14 +252,14 @@ setclassvariable
rb_cvar_set(vm_get_cvar_base(vm_get_cref(GET_EP()), GET_CFP()), id, val);
}
-/* Get constant variable id. If klass is Qnil and allow_nil is true, constants
+/* Get constant variable id. If klass is Qnil and allow_nil is Qtrue, constants
are searched in the current scope. Otherwise, get constant under klass
class or module.
*/
DEFINE_INSN
getconstant
-(ID id, VALUE allow_nil)
-(VALUE klass)
+(ID id)
+(VALUE klass, VALUE allow_nil)
(VALUE val)
/* getconstant can kick autoload */
// attr bool leaf = false; /* has rb_autoload_load() */