Reduce binop args before reducing full expr
This commit is contained in:
parent
c27c900e7f
commit
5c79563e53
@ -56,8 +56,10 @@ fn reduce(evr: EvalResult) -> EvalResult {
|
|||||||
match ast {
|
match ast {
|
||||||
|
|
||||||
BinOp(op, lhs, rhs) => {
|
BinOp(op, lhs, rhs) => {
|
||||||
let result: AST = reduce_binop(*op, *lhs, *rhs);
|
let (reduced_lhs, new_env) = reduce((*lhs, env));
|
||||||
(result, 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) => {
|
Name(name) => {
|
||||||
let result = match env.lookup_binding(&name) {
|
let result = match env.lookup_binding(&name) {
|
||||||
@ -124,3 +126,10 @@ fn reduce_binop(op: AST, lhs: AST, rhs: AST) -> AST {
|
|||||||
_ => Null
|
_ => Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user