about summary refs log tree commit diff
path: root/src/interpret
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-10-20 22:15:08 +0200
committerMel <einebeere@gmail.com>2021-10-20 22:15:08 +0200
commita4980b8dbf1394c2b302f1de7c72d2264426b86e (patch)
tree97160332c53d8036ea3f6865ff60dabb2c55ef49 /src/interpret
parent8d5a74566beba45f4642838102c5a066ef2aa18d (diff)
downloadrabbithole-a4980b8dbf1394c2b302f1de7c72d2264426b86e.tar.zst
rabbithole-a4980b8dbf1394c2b302f1de7c72d2264426b86e.zip
Statement parsing.
Diffstat (limited to 'src/interpret')
-rw-r--r--src/interpret/walker.rs43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/interpret/walker.rs b/src/interpret/walker.rs
index e301d44..817e94e 100644
--- a/src/interpret/walker.rs
+++ b/src/interpret/walker.rs
@@ -3,7 +3,10 @@ use std::{
     ops::{Add, Div, Mul, Neg, Sub},
 };
 
-use crate::{lex::token::TokenVariant::*, parse::ast::Expression};
+use crate::parse::ast::{
+    expression::Expression,
+    value::{BinaryOperator, Literal, UnaryOperator},
+};
 use anyhow::Result;
 
 // No state for now.
@@ -20,12 +23,20 @@ impl Walker {
                 let left_value = self.walk(left)?;
                 let right_value = self.walk(right)?;
 
-                let new_value = match op.variant {
-                    OpPlus => left_value + right_value,
-                    OpMinus => left_value - right_value,
-                    OpStar => left_value * right_value,
-                    OpSlash => left_value / right_value,
-                    _ => unreachable!(),
+                let new_value = match op {
+                    BinaryOperator::Plus => left_value + right_value,
+                    BinaryOperator::Minus => left_value - right_value,
+                    BinaryOperator::Star => left_value * right_value,
+                    BinaryOperator::Slash => left_value / right_value,
+                    BinaryOperator::Eq => todo!(),
+                    BinaryOperator::Neq => todo!(),
+                    BinaryOperator::Gt => todo!(),
+                    BinaryOperator::Gte => todo!(),
+                    BinaryOperator::Lt => todo!(),
+                    BinaryOperator::Lte => todo!(),
+                    BinaryOperator::Assign => todo!(),
+                    BinaryOperator::ConstAssign => todo!(),
+                    BinaryOperator::Dot => todo!(),
                 };
 
                 Ok(new_value)
@@ -33,25 +44,25 @@ impl Walker {
             Expression::Unary { op, right } => {
                 let value = self.walk(right)?;
 
-                let new_value = match op.variant {
-                    OpPlus => value,
-                    OpMinus => -value,
-                    OpNot => todo!("Implement boolean arithmetic."),
-                    _ => unreachable!(),
+                let new_value = match op {
+                    UnaryOperator::Plus => value,
+                    UnaryOperator::Minus => -value,
+                    UnaryOperator::Not => todo!("Implement boolean arithmetic."),
                 };
 
                 Ok(new_value)
             }
             Expression::Group(node) => self.walk(node),
             Expression::Literal(token) => {
-                let value = match token.variant {
-                    Int(int) => WalkValue::Int(int as i64),
-                    Float(float) => WalkValue::Float(float as f64),
-                    _ => unreachable!(),
+                let value = match token {
+                    Literal::Int(int) => WalkValue::Int(*int as i64),
+                    Literal::Float(float) => WalkValue::Float(*float as f64),
+                    _ => todo!(),
                 };
 
                 Ok(value)
             }
+            _ => todo!(),
         }
     }
 }