diff options
author | Test_User <hax@andrewyu.org> | 2024-12-09 18:21:23 -0500 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-12-09 18:21:23 -0500 |
commit | 0f0b0eae472d5989d4ce388986731e806876fac0 (patch) | |
tree | b7b18b53d3769bb90f9652d0692c447b1bbca17a /language_description.md | |
parent | README: Update online reading URL (diff) | |
download | e2-spec-0f0b0eae472d5989d4ce388986731e806876fac0.tar.gz e2-spec-0f0b0eae472d5989d4ce388986731e806876fac0.tar.zst e2-spec-0f0b0eae472d5989d4ce388986731e806876fac0.zip |
Some changes, and some examples to start with for error propagation
Diffstat (limited to 'language_description.md')
-rw-r--r-- | language_description.md | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/language_description.md b/language_description.md index 1a50c37..fd54e50 100644 --- a/language_description.md +++ b/language_description.md @@ -49,7 +49,7 @@ If something causes `malloc` to be uncallable, e.g. if there is insufficient stack space to hold its local variables, it simply returns a meaningless pointer and a non-nil error value. Note that although we return "`0`" in the example code above, the zero pointer is not guaranteed to be an invalid pointer -in $e^2$. +in `e²`. Other functions may have different methods of failure. Some might return an error, so it might be natural to set their error return value to something like @@ -129,6 +129,35 @@ try { The overflow is caught if and only if it is not handled at the point of the operation and has not been handled at an inner `on_overflow`. +## Error propagation + +```e2 +(int x, char y) do_stuff() { + ... + return 0, 1; // Not an error + ... + return var, 2; // Also not an error + ... + return 0, 5; // Some error + ... + return -5, 3; // Some other error +} on_fail { + return 0, 9; // Another error +} error { + // Consider it an error if (and only if) the 2nd return value is >= 3 + return y >= 3; +} +``` + +```e2 +int f() { + // If do_stuff() errored, return ENOCONN + int a, char b = do_stuff()!(ENOTCONN); + + return a - b; +} +``` + ## Other non-trivial differences from C 1. Instead of `errno`, we use multiple return values to indicate errors where @@ -144,6 +173,6 @@ operation and has not been handled at an inner `on_overflow`. 7. There is no special null pointer. 8. No implicit integer promotion. 9. Void pointers of varying depth (such as `void **`) can be implicitly casted - to pointers of the same or deeper depth (such as `void **` -> `int ***`, + to or from pointers of the same or deeper depth (such as `void **` -> `int ***`, but not `void **` -> `int *`). 10. There is language-level support for tagged unions. |