diff options
| author | SAJJA EASWAR <eshwarsajja20@gmail.com> | 2026-01-25 22:59:36 +0530 |
|---|---|---|
| committer | SAJJA EASWAR <eshwarsajja20@gmail.com> | 2026-01-25 22:59:36 +0530 |
| commit | ebc8b94baa6bc694cb4829e2eb2934a1f17fa6a1 (patch) | |
| tree | 71b952ad455bf17d5bdea01472f0e2297f25eabe /src/codegen/codegen_decl.c | |
| parent | 863118c95caac0d69a35f6ae4d2e83844734a8a1 (diff) | |
| parent | 489336b2101bf16edeec7bfc4379408eb19b936e (diff) | |
Merge branch 'main' into pr-109
Diffstat (limited to 'src/codegen/codegen_decl.c')
| -rw-r--r-- | src/codegen/codegen_decl.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/codegen/codegen_decl.c b/src/codegen/codegen_decl.c index 18d81f5..d525963 100644 --- a/src/codegen/codegen_decl.c +++ b/src/codegen/codegen_decl.c @@ -953,7 +953,20 @@ void emit_impl_vtables(ParserContext *ctx, FILE *out) ASTNode *m = node->impl_trait.methods; while (m) { - const char *orig = parse_original_method_name(m->func.name); + // Calculate expected prefix: Struct__Trait_ + char prefix[256]; + sprintf(prefix, "%s__%s_", strct, trait); + const char *orig = m->func.name; + if (strncmp(orig, prefix, strlen(prefix)) == 0) + { + orig += strlen(prefix); + } + else + { + // Fallback if mangling schema differs (shouldn't happen) + orig = parse_original_method_name(m->func.name); + } + fprintf(out, ".%s = (__typeof__(((%s_VTable*)0)->%s))%s__%s_%s", orig, trait, orig, strct, trait, orig); if (m->next) @@ -978,7 +991,14 @@ int emit_tests_and_runner(ParserContext *ctx, ASTNode *node, FILE *out) if (cur->type == NODE_TEST) { fprintf(out, "static void _z_test_%d() {\n", test_count); + int saved = defer_count; codegen_walker(ctx, cur->test_stmt.body, out); + // Run defers + for (int i = defer_count - 1; i >= saved; i--) + { + codegen_node_single(ctx, defer_stack[i], out); + } + defer_count = saved; fprintf(out, "}\n"); test_count++; } |
