ast: Consistent constant folding.

This commit is contained in:
John 2024-08-05 12:36:27 -05:00
parent 5a1112db8f
commit 0614e17b73

View File

@ -645,13 +645,12 @@ pub mod canonical {
Expr::Number(tail) Expr::Number(tail)
} }
Expr::Binary(head, tails) => { Expr::Binary(head, tails) => {
let mut tails = tails.into_iter().map(|(op, tail)| (op, tail.to_canonical()));
let mut head = match head.to_canonical() { let mut head = match head.to_canonical() {
Expr::Number(n) => n, Expr::Number(n) => n,
head => return Expr::Binary(head.into(), tails), head => return Expr::Binary(head.into(), tails.collect()),
}; };
let mut tails = tails.into_iter();
for (op, tail) in &mut tails { for (op, tail) in &mut tails {
let tail = tail.to_canonical();
// If the canonical tail isn't a number, rebuild and return // If the canonical tail isn't a number, rebuild and return
let Expr::Number(tail) = tail else { let Expr::Number(tail) = tail else {
return Expr::Binary( return Expr::Binary(