MCPcopy Index your code
hub / github.com/endbasic/endbasic / do_binary_integer_op

Method do_binary_integer_op

core/src/vm/context.rs:520–541  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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.

Callers 10

do_add_integerMethod · 0.80
do_bitwise_andMethod · 0.80
do_bitwise_orMethod · 0.80
do_bitwise_xorMethod · 0.80
do_divide_integerMethod · 0.80
do_modulo_integerMethod · 0.80
do_multiply_integerMethod · 0.80
do_shift_leftMethod · 0.80
do_shift_rightMethod · 0.80
do_subtract_integerMethod · 0.80

Calls 4

parseFunction · 0.85
get_regMethod · 0.80
set_regMethod · 0.80
set_exceptionMethod · 0.80

Tested by

no test coverage detected