ast: Consistent constant folding.
This commit is contained in:
parent
5a1112db8f
commit
0614e17b73
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user