diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-24 20:55:29 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-24 20:55:29 -0400 |
| commit | f5b2281084d31700690916c6dd250e2da927e566 (patch) | |
| tree | 067f566a72fab976feccdb92f5bc26c16736e3f3 /src/compile/optionals.c | |
| parent | bb1af5c7b5e76ddd3e76ff75e62c0f0a65026ded (diff) | |
Clean up and fix issue with `if var := val` statements. Previous
implementation was kinda janky, but the new one is more robust and
simple.
Diffstat (limited to 'src/compile/optionals.c')
| -rw-r--r-- | src/compile/optionals.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/compile/optionals.c b/src/compile/optionals.c index 1cd86c29..b3d94005 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -92,21 +92,20 @@ 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 == PATH_TYPE) return Texts("({(", value, ").type.$tag == PATH_NONE;})"); - else if (t == PATH_TYPE_TYPE) return Texts("({(", value, ").$tag == PATH_NONE;})"); - else if (t->tag == BigIntType) return Texts("({(", value, ").small == 0;})"); - else if (t->tag == ClosureType) return Texts("({(", value, ").fn == NULL;})"); + if (t->tag == PointerType || t->tag == FunctionType || t->tag == CStringType) return Texts("(", value, " == NULL)"); + else if (t == PATH_TYPE) return Texts("((", value, ").type.$tag == PATH_NONE)"); + else if (t == PATH_TYPE_TYPE) return Texts("((", value, ").$tag == PATH_NONE)"); + 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, ").length < 0;})"); - else if (t->tag == TableType || t->tag == SetType) return Texts("({(", value, ").entries.length < 0;})"); - else if (t->tag == BoolType) return Texts("({(", value, ") == NONE_BOOL;})"); - else if (t->tag == TextType) return Texts("({(", value, ").length < 0;})"); + else if (t->tag == ListType) return Texts("((", value, ").length < 0)"); + else if (t->tag == TableType || t->tag == SetType) return Texts("((", value, ").entries.length < 0)"); + else if (t->tag == BoolType) return Texts("((", value, ") == NONE_BOOL)"); + else if (t->tag == TextType) return Texts("((", value, ").length < 0)"); else if (t->tag == IntType || t->tag == ByteType || t->tag == StructType) return Texts("(", value, ").is_none"); else if (t->tag == EnumType) { - if (enum_has_fields(t)) return Texts("({(", value, ").$tag == 0;})"); + if (enum_has_fields(t)) return Texts("((", value, ").$tag == 0)"); else return Texts("((", value, ") == 0)"); } print_err("Optional check not implemented for: ", type_to_str(t)); |
