about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/interpret/value.rs15
-rw-r--r--src/interpret/walker.rs5
-rw-r--r--src/parse/ast/nodes.rs2
3 files changed, 17 insertions, 5 deletions
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<Value> {
+        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<Value> {
+        match self {
+            Value::Bool(bool) => Ok(Value::Bool(bool)),
+            _ => Err(anyhow!("Can't flip non-bool value.")),
+        }
+    }
 }
 
 impl Display for Value {
diff --git a/src/interpret/walker.rs b/src/interpret/walker.rs
index e04b5a4..7684747 100644
--- a/src/interpret/walker.rs
+++ b/src/interpret/walker.rs
@@ -87,9 +87,8 @@ impl Walker {
                 let value = self.walk_expression(right)?;
 
                 let new_value = match op {
-                    UnOp::Plus => value,
-                    UnOp::Minus => todo!(),
-                    UnOp::Not => todo!("Implement boolean arithmetic."),
+                    UnOp::Minus => value.neg()?,
+                    UnOp::Not => value.not()?,
                 };
 
                 Ok(new_value)
diff --git a/src/parse/ast/nodes.rs b/src/parse/ast/nodes.rs
index 36b15c8..822ffb6 100644
--- a/src/parse/ast/nodes.rs
+++ b/src/parse/ast/nodes.rs
@@ -42,7 +42,6 @@ impl BinaryOperator {
 
 #[derive(Debug, Clone, Copy)]
 pub enum UnaryOperator {
-    Plus,
     Minus,
     Not,
 }
@@ -50,7 +49,6 @@ pub enum UnaryOperator {
 impl UnaryOperator {
     pub fn from_token(token: Token) -> Self {
         match token.variant {
-            OpPlus => Self::Plus,
             OpMinus => Self::Minus,
             OpNot => Self::Not,
             _ => panic!("Can't create unary operator from '{:?}'.", token.variant),