From 1f6e586b2a3fe7f8ca32ce95659032bafef0ad24 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 11 Mar 2025 17:49:04 -0400 Subject: Support external structs with namespaced methods (also C-strings are now `const char*` instead of `char*`) --- structs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'structs.c') diff --git a/structs.c b/structs.c index 27f3a295..fe57f472 100644 --- a/structs.c +++ b/structs.c @@ -51,15 +51,12 @@ CORD compile_struct_header(env_t *env, ast_t *ast) type_t *field_t = get_arg_ast_type(env, field); fields = CORD_all(fields, compile_declaration(field_t, field->name), field_t->tag == BoolType ? ":1" : CORD_EMPTY, ";\n"); } - CORD struct_code = CORD_all("struct ", full_name, "$$struct {\n"); - struct_code = CORD_all(struct_code, "};\n"); + CORD struct_code = def->external ? CORD_EMPTY : CORD_all("struct ", full_name, "$$struct {\n", fields, "};\n"); type_t *t = Table$str_get(*env->types, def->name); return CORD_all( - "struct ", full_name, "$$struct {\n", - fields, - "};\n", + struct_code, "DEFINE_OPTIONAL_TYPE(", compile_type(t), ", ", heap_strf("%zu", unpadded_struct_size(t)), - ", ", namespace_prefix(env, env->namespace), "$Optional", def->name, "$$type);\n" + ", ", namespace_prefix(env, env->namespace), "$Optional", def->name, "$$type);\n" "extern const TypeInfo_t ", full_name, "$$info;\n"); } -- cgit v1.2.3