From 55ea0c233efda76bb2315fc4e4fff6a2eca16cd6 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Mon, 2 Oct 2023 20:28:36 -0500 Subject: [PATCH] not really faster. Maybe more clear. --- lunar_wave_vm/src/state.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lunar_wave_vm/src/state.rs b/lunar_wave_vm/src/state.rs index 89682d8..28437c3 100644 --- a/lunar_wave_vm/src/state.rs +++ b/lunar_wave_vm/src/state.rs @@ -541,16 +541,11 @@ impl State { Instruction::AddI (a, b, s_c) => { let v_b = self.reg (b); - let x = if let Some (v_b) = v_b.as_int () - { - Value::from (v_b + s_c as i64) - } - else { - let v_b = v_b.as_float ().unwrap_or_else (|| panic! ("{v_b}")); - Value::from (v_b + f64::from (s_c)) + *self.reg_mut (a) = match v_b { + Value::Integer (v_b) => Value::from (v_b + s_c as i64), + Value::Float (v_b) => Value::from (v_b + s_c as f64), + x => panic! ("{x}"), }; - - *self.reg_mut (a) = x; }, Instruction::Call (a, b, c) => { if self.op_call (a, b, c) { @@ -678,11 +673,11 @@ impl State { Instruction::GetUpVal (a, b) => { let this_func = self.stack_top.register_offset - 1; let closure = match &self.registers [this_func] { - Value::BogusClosure (rc) => rc.clone (), + Value::BogusClosure (rc) => rc, _ => panic! ("Can't do GetUpVal outside a closure"), }; - let b = usize::try_from (b).unwrap (); + let b = usize::try_from (b).unwrap (); let upvalue = match closure.borrow ().upvalues.get (b) { Some (x) => x.clone (),