diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 15:33:18 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-17 15:33:18 +0000 |
| commit | b885629239d04d2860a8853799a3d335d8bec154 (patch) | |
| tree | 98ee21d5e7ef791948456da4f23e6b5bb496de7f /src/codegen | |
| parent | e0cf5aca2a17fae1f89860d5106aa901dde32782 (diff) | |
Add support for mixin method dispatch.
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/codegen.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index f019a4b..25ae5b3 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -560,8 +560,38 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out) } else { - fprintf(out, "%s__%s(", base, method); - if (!strchr(type, '*')) + // Mixin Lookup Logic + char *call_base = base; + int need_cast = 0; + char mixin_func_name[128]; + sprintf(mixin_func_name, "%s__%s", base, method); + + if (!find_func(ctx, mixin_func_name)) + { + // Method not found on primary struct, check mixins + ASTNode *def = find_struct_def(ctx, base); + if (def && def->type == NODE_STRUCT && def->strct.used_structs) + { + for (int k = 0; k < def->strct.used_struct_count; k++) + { + char mixin_check[128]; + sprintf(mixin_check, "%s__%s", def->strct.used_structs[k], method); + if (find_func(ctx, mixin_check)) + { + call_base = def->strct.used_structs[k]; + need_cast = 1; + break; + } + } + } + } + + fprintf(out, "%s__%s(", call_base, method); + if (need_cast) + { + fprintf(out, "(%s*)%s", call_base, strchr(type, '*') ? "" : "&"); + } + else if (!strchr(type, '*')) { fprintf(out, "&"); } |
