diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2026-02-20 00:18:03 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2026-02-20 00:20:46 -0500 |
| commit | 2727705528aa70f46fab2666b76ab0043469ff80 (patch) | |
| tree | 991388893132a166d782aa11c56c1db578b86552 /src/compile/optionals.c | |
| parent | 92c2eadcf55befba95d461aa0ea8e2feb3664cdc (diff) | |
Code cleanup and copy over some CString methods to path
Diffstat (limited to 'src/compile/optionals.c')
| -rw-r--r-- | src/compile/optionals.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/compile/optionals.c b/src/compile/optionals.c index 8cb6af2b..798d75a6 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -85,19 +85,27 @@ Text_t check_none(type_t *t, Text_t value) { t = Match(t, OptionalType)->type; // NOTE: these use statement expressions ({...;}) because some compilers // complain about excessive parens around equality comparisons - if (t->tag == PointerType || t->tag == FunctionType || t->tag == CStringType) return Texts("(", value, " == NULL)"); - else if (t->tag == BigIntType) return Texts("((", value, ").small == 0)"); - else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)"); - else if (t->tag == NumType) - return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")"); - else if (t->tag == ListType) return Texts("((", value, ").data == NULL)"); - else if (t->tag == TableType) return Texts("((", value, ").entries.data == NULL)"); - else if (t->tag == BoolType) return Texts("((", value, ") == NONE_BOOL)"); - else if (t->tag == TextType) return Texts("((", value, ").tag == TEXT_NONE)"); - else if (t->tag == IntType || t->tag == ByteType || t->tag == StructType) return Texts("!(", value, ").has_value"); - else if (t->tag == EnumType) return Texts("((", value, ").$tag == 0)"); - print_err("Optional check not implemented for: ", type_to_text(t)); - return EMPTY_TEXT; + switch (t->tag) { + case PointerType: + case FunctionType: + case CStringType: + case PathType: return Texts("(", value, " == NULL)"); + case BigIntType: return Texts("((", value, ").small == 0)"); + case ClosureType: return Texts("((", value, ").fn == NULL)"); + case NumType: return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")"); + case ListType: return Texts("((", value, ").data == NULL)"); + case TableType: return Texts("((", value, ").entries.data == NULL)"); + case BoolType: return Texts("((", value, ") == NONE_BOOL)"); + case TextType: return Texts("((", value, ").tag == TEXT_NONE)"); + case IntType: + case ByteType: + case StructType: return Texts("!(", value, ").has_value"); + case EnumType: return Texts("((", value, ").$tag == 0)"); + default: { + print_err("Optional check not implemented for: ", type_to_text(t)); + return EMPTY_TEXT; + } + } } public |
