diff --git a/src/instruction.rs b/src/instruction.rs index 21c2ba0..6eb7647 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -40,6 +40,7 @@ pub enum OpCode { GetObj, SetObj, Addi, + Subi, GetIter, GetIterk, GetIteri, diff --git a/src/vm.rs b/src/vm.rs index 403749d..01215a8 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -1186,6 +1186,39 @@ impl VM { } pc += 1; } + OpCode::Subi => { + let val_b = self + .activation_records + .get_mut(sp + inst.b as usize) + .unwrap() + .clone(); + if let Record::Val(Value::Number(n)) = val_b { + self.activation_records[sp + inst.a as usize] = Record::Val(Value::Number(NumberValue { + n: n.n - inst.c as f64 + })); + } else { + match val_b + .as_val() + .sub(&mut Value::Number(NumberValue { n: inst.c as f64 })) + { + Ok(v) => { + self.activation_records[sp + inst.a as usize] = Record::Val(v); + } + Err(e) => { + throw_exception!( + self, + this, + original_instructions, + original_instructions_data, + pc, + sp, + e + ); + } + } + } + pc += 1; + } OpCode::GetIter => { let val_b = self .activation_records