Walks through each expression in the abstract syntax tree, optimizing the AST where possible. A new, optimized AST is returned Which is then passed into the Miden generation logic.
(ast: Vec<Expr>, visitor: &mut V)
| 19 | // Walks through each expression in the abstract syntax tree, optimizing the AST where possible. A new, optimized AST is returned |
| 20 | //Which is then passed into the Miden generation logic. |
| 21 | fn walk_ast<V: ExpressionVisitor>(ast: Vec<Expr>, visitor: &mut V) -> Vec<Expr> { |
| 22 | let mut new_ast = vec![]; |
| 23 | for expr in ast { |
| 24 | if let Some(expr) = walk_expr(expr, visitor) { |
| 25 | new_ast.push(expr); |
| 26 | } |
| 27 | } |
| 28 | new_ast |
| 29 | } |
| 30 | |
| 31 | trait ExpressionVisitor { |
| 32 | fn visit_expr(&mut self, expr: Expr) -> Option<Expr>; |