@@ -606,6 +606,22 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
606606 Ok ( ( ) )
607607 } ,
608608 Insn :: Snapshot { state } => write ! ( f, "Snapshot {}" , state) ,
609+ Insn :: Defined { op_type, v, .. } => {
610+ // op_type (enum defined_type) printing logic from iseq.c.
611+ // Not sure why rb_iseq_defined_string() isn't exhaustive.
612+ use std:: borrow:: Cow ;
613+ let op_type = * op_type as u32 ;
614+ let op_type = if op_type == DEFINED_FUNC {
615+ Cow :: Borrowed ( "func" )
616+ } else if op_type == DEFINED_REF {
617+ Cow :: Borrowed ( "ref" )
618+ } else if op_type == DEFINED_CONST_FROM {
619+ Cow :: Borrowed ( "constant-from" )
620+ } else {
621+ String :: from_utf8_lossy ( unsafe { rb_iseq_defined_string ( op_type) . as_rstring_byte_slice ( ) . unwrap ( ) } )
622+ } ;
623+ write ! ( f, "Defined {op_type}, {v}" )
624+ }
609625 Insn :: DefinedIvar { self_val, id, .. } => write ! ( f, "DefinedIvar {self_val}, :{}" , id. contents_lossy( ) . into_owned( ) ) ,
610626 Insn :: GetIvar { self_val, id, .. } => write ! ( f, "GetIvar {self_val}, :{}" , id. contents_lossy( ) . into_owned( ) ) ,
611627 Insn :: SetIvar { self_val, id, val, .. } => write ! ( f, "SetIvar {self_val}, :{}, {val}" , id. contents_lossy( ) . into_owned( ) ) ,
@@ -2165,9 +2181,10 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
21652181 state. stack_push ( fun. push_insn ( block, Insn :: Const { val : Const :: Value ( VALUE :: fixnum_from_usize ( 1 ) ) } ) ) ;
21662182 }
21672183 YARVINSN_defined => {
2184+ // (rb_num_t op_type, VALUE obj, VALUE pushval)
21682185 let op_type = get_arg ( pc, 0 ) . as_usize ( ) ;
2169- let obj = get_arg ( pc, 0 ) ;
2170- let pushval = get_arg ( pc, 0 ) ;
2186+ let obj = get_arg ( pc, 1 ) ;
2187+ let pushval = get_arg ( pc, 2 ) ;
21712188 let v = state. stack_pop ( ) ?;
21722189 state. stack_push ( fun. push_insn ( block, Insn :: Defined { op_type, obj, pushval, v } ) ) ;
21732190 }
0 commit comments