Streamline.

This commit is contained in:
Stephen Chung
2020-04-29 16:11:54 +08:00
parent 304c658f89
commit 21c3edb31e
3 changed files with 33 additions and 20 deletions

View File

@@ -729,10 +729,10 @@ pub fn optimize_into_ast(
// Optimize the function body
let mut body =
optimize(vec![fn_def.body], engine, &Scope::new(), &fn_lib, level);
optimize(vec![*fn_def.body], engine, &Scope::new(), &fn_lib, level);
// {} -> Noop
fn_def.body = match body.pop().unwrap_or_else(|| Stmt::Noop(pos)) {
fn_def.body = Box::new(match body.pop().unwrap_or_else(|| Stmt::Noop(pos)) {
// { return val; } -> val
Stmt::ReturnWithVal(Some(val), ReturnType::Return, _) => Stmt::Expr(val),
// { return; } -> ()
@@ -741,7 +741,7 @@ pub fn optimize_into_ast(
}
// All others
stmt => stmt,
};
});
}
fn_def
})