diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-05 18:20:54 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-05 18:20:54 -0500 |
| commit | 147e0f0269440fce15d6b88a8a90627f3a3b2df2 (patch) | |
| tree | bc33522ba71b5a2996fae22e102cce5046cf1333 /structs.c | |
| parent | 2c4324670ff569ede360d13875c5e4b5720a626d (diff) | |
Overhaul of constructors, making it more consistent and correct. Also
changed T(), T, T_t, T_s type names to T(), T$$info, T$$type, T$$struct
for unambiguity
Diffstat (limited to 'structs.c')
| -rw-r--r-- | structs.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -27,7 +27,7 @@ CORD compile_struct_typeinfo(env_t *env, ast_t *ast) short_name = strrchr(short_name, '$') + 1; const char *metamethods = is_packed_data(t) ? "PackedData$metamethods" : "Struct$metamethods"; - CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r = {.size=%zu, .align=%zu, .metamethods=%s, " + CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r$$info = {.size=%zu, .align=%zu, .metamethods=%s, " ".tag=StructInfo, .StructInfo.name=\"%s\"%s, " ".StructInfo.num_fields=%ld", full_name, type_size(t), type_align(t), metamethods, short_name, def->secret ? ", .StructInfo.is_secret=true" : "", @@ -55,23 +55,26 @@ CORD compile_struct_header(env_t *env, ast_t *ast) CORD type_code = compile_type(field_t); fields = CORD_all(fields, type_code, " $", field->name, field_t->tag == BoolType ? ":1" : CORD_EMPTY, ";\n"); } - CORD struct_code = CORD_all("struct ", full_name, "_s {\n"); + CORD struct_code = CORD_all("struct ", full_name, "$$struct {\n"); struct_code = CORD_all(struct_code, "};\n"); type_t *t = Table$str_get(*env->types, def->name); return CORD_all( - "struct ", full_name, "_s {\n", + "struct ", full_name, "$$struct {\n", fields, "};\n", "typedef struct {\n", "union {\n", - full_name, "_t value;\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, "_t;\n" - "extern const TypeInfo_t ", full_name, ";\n"); + "} ", 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" + "extern const TypeInfo_t ", full_name, "$$info;\n"); } // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
