diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-07T23·32+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-12T13·24+0000 |
commit | 72be759e1e3ec9c84ef3f2f15d54662efa7b0c03 (patch) | |
tree | 49778caae847d77a7e2dee132b4fb8ea73b33f6b /tvix/eval/src/vm.rs | |
parent | d35ecc0caf2d6ba54b5934f606796687303275b0 (diff) |
feat(tvix/eval): implement unary negation operator r/4411
Change-Id: I5d012cc073e55d79d7b34b88283aab3164864293 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6075 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r-- | tvix/eval/src/vm.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 077acfcc1b8d..da79867ef3f0 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -81,6 +81,18 @@ impl VM { NumberPair::Integer(i1, i2) => self.push(Value::Integer(i1 / i2)), }, + OpCode::OpNegate => match self.pop() { + Value::Integer(i) => self.push(Value::Integer(-i)), + Value::Float(f) => self.push(Value::Float(-f)), + v => { + return Err(Error::TypeError { + expected: "number (either int or float)", + actual: v.type_of(), + }) + } + }, + + OpCode::OpInvert => todo!(), OpCode::OpNull => todo!(), OpCode::OpTrue => todo!(), OpCode::OpFalse => todo!(), |