From 0b5bb32912cfc68c7783548006fca2dc5874eb93 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 11 Sep 2024 14:18:01 -0400 Subject: Fix optional bools --- builtins/optionals.c | 4 ++-- builtins/optionals.h | 6 ++---- 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; diff --git a/compile.c b/compile.c index d3ca0ba6..a8ded474 100644 --- a/compile.c +++ b/compile.c @@ -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); -- cgit v1.2.3