feat(tvix/eval): implement unary negation operator
Change-Id: I5d012cc073e55d79d7b34b88283aab3164864293 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6075 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
d35ecc0caf
commit
72be759e1e
3 changed files with 35 additions and 1 deletions
|
|
@ -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!(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue