Minor cleanup

master
Nick Krichevsky 2024-05-22 15:08:38 -04:00
parent b4e1fa7690
commit 893dab62c7
1 changed files with 4 additions and 4 deletions

View File

@ -85,7 +85,7 @@ impl ExprVisitor<Result<EvaluatedValue, ScriptError>> for InterpreterRunner<'_>
) -> Result<EvaluatedValue, ScriptError> {
let operand = self.visit_expr(expr)?;
match operator.kind() {
TokenKind::Minus => evaluate_negation(operand, operator),
TokenKind::Minus => evaluate_negation(&operand, operator),
TokenKind::Bang => Ok(EvaluatedValue::Boolean(!operand.is_truthy())),
_ => unreachable!(
"attempted to evaluate non-unary operator as unary operator: {:?}",
@ -274,7 +274,7 @@ fn evaluate_addition(
_ => Err(ScriptError {
line: operator.line(),
location: String::new(),
message: format!("left and right operands must be both numbers or both strings"),
message: "left and right operands must be both numbers or both strings".to_string(),
}),
}
}
@ -291,7 +291,7 @@ fn evaluate_binary_arithmetic<F: FnOnce(f64, f64) -> EvaluatedValue>(
}
fn evaluate_negation(
operand: EvaluatedValue,
operand: &EvaluatedValue,
operator: &Token,
) -> Result<EvaluatedValue, ScriptError> {
match operand {
@ -299,7 +299,7 @@ fn evaluate_negation(
_ => Err(ScriptError {
line: operator.line(),
location: String::new(),
message: format!("operand must be a number"),
message: "operand must be a number".to_string(),
}),
}
}