This repository was archived by the owner on Jan 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,17 @@ impl<'borrow_code_lifetime> VM<'borrow_code_lifetime> {
114114 else if self . codes [ self . pc ] == compiler. compile_single ( "OP_IF" ) { self . op_if ( ) ; }
115115 else { panic ! ( "[VM] The opcode is not implemented yet," ) ; }
116116 }
117+ fn get_ifblock_vec ( codes : Vec < i32 > ) -> Vec < Vec < i32 > > {
118+ let compiler = Compiler :: new ( ) ;
119+ match codes. binary_search ( & compiler. compile_single ( "OP_IF" ) ) {
120+ Ok ( value) => {
121+ let after_if = codes. split_at ( value + 1 ) . 1 ;
122+ let codes_in_if_to_endif = after_if. rsplitn ( 2 , |code| * code == compiler. compile_single ( "OP_ENDIF" ) ) ;
123+ codes_in_if_to_endif
124+ } ,
125+ Err ( value) => value,
126+ }
127+ }
117128 fn op_pushnumber ( & mut self , num : i32 ) {
118129 self . stack . push ( num) ;
119130 self . pc += 1 ;
@@ -135,8 +146,6 @@ impl<'borrow_code_lifetime> VM<'borrow_code_lifetime> {
135146 fn op_if ( & mut self ) {
136147 //let = self.codes[self.pc - 2];
137148
138- let after_if = self . codes . split_at ( self . pc + 1 ) . 1 ;
139- let codes_in_if_to_endif = after_if. rsplitn ( 2 , |code| * code == Compiler :: new ( ) . compile_single ( "OP_ENDIF" ) ) ;
140149
141150 //codes_in_if_to_endif.last().unwrap()
142151
You can’t perform that action at this time.
0 commit comments