interpreter: Allow statements to choose their own return value (reduces code duplication)

This commit is contained in:
John 2024-02-26 15:53:45 -06:00
parent ffa313eea8
commit bb3eecd190

View File

@ -649,18 +649,7 @@ pub mod interpret {
let mut env = env.frame("block");
let mut out = ConValue::Empty;
for stmt in stmts {
let Stmt { kind, semi, .. } = stmt;
out = match (kind, semi) {
(StmtKind::Expr(_), Semi::Unterminated) => stmt.interpret(&mut env)?,
(StmtKind::Expr(_), _) => {
stmt.interpret(&mut env)?;
ConValue::Empty
}
_ => {
stmt.interpret(&mut env)?;
continue;
}
}
out = stmt.interpret(&mut env)?;
}
Ok(out)
}