diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-11 13:44:02 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-11 13:44:02 -0400 |
| commit | cab9ea0aad4c7fb0fe512f4003a2c160cdd3ddef (patch) | |
| tree | 3f596b231fc2a1afadfad41b02cdf2cecef910f3 /stdlib | |
| parent | d0efc4ae5aeb321128c210d762036d4a8ed2c9d1 (diff) | |
Improve codegen for optional struct types
Diffstat (limited to 'stdlib')
| -rw-r--r-- | stdlib/types.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/stdlib/types.h b/stdlib/types.h index 2c9abcfc..f74048cc 100644 --- a/stdlib/types.h +++ b/stdlib/types.h @@ -80,4 +80,14 @@ Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type) .tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr, \ .metamethods={.serialize=cannot_serialize, .deserialize=cannot_deserialize, .as_text=Type$as_text}}) +#define DEFINE_OPTIONAL_TYPE(t, unpadded_size, name) \ + typedef struct { \ + union { \ + t value; \ + struct { \ + char _padding[unpadded_size]; \ + Bool_t is_none:1; \ + }; \ + }; \ + } name // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
