From 8f717fe9f498642ca6f857ef329d73760b98d44c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 28 Sep 2024 14:17:17 -0400 Subject: [PATCH] Redefine NULL_* values as #defines so they can be constant initializers --- stdlib/optionals.c | 7 ------- stdlib/optionals.h | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/stdlib/optionals.c b/stdlib/optionals.c index 1dc770a..717a1e0 100644 --- a/stdlib/optionals.c +++ b/stdlib/optionals.c @@ -11,13 +11,6 @@ #include "text.h" #include "util.h" -public const Array_t NULL_ARRAY = {.length=-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}; -public const Text_t NULL_TEXT = {.length=-1}; - public PUREFUNC bool is_null(const void *obj, const TypeInfo *non_optional_type) { if (non_optional_type == &Int$info) diff --git a/stdlib/optionals.h b/stdlib/optionals.h index 34ea3b4..31fad71 100644 --- a/stdlib/optionals.h +++ b/stdlib/optionals.h @@ -16,12 +16,12 @@ #define OptionalText_t Text_t #define OptionalClosure_t Closure_t -extern const OptionalBool_t NULL_BOOL; -extern const OptionalTable_t NULL_TABLE; -extern const OptionalArray_t NULL_ARRAY; -extern const OptionalInt_t NULL_INT; -extern const OptionalClosure_t NULL_CLOSURE; -extern const OptionalText_t NULL_TEXT; +#define NULL_ARRAY ((Array_t){.length=-1}) +#define NULL_BOOL ((OptionalBool_t)2) +#define NULL_INT ((OptionalInt_t){.small=0}) +#define NULL_TABLE ((OptionalTable_t){.entries.length=-1}) +#define NULL_CLOSURE ((OptionalClosure_t){.fn=NULL}) +#define NULL_TEXT ((OptionalText_t){.length=-1}) PUREFUNC bool is_null(const void *obj, const TypeInfo *non_optional_type); Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo *type);