diff options
author | Vincent Ambo <mail@tazj.in> | 2021-01-14T19·49+0300 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-01-14T20·26+0000 |
commit | 39439d59e8e9ddb1e2b7802f3aff092d77de7acf (patch) | |
tree | e7c808364ec2078faa42739877d4ffdba5bd4ec9 /users/tazjin/rlox/src/errors.rs | |
parent | 20a6cfeee233bde9ba1f482fa4545f5e395d6235 (diff) |
feat(tazjin/rlox): Implement early return from functions r/2108
In the book this is implemented via exceptions as control flow, and I'm sticking somewhat closely to that by doing it via an error variant. Change-Id: I9c7b84d6bb28265ab94021ea681df84f16a53da2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2395 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/errors.rs')
-rw-r--r-- | users/tazjin/rlox/src/errors.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/errors.rs b/users/tazjin/rlox/src/errors.rs index 4f173d016039..875f268ca64d 100644 --- a/users/tazjin/rlox/src/errors.rs +++ b/users/tazjin/rlox/src/errors.rs @@ -1,3 +1,5 @@ +use crate::interpreter::Value; + #[derive(Debug)] pub enum ErrorKind { UnexpectedChar(char), @@ -12,6 +14,16 @@ pub enum ErrorKind { InternalError(String), InvalidAssignmentTarget(String), RuntimeError(String), + + // This variant is not an error, rather it is used for + // short-circuiting out of a function body that hits a `return` + // statement. + // + // It's implemented this way because in the original book the + // author uses exceptions for control flow, and this is the + // closest equivalent that I had available without diverging too + // much. + FunctionReturn(Value), } #[derive(Debug)] |