From 398d2cab6988e20c59e7037ff7ef551540339abb Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 5 Oct 2025 17:52:33 -0400 Subject: Fix a bunch of issues with optional types --- src/compile/structs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/compile/structs.c') diff --git a/src/compile/structs.c b/src/compile/structs.c index 2e7217f6..3f443c44 100644 --- a/src/compile/structs.c +++ b/src/compile/structs.c @@ -70,12 +70,14 @@ Text_t compile_struct_header(env_t *env, ast_t *ast) { Text_t struct_code = def->external ? EMPTY_TEXT : Texts(type_code, " {\n", fields, "};\n"); type_t *t = Table$str_get(*env->types, def->name); - Text_t unpadded_size = def->opaque ? Texts("sizeof(", type_code, ")") : Texts((int64_t)unpadded_struct_size(t)); Text_t typeinfo_code = Texts("extern const TypeInfo_t ", typeinfo_name, ";\n"); Text_t optional_code = EMPTY_TEXT; if (!def->opaque) { - optional_code = Texts("DEFINE_OPTIONAL_TYPE(", compile_type(t), ", ", unpadded_size, ", ", - namespace_name(env, env->namespace, Texts("$Optional", def->name, "$$type")), ");\n"); + optional_code = Texts("typedef struct {\n", compile_type(t), + " value;\n" + "Bool_t has_value;\n" + "} ", + namespace_name(env, env->namespace, Texts("$Optional", def->name, "$$type")), ";\n"); } return Texts(struct_code, optional_code, typeinfo_code); } -- cgit v1.2.3