diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-05 17:52:33 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-05 17:52:33 -0400 |
| commit | 398d2cab6988e20c59e7037ff7ef551540339abb (patch) | |
| tree | 8c5154cfcd32d0664fd40ac8fa93f50f6434859a /src/compile/structs.c | |
| parent | 9b5b6b110bb80f8530dd7ca4e0cc9eb3236d8ad7 (diff) | |
Fix a bunch of issues with optional types
Diffstat (limited to 'src/compile/structs.c')
| -rw-r--r-- | src/compile/structs.c | 8 |
1 files changed, 5 insertions, 3 deletions
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); } |
