diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-10-08 21:10:36 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-10-08 21:10:36 -0400 |
| commit | 839c1983a0dad0232da3ceda9c7c02a49715453c (patch) | |
| tree | 955e588981f589b780257c2a8a6fade286f41876 /structs.c | |
| parent | 5103fde1c5e7e92f00801fb3a0e3662e436ee881 (diff) | |
Reduce padding needed for optional types and clean up some redundant
type padding
Diffstat (limited to 'structs.c')
| -rw-r--r-- | structs.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -55,14 +55,20 @@ CORD compile_struct_header(env_t *env, ast_t *ast) } CORD struct_code = CORD_all("struct ", full_name, "_s {\n"); struct_code = CORD_all(struct_code, "};\n"); + type_t *t = Table$str_get(*env->types, def->name); return CORD_all( "typedef struct ", full_name, "_s ", full_name, "_t;\n", "struct ", full_name, "_s {\n", fields, "};\n", "typedef struct {\n", + "union {\n", full_name, "_t value;\n" - "Bool_t is_null:1;\n" + "struct {\n" + "char _padding[", heap_strf("%zu", unpadded_struct_size(t)), "];\n", + "Bool_t is_null;\n" + "};\n" + "};\n" "} ", namespace_prefix(env, env->namespace), "$Optional", def->name, "_t;\n" "extern const TypeInfo_t ", full_name, ";\n", compile_namespace_header(env, def->name, def->namespace)); |
