diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-17 14:41:31 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-17 14:41:31 -0400 |
| commit | cbe117a6d3c1f9e9167b671c752cde978c4ea8d1 (patch) | |
| tree | 4d1ae5462d7668b0c0291a9b45bf4cc1e596a37e /builtins/util.h | |
| parent | bac188ce07b957807d4c649cb5d4e5e253360278 (diff) | |
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.
Diffstat (limited to 'builtins/util.h')
| -rw-r--r-- | builtins/util.h | 2 |
1 files changed, 2 insertions, 0 deletions
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 |
