Fix optional bools

This commit is contained in:
Bruce Hill 2024-09-11 14:18:01 -04:00
parent 273e2f995f
commit 0b5bb32912
3 changed files with 6 additions and 7 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);