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 /structs.c | |
| parent | d0efc4ae5aeb321128c210d762036d4a8ed2c9d1 (diff) | |
Improve codegen for optional struct types
Diffstat (limited to 'structs.c')
| -rw-r--r-- | structs.c | 11 |
1 files changed, 2 insertions, 9 deletions
@@ -61,15 +61,8 @@ CORD compile_struct_header(env_t *env, ast_t *ast) "struct ", full_name, "$$struct {\n", fields, "};\n", - "typedef struct {\n", - "union {\n", - full_name, "$$type value;\n" - "struct {\n" - "char _padding[", heap_strf("%zu", unpadded_struct_size(t)), "];\n", - "Bool_t is_none:1;\n" - "};\n" - "};\n" - "} ", namespace_prefix(env, env->namespace), "$Optional", def->name, "$$type;\n" + "DEFINE_OPTIONAL_TYPE(", full_name, "$$type, ", heap_strf("%zu", unpadded_struct_size(t)), + ", ", namespace_prefix(env, env->namespace), "$Optional", def->name, "$$type);\n" // Constructor macro: "#define ", namespace_prefix(env, env->namespace), def->name, "(...) ((", namespace_prefix(env, env->namespace), def->name, "$$type){__VA_ARGS__})\n" |
