From 32a04f1e677cfa2b4f62a2c1db358588b78d593d Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 23 Oct 2021 00:38:57 +0200 Subject: Remove Plus unary op and implement other unary ops --- src/interpret/value.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/interpret/value.rs') diff --git a/src/interpret/value.rs b/src/interpret/value.rs index c0ac96e..27f2668 100644 --- a/src/interpret/value.rs +++ b/src/interpret/value.rs @@ -148,6 +148,21 @@ impl Value { _ => Err(anyhow!("Left operand can't be compared.")), } } + + pub fn neg(self) -> Result { + match self { + Value::Float(float) => Ok(Value::Float(-float)), + Value::Int(int) => Ok(Value::Int(-int)), + _ => Err(anyhow!("Can't negate value.")), + } + } + + pub fn not(self) -> Result { + match self { + Value::Bool(bool) => Ok(Value::Bool(bool)), + _ => Err(anyhow!("Can't flip non-bool value.")), + } + } } impl Display for Value { -- cgit 1.4.1