From 5c79563e538acd104d44e2e418fa9b5af6f484f5 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 7 Aug 2015 02:09:52 -0700 Subject: [PATCH] Reduce binop args before reducing full expr --- src/evaluate.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/evaluate.rs b/src/evaluate.rs index f51c2e8..caaf8b7 100644 --- a/src/evaluate.rs +++ b/src/evaluate.rs @@ -56,8 +56,10 @@ fn reduce(evr: EvalResult) -> EvalResult { match ast { BinOp(op, lhs, rhs) => { - let result: AST = reduce_binop(*op, *lhs, *rhs); - (result, env) + let (reduced_lhs, new_env) = reduce((*lhs, env)); + let (reduced_rhs, new_env2) = reduce((*rhs, new_env)); + let result: AST = reduce_binop(*op, reduced_lhs, reduced_rhs); + (result, new_env2) }, Name(name) => { let result = match env.lookup_binding(&name) { @@ -124,3 +126,10 @@ fn reduce_binop(op: AST, lhs: AST, rhs: AST) -> AST { _ => Null } } + +#[cfg(test)] +mod test { + use super::*; + + +}