diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-11 13:50:01 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-11 13:52:46 -0500 |
| commit | 7f8f2117799cdfa6b62909a9182b5adade1d0bd2 (patch) | |
| tree | 1db466db870768e952f50572453660e090e434e0 /src/stdlib/result.c | |
| parent | 630f910563b6f27dd34a4a0496a43d32539eadcb (diff) | |
| parent | 02886fab651d3f64d2c8ded5597e6c075dc69b5f (diff) | |
Merge branch 'dev' into constructive-reals
Diffstat (limited to 'src/stdlib/result.c')
| -rw-r--r-- | src/stdlib/result.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/stdlib/result.c b/src/stdlib/result.c new file mode 100644 index 00000000..8fd2ca1e --- /dev/null +++ b/src/stdlib/result.c @@ -0,0 +1,65 @@ +// Result (Success/Failure) type info +#include <err.h> +#include <gc.h> +#include <stdbool.h> +#include <stdint.h> +#include <sys/param.h> + +#include "enums.h" +#include "structs.h" +#include "text.h" +#include "util.h" + +public +const TypeInfo_t Result$Success$$info = { + .size = sizeof(Result$Success$$type), + .align = __alignof__(Result$Success$$type), + .tag = StructInfo, + .StructInfo = + { + .name = "Success", + .num_fields = 0, + }, + .metamethods = Struct$metamethods, +}; + +public +const TypeInfo_t Result$Failure$$info = { + .size = sizeof(Result$Failure$$type), + .align = __alignof__(Result$Failure$$type), + .tag = StructInfo, + .StructInfo = + { + .name = "Failure", + .num_fields = 1, + .fields = + (NamedType_t[1]){ + {.name = "reason", .type = &Text$info}, + }, + }, + .metamethods = Struct$metamethods, +}; + +public +const TypeInfo_t Result$$info = { + .size = sizeof(Result_t), + .align = __alignof__(Result_t), + .tag = EnumInfo, + .EnumInfo = + { + .name = "Result", + .num_tags = 2, + .tags = + (NamedType_t[2]){ + { + .name = "Success", + .type = &Result$Success$$info, + }, + { + .name = "Failure", + .type = &Result$Failure$$info, + }, + }, + }, + .metamethods = Enum$metamethods, +}; |
