From a887bf4b3e8101bdc99554e5a9e25803e7dc5c6e Mon Sep 17 00:00:00 2001 From: Raptorox <70806316+Raptorox@users.noreply.github.com> Date: Thu, 21 May 2026 17:40:53 +0200 Subject: [PATCH] don't repeat l/rhs in eval --- src/eval.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 3d486e8..feedf85 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -20,13 +20,16 @@ impl Evaluator { } }, Expr::Binary { op, left, right } => { + let lhs = self.eval_expr(*left); + let rhs = self.eval_expr(*right); + match op { - BinaryOp::Add => self.eval_expr(*left) + self.eval_expr(*right), - BinaryOp::Sub => self.eval_expr(*left) - self.eval_expr(*right), - BinaryOp::Mul => self.eval_expr(*left) * self.eval_expr(*right), - BinaryOp::Div => self.eval_expr(*left) / self.eval_expr(*right), - BinaryOp::Mod => self.eval_expr(*left) % self.eval_expr(*right), - BinaryOp::Exp => self.eval_expr(*left).pow(self.eval_expr(*right) as u32) // probably shouldn't cast like that + BinaryOp::Add => lhs + rhs, + BinaryOp::Sub => lhs - rhs, + BinaryOp::Mul => lhs * rhs, + BinaryOp::Div => lhs / rhs, + BinaryOp::Mod => lhs % rhs, + BinaryOp::Exp => lhs.pow(rhs as u32) // probably shouldn't cast like that } }, expr => panic!("can't eval expression: {expr:?}")