Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Commit 802f6ef

Browse files
committed
flatten op_else
1 parent 8008827 commit 802f6ef

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ 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-
}
128117
fn op_pushnumber(&mut self, num: i32){
129118
self.stack.push(num);
130119
self.pc += 1;
@@ -146,6 +135,20 @@ impl<'borrow_code_lifetime> VM<'borrow_code_lifetime> {
146135
fn op_if(&mut self){
147136
//let = self.codes[self.pc - 2];
148137

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"));
140+
141+
{
142+
let mut count_op_if = 0;
143+
let mut count_op_endif = 0;
144+
for code in codes_in_if_to_endif {
145+
if code == Compiler::new().compile_single("OP_IF") {
146+
count_op_if+=1;
147+
} else if code == Compiler::new().compile_single("OP_ENDIF") {
148+
count_op_endif+=1;
149+
}
150+
}
151+
}
149152

150153
//codes_in_if_to_endif.last().unwrap()
151154

0 commit comments

Comments
 (0)