Applies a binary integer operation using `parse` to decode the instruction and `op` to compute the result. `op` returns `Err` with a message on failure.
(
&mut self,
instr: u32,
parse: fn(u32) -> (Register, Register, Register),
op: F,
)
| 518 | /// Applies a binary integer operation using `parse` to decode the instruction and `op` to |
| 519 | /// compute the result. `op` returns `Err` with a message on failure. |
| 520 | fn do_binary_integer_op<F, E>( |
| 521 | &mut self, |
| 522 | instr: u32, |
| 523 | parse: fn(u32) -> (Register, Register, Register), |
| 524 | op: F, |
| 525 | ) where |
| 526 | F: Fn(i32, i32) -> Result<i32, E>, |
| 527 | E: ToString, |
| 528 | { |
| 529 | let (dest, src1, src2) = parse(instr); |
| 530 | let lhs = self.get_reg(src1) as i32; |
| 531 | let rhs = self.get_reg(src2) as i32; |
| 532 | match op(lhs, rhs) { |
| 533 | Ok(result) => { |
| 534 | self.set_reg(dest, result as u64); |
| 535 | self.pc += 1; |
| 536 | } |
| 537 | Err(msg) => { |
| 538 | self.set_exception(msg.to_string()); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | /// Applies a binary integer predicate using `parse` to decode the instruction and `op` to |
| 544 | /// compute the result. |
no test coverage detected