diff --git a/src/compiler/interpreter.rs b/src/compiler/interpreter.rs index e6303c9..3652f7e 100644 --- a/src/compiler/interpreter.rs +++ b/src/compiler/interpreter.rs @@ -40,8 +40,40 @@ impl<'source> Interpreter<'source> { "<=" => Value::Bool(self.interpret(left) <= self.interpret(right)), ">" => Value::Bool(self.interpret(left) > self.interpret(right)), ">=" => Value::Bool(self.interpret(left) >= self.interpret(right)), - "and" => self.interpret(left).and(&self.interpret(right)), - "or" => self.interpret(left).or(&self.interpret(right)), + "and" => { + let left_val = self.interpret(left); + if let Value::Bool(val_l) = left_val { + if !val_l { + Value::Bool(false) + } else { + let right_val = self.interpret(right); + if let Value::Bool(val_r) = right_val { + Value::Bool(val_r) + } else { + panic!("Non-bool with and operator"); + } + } + } else { + panic!("Non-bool with and operator"); + } + } + "or" => { + let left_val = self.interpret(left); + if let Value::Bool(val_l) = left_val { + if val_l { + Value::Bool(true) + } else { + let right_val = self.interpret(right); + if let Value::Bool(val_r) = right_val { + Value::Bool(val_r) + } else { + panic!("Non-bool with and operator"); + } + } + } else { + panic!("Non-bool with and operator"); + } + } "=" => { if let Expression::Identifier(_, name) = **left { let val = self.interpret(right); diff --git a/src/compiler/value.rs b/src/compiler/value.rs index 3b5bde5..7325c68 100644 --- a/src/compiler/value.rs +++ b/src/compiler/value.rs @@ -10,32 +10,6 @@ pub enum Value { None(), } -impl Value { - pub fn and(&self, other: &Self) -> Self { - if let Value::Bool(val1) = self { - if let Value::Bool(val2) = other { - Value::Bool(*val1 && *val2) - } else { - panic!("Can't apply and to non-bools!") - } - } else { - panic!("Can't apply and to non-bools!!") - } - } - - pub fn or(&self, other: &Self) -> Self { - if let Value::Bool(val1) = self { - if let Value::Bool(val2) = other { - Value::Bool(*val1 || *val2) - } else { - panic!("Can't apply or to non-bools!") - } - } else { - panic!("Can't apply or to non-bools!!") - } - } -} - impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self {