mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-13 09:49:11 +03:00
wasm_interp: remove unnecessary and confusing ELSE check
This commit is contained in:
parent
0009e65d93
commit
df972a4567
@ -196,16 +196,10 @@ impl<'a> ExecutionState<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_break(&mut self, relative_blocks_outward: u32, module: &WasmModule<'a>, op: OpCode) {
|
fn do_break(&mut self, relative_blocks_outward: u32, module: &WasmModule<'a>) {
|
||||||
let maybe_loop = if matches!(op, OpCode::ELSE) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
let block_index = self.block_loop_addrs.len() - 1 - relative_blocks_outward as usize;
|
let block_index = self.block_loop_addrs.len() - 1 - relative_blocks_outward as usize;
|
||||||
self.block_loop_addrs[block_index].map(|addr| (block_index, addr))
|
match self.block_loop_addrs[block_index] {
|
||||||
};
|
Some(addr) => {
|
||||||
|
|
||||||
match maybe_loop {
|
|
||||||
Some((block_index, addr)) => {
|
|
||||||
self.block_loop_addrs.truncate(block_index + 1);
|
self.block_loop_addrs.truncate(block_index + 1);
|
||||||
self.program_counter = addr as usize;
|
self.program_counter = addr as usize;
|
||||||
}
|
}
|
||||||
@ -301,7 +295,7 @@ impl<'a> ExecutionState<'a> {
|
|||||||
// We only reach this point when we finish executing the "then" block of an IF statement
|
// We only reach this point when we finish executing the "then" block of an IF statement
|
||||||
// (For a false condition, we would have skipped past the ELSE when we saw the IF)
|
// (For a false condition, we would have skipped past the ELSE when we saw the IF)
|
||||||
// We don't want to execute the ELSE block, so we skip it, just like `br 0` would.
|
// We don't want to execute the ELSE block, so we skip it, just like `br 0` would.
|
||||||
self.do_break(0, module, op_code);
|
self.do_break(0, module);
|
||||||
}
|
}
|
||||||
END => {
|
END => {
|
||||||
if self.block_loop_addrs.is_empty() {
|
if self.block_loop_addrs.is_empty() {
|
||||||
@ -313,13 +307,13 @@ impl<'a> ExecutionState<'a> {
|
|||||||
}
|
}
|
||||||
BR => {
|
BR => {
|
||||||
let relative_blocks_outward = self.fetch_immediate_u32(module);
|
let relative_blocks_outward = self.fetch_immediate_u32(module);
|
||||||
self.do_break(relative_blocks_outward, module, op_code);
|
self.do_break(relative_blocks_outward, module);
|
||||||
}
|
}
|
||||||
BRIF => {
|
BRIF => {
|
||||||
let relative_blocks_outward = self.fetch_immediate_u32(module);
|
let relative_blocks_outward = self.fetch_immediate_u32(module);
|
||||||
let condition = self.value_stack.pop_i32();
|
let condition = self.value_stack.pop_i32();
|
||||||
if condition != 0 {
|
if condition != 0 {
|
||||||
self.do_break(relative_blocks_outward, module, op_code);
|
self.do_break(relative_blocks_outward, module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BRTABLE => {
|
BRTABLE => {
|
||||||
@ -334,7 +328,7 @@ impl<'a> ExecutionState<'a> {
|
|||||||
}
|
}
|
||||||
let fallback = self.fetch_immediate_u32(module);
|
let fallback = self.fetch_immediate_u32(module);
|
||||||
let relative_blocks_outward = selected.unwrap_or(fallback);
|
let relative_blocks_outward = selected.unwrap_or(fallback);
|
||||||
self.do_break(relative_blocks_outward, module, op_code);
|
self.do_break(relative_blocks_outward, module);
|
||||||
}
|
}
|
||||||
RETURN => {
|
RETURN => {
|
||||||
action = self.do_return();
|
action = self.do_return();
|
||||||
|
Loading…
Reference in New Issue
Block a user