@@ -608,6 +608,22 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
608
608
Ok ( ( ) )
609
609
} ,
610
610
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
+ }
611
627
Insn :: DefinedIvar { self_val, id, .. } => write ! ( f, "DefinedIvar {self_val}, :{}" , id. contents_lossy( ) . into_owned( ) ) ,
612
628
Insn :: GetIvar { self_val, id, .. } => write ! ( f, "GetIvar {self_val}, :{}" , id. contents_lossy( ) . into_owned( ) ) ,
613
629
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> {
2152
2168
state. stack_push ( fun. push_insn ( block, Insn :: Const { val : Const :: Value ( VALUE :: fixnum_from_usize ( 1 ) ) } ) ) ;
2153
2169
}
2154
2170
YARVINSN_defined => {
2171
+ // (rb_num_t op_type, VALUE obj, VALUE pushval)
2155
2172
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 ) ;
2158
2175
let v = state. stack_pop ( ) ?;
2159
2176
state. stack_push ( fun. push_insn ( block, Insn :: Defined { op_type, obj, pushval, v } ) ) ;
2160
2177
}
0 commit comments