From cbe117a6d3c1f9e9167b671c752cde978c4ea8d1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 17 Aug 2024 14:41:31 -0400 Subject: Allow for top-level or namespace-level variables that are initialized with non-constant values by the use of an initializer function and runtime checks for whether the variable is initialized. --- builtins/util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtins') diff --git a/builtins/util.h b/builtins/util.h index bc0a5828..44b780c2 100644 --- a/builtins/util.h +++ b/builtins/util.h @@ -14,6 +14,8 @@ #define copy(obj_ptr) ((__typeof(obj_ptr))memcpy(GC_MALLOC(sizeof(*(obj_ptr))), obj_ptr, sizeof(*(obj_ptr)))) #define Match(x, _tag) ((x)->tag == _tag ? &(x)->__data._tag : (errx(1, __FILE__ ":%d This was supposed to be a " # _tag "\n", __LINE__), &(x)->__data._tag)) #define Tagged(t, _tag, ...) new(t, .tag=_tag, .__data._tag={__VA_ARGS__}) +#define check_initialized(var, name) *({ if (!var ## $initialized) fail("The variable " name " is being accessed before it has been initialized!"); \ + &var; }) #ifndef auto #define auto __auto_type -- cgit v1.2.3