diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-12-22 15:53:26 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-12-22 15:53:26 -0500 |
| commit | 3dd7854076c5f49032ad520dc56769faa1c35d08 (patch) | |
| tree | 9edc71f9f37b0a667ab0ac5586d34c0089744f21 /structs.c | |
| parent | cdda494fe53374dc513b04ada2dc0fad6a8b83bc (diff) | |
Add optimized metamethods for enums and structs that hold packed data
Diffstat (limited to 'structs.c')
| -rw-r--r-- | structs.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -27,10 +27,11 @@ void compile_struct_def(env_t *env, ast_t *ast) short_name = strrchr(short_name, '$') + 1; env->code->typeinfos = CORD_all("public const TypeInfo_t ", full_name, ";\n", env->code->typeinfos); - CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r = {.size=%zu, .align=%zu, .metamethods=Struct$metamethods, " + 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, " ".tag=StructInfo, .StructInfo.name=\"%s\"%s, " ".StructInfo.num_fields=%ld", - full_name, type_size(t), type_align(t), short_name, def->secret ? ", .StructInfo.is_secret=true" : "", + full_name, type_size(t), type_align(t), metamethods, short_name, def->secret ? ", .StructInfo.is_secret=true" : "", num_fields); if (def->fields) { typeinfo = CORD_asprintf("%r, .StructInfo.fields=(NamedType_t[%d]){", typeinfo, num_fields); |
