diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen/codegen.c | 33 | ||||
| -rw-r--r-- | src/parser/parser_type.c | 7 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index 370bcec..f019a4b 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -668,15 +668,46 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out) } else { + FuncSig *sig = NULL; + if (node->call.callee->type == NODE_EXPR_VAR) + { + sig = find_func(ctx, node->call.callee->var_ref.name); + } + ASTNode *arg = node->call.args; + int arg_idx = 0; while (arg) { - codegen_expression(ctx, arg, out); + int handled = 0; + if (sig && arg_idx < sig->total_args) + { + Type *param_t = sig->arg_types[arg_idx]; + Type *arg_t = arg->type_info; + + if (param_t && param_t->kind == TYPE_ARRAY && param_t->array_size == 0 && + arg_t && arg_t->kind == TYPE_ARRAY && arg_t->array_size > 0) + { + char *inner = type_to_string(param_t->inner); + fprintf(out, "(Slice_%s){.data = ", inner); + codegen_expression(ctx, arg, out); + fprintf(out, ", .len = %d, .cap = %d}", arg_t->array_size, + arg_t->array_size); + free(inner); + handled = 1; + } + } + + if (!handled) + { + codegen_expression(ctx, arg, out); + } + if (arg->next) { fprintf(out, ", "); } arg = arg->next; + arg_idx++; } } fprintf(out, ")"); diff --git a/src/parser/parser_type.c b/src/parser/parser_type.c index 1b5e8b6..27328fe 100644 --- a/src/parser/parser_type.c +++ b/src/parser/parser_type.c @@ -707,6 +707,13 @@ Type *parse_type_formal(ParserContext *ctx, Lexer *l) expect(l, TOK_RBRACKET, "Expected ']' in array type"); + if (size == 0) + { + char *inner_str = type_to_string(t); + register_slice(ctx, inner_str); + free(inner_str); + } + Type *arr = type_new(TYPE_ARRAY); arr->inner = t; arr->array_size = size; |
