11// We use the YARV bytecode constants which have a CRuby-style name
22#![ allow( non_upper_case_globals) ]
33
4- use crate :: { cruby:: * , get_option, options:: DumpSSA } ;
4+ use crate :: {
5+ cruby:: * ,
6+ get_option,
7+ options:: DumpSSA
8+ } ;
59use std:: collections:: { HashMap , HashSet } ;
610
711#[ derive( Copy , Clone , Eq , PartialEq , Hash , Debug ) ]
@@ -85,6 +89,7 @@ pub enum Insn {
8589 NewArray { count : usize } ,
8690 ArraySet { idx : usize , val : Opnd } ,
8791 ArrayDup { val : Opnd } ,
92+
8893 // Check if the value is truthy and "return" a C boolean. In reality, we will likely fuse this
8994 // with IfTrue/IfFalse in the backend to generate jcc.
9095 Test { val : Opnd } ,
@@ -108,7 +113,8 @@ pub enum Insn {
108113 IfFalse { val : Opnd , target : BranchEdge } ,
109114
110115 // Call a C function
111- // TODO: should we store the C function name?
116+ // NOTE: should we store the C function name for pretty-printing?
117+ // or can we backtranslate the function pointer into a name string?
112118 CCall { cfun : * const u8 , args : Vec < Opnd > } ,
113119
114120 // Send with dynamic dispatch
@@ -277,11 +283,12 @@ impl std::fmt::Display for FrameState {
277283 }
278284}
279285
280- /// Get instruction argument
286+ /// Get YARV instruction argument
281287fn get_arg ( pc : * const VALUE , arg_idx : isize ) -> VALUE {
282288 unsafe { * ( pc. offset ( arg_idx + 1 ) ) }
283289}
284290
291+ /// Compute YARV instruction index at relative offset
285292fn insn_idx_at_offset ( idx : u32 , offset : i64 ) -> u32 {
286293 ( ( idx as isize ) + ( offset as isize ) ) as u32
287294}
0 commit comments