From cab9ea0aad4c7fb0fe512f4003a2c160cdd3ddef Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 11 Mar 2025 13:44:02 -0400 Subject: Improve codegen for optional struct types --- structs.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'structs.c') diff --git a/structs.c b/structs.c index 080791e5..5b8aafd3 100644 --- a/structs.c +++ b/structs.c @@ -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" -- cgit v1.2.3