diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 14:18:01 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 14:18:01 -0400 |
| commit | 0b5bb32912cfc68c7783548006fca2dc5874eb93 (patch) | |
| tree | db5f28d83039ed6f78030f11d347c1c0d7b39664 | |
| parent | 273e2f995f1d74e9ef8e9a2e09a3ea2c2b16d839 (diff) | |
Fix optional bools
| -rw-r--r-- | builtins/optionals.c | 4 | ||||
| -rw-r--r-- | builtins/optionals.h | 6 | ||||
| -rw-r--r-- | compile.c | 3 |
3 files changed, 6 insertions, 7 deletions
diff --git a/builtins/optionals.c b/builtins/optionals.c index 687486db..8a1aaf99 100644 --- a/builtins/optionals.c +++ b/builtins/optionals.c @@ -8,7 +8,7 @@ #include "util.h" public const Array_t NULL_ARRAY = {.length=-1}; -public const Bool_t NULL_BOOL = -1; +public const OptionalBool_t NULL_BOOL = 2; public const Int_t NULL_INT = {.small=0}; public const Table_t NULL_TABLE = {.entries.length=-1}; public const Closure_t NULL_CLOSURE = {.fn=NULL}; @@ -19,7 +19,7 @@ static inline bool is_null(const void *obj, const TypeInfo *non_optional_type) if (non_optional_type == &Int$info) return ((Int_t*)obj)->small == 0; else if (non_optional_type == &Bool$info) - return *((Bool_t*)obj) == NULL_BOOL; + return *((OptionalBool_t*)obj) == NULL_BOOL; else if (non_optional_type == &Num$info) return isnan(*((Num_t*)obj)); else if (non_optional_type == &Int64$info) diff --git a/builtins/optionals.h b/builtins/optionals.h index a6ff5c72..10599473 100644 --- a/builtins/optionals.h +++ b/builtins/optionals.h @@ -9,11 +9,9 @@ #include "types.h" #include "util.h" -#define Bool_t bool -#define yes (Bool_t)true -#define no (Bool_t)false +#define OptionalBool_t uint8_t -extern const Bool_t NULL_BOOL; +extern const OptionalBool_t NULL_BOOL; extern const Table_t NULL_TABLE; extern const Array_t NULL_ARRAY; extern const Int_t NULL_INT; @@ -222,7 +222,8 @@ CORD compile_type(type_t *t) case OptionalType: { type_t *nonnull = Match(t, OptionalType)->type; switch (nonnull->tag) { - case BoolType: case CStringType: case BigIntType: case NumType: case TextType: + case BoolType: return "OptionalBool_t"; + case CStringType: case BigIntType: case NumType: case TextType: case ArrayType: case SetType: case TableType: case FunctionType: case ClosureType: case PointerType: case EnumType: case ChannelType: return compile_type(nonnull); |
