Skip to content

Commit 06a67da

Browse files
committed
ZJIT: Fix insn arg index for defined, add tests
1 parent 9c44353 commit 06a67da

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ fn main() {
368368
.allowlist_function("rb_iseqw_to_iseq")
369369
.allowlist_function("rb_iseq_label")
370370
.allowlist_function("rb_iseq_line_no")
371+
.allowlist_function("rb_iseq_defined_string")
371372
.allowlist_type("defined_type")
372373

373374
// From builtin.h

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/hir.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,22 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
608608
Ok(())
609609
},
610610
Insn::Snapshot { state } => write!(f, "Snapshot {}", state),
611+
Insn::Defined { op_type, v, .. } => {
612+
// op_type (enum defined_type) printing logic from iseq.c.
613+
// Not sure why rb_iseq_defined_string() isn't exhaustive.
614+
use std::borrow::Cow;
615+
let op_type = *op_type as u32;
616+
let op_type = if op_type == DEFINED_FUNC {
617+
Cow::Borrowed("func")
618+
} else if op_type == DEFINED_REF {
619+
Cow::Borrowed("ref")
620+
} else if op_type == DEFINED_CONST_FROM {
621+
Cow::Borrowed("constant-from")
622+
} else {
623+
String::from_utf8_lossy(unsafe { rb_iseq_defined_string(op_type).as_rstring_byte_slice().unwrap() })
624+
};
625+
write!(f, "Defined {op_type}, {v}")
626+
}
611627
Insn::DefinedIvar { self_val, id, .. } => write!(f, "DefinedIvar {self_val}, :{}", id.contents_lossy().into_owned()),
612628
Insn::GetIvar { self_val, id, .. } => write!(f, "GetIvar {self_val}, :{}", id.contents_lossy().into_owned()),
613629
Insn::SetIvar { self_val, id, val, .. } => write!(f, "SetIvar {self_val}, :{}, {val}", id.contents_lossy().into_owned()),
@@ -2152,9 +2168,10 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
21522168
state.stack_push(fun.push_insn(block, Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(1)) }));
21532169
}
21542170
YARVINSN_defined => {
2171+
// (rb_num_t op_type, VALUE obj, VALUE pushval)
21552172
let op_type = get_arg(pc, 0).as_usize();
2156-
let obj = get_arg(pc, 0);
2157-
let pushval = get_arg(pc, 0);
2173+
let obj = get_arg(pc, 1);
2174+
let pushval = get_arg(pc, 2);
21582175
let v = state.stack_pop()?;
21592176
state.stack_push(fun.push_insn(block, Insn::Defined { op_type, obj, pushval, v }));
21602177
}

0 commit comments

Comments
 (0)