diff options
Diffstat (limited to 'src/vm.rs')
| -rw-r--r-- | src/vm.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -10,10 +10,13 @@ pub enum Value { pub enum Op { Pop, Constant(Value), + Add, Sub, Mul, Div, + Neg, + Print, Return, } @@ -91,6 +94,15 @@ impl VM { self.stack.push(value); } + Op::Neg => { + let a = self.stack.pop().unwrap(); + match a { + Value::Float(a) => self.stack.push(Value::Float(-a)), + Value::Int(a) => self.stack.push(Value::Int(-a)), + _ => unimplemented!("Cannot negate '{:?}'.", a), + } + } + Op::Add => { let b = self.stack.pop().unwrap(); let a = self.stack.pop().unwrap(); |
