Check if function calls cannot be scripted.

This commit is contained in:
Stephen Chung
2022-10-14 18:31:40 +08:00
parent ea63c66cf0
commit ac05f0a0a8
6 changed files with 142 additions and 102 deletions

View File

@@ -897,24 +897,17 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b
Stmt::Expr(expr) => {
optimize_expr(expr, state, false);
match &mut **expr {
// func(...)
Expr::FnCall(x, pos) => {
state.set_dirty();
*stmt = Stmt::FnCall(mem::take(x), *pos);
}
// {...};
Expr::Stmt(x) => {
if x.is_empty() {
state.set_dirty();
*stmt = Stmt::Noop(x.position());
} else {
state.set_dirty();
*stmt = mem::take(&mut **x).into();
}
}
// expr;
_ => (),
if matches!(**expr, Expr::FnCall(..) | Expr::Stmt(..)) {
state.set_dirty();
*stmt = match *mem::take(expr) {
// func(...);
Expr::FnCall(x, pos) => Stmt::FnCall(x, pos),
// {};
Expr::Stmt(x) if x.is_empty() => Stmt::Noop(x.position()),
// {...};
Expr::Stmt(x) => (*x).into(),
_ => unreachable!(),
};
}
}