diff options
| author | Martin Haug <mhaug@live.de> | 2022-02-28 14:22:49 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-02-28 14:22:49 +0100 |
| commit | 9fde38a6f82106e4c3a47f1bc34343650d8aad5b (patch) | |
| tree | 8834ed5d4051ee5c0670519f62b31b18aa6fada6 /src/eval | |
| parent | 8e0f5993f12a590c42dfebfbc99b75dba00daf15 (diff) | |
CR: I've a feeling we're not in Review anymore.
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/func.rs | 3 | ||||
| -rw-r--r-- | src/eval/mod.rs | 9 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/eval/func.rs b/src/eval/func.rs index b870fd9d..a7f2a209 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -139,8 +139,7 @@ impl Closure { // Evaluate the body. let value = match self.body.eval(ctx, &mut scp) { - Ok(value) => value, - Err(Control::Return(value, _)) => return Ok(value.unwrap_or_default()), + Err(Control::Return(value, _)) => value.unwrap_or_default(), other => other?, }; diff --git a/src/eval/mod.rs b/src/eval/mod.rs index cb80968c..3686d665 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -58,9 +58,13 @@ pub type EvalResult<T> = Result<T, Control>; /// A control flow event that occurred during evaluation. #[derive(Clone, Debug, PartialEq)] pub enum Control { + /// Stop iteration in a loop. Break(Span), + /// Skip the remainder of the current iteration in a loop. Continue(Span), + /// Stop execution of a function early, optionally returning a value. Return(Option<Value>, Span), + /// Stop the execution because an error occurred. Err(TypError), } @@ -634,7 +638,6 @@ impl Eval for WhileExpr { while condition.eval(ctx, scp)?.cast::<bool>().at(condition.span())? { let body = self.body(); let value = match body.eval(ctx, scp) { - Ok(value) => value, Err(Control::Break(_)) => break, Err(Control::Continue(_)) => continue, other => other?, @@ -661,14 +664,12 @@ impl Eval for ForExpr { let body = self.body(); let value = match body.eval(ctx, scp) { - Ok(value) => value, Err(Control::Break(_)) => break, Err(Control::Continue(_)) => continue, other => other?, }; - output = ops::join(output, value) - .at(self.body().span())?; + output = ops::join(output, value).at(body.span())?; } scp.exit(); |
