From 9f7d51ff02d3b92c2ec8355cf05cce7e8e2d70b0 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 20 Jun 2022 16:23:35 +0200 Subject: [PATCH] Initially was working on vargs but we need a new algorithm to match lambda call arguments --- ast.cpp | 1 + ccodegen.cpp | 6 +++++- typechecking.cpp | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ast.cpp b/ast.cpp index c253363..41a99ec 100644 --- a/ast.cpp +++ b/ast.cpp @@ -347,6 +347,7 @@ ast_expr_binary(Ast_Expr *left, Ast_Expr *right, Token *op){ function Ast_Call * ast_call(Token *pos, Ast_Expr *name, Array exprs){ + // name here specifies also typespec for compound expressions ! AST_NEW(Call, CALL, pos, AST_EXPR); result->name = name; result->exprs = exprs.tight_copy(pctx->perm); diff --git a/ccodegen.cpp b/ccodegen.cpp index c231e34..fbd1582 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -462,6 +462,8 @@ gen_ast(Ast *ast){ CASE(IF, If){ For(node->ifs){ + gen_line(node); + genln(""); if(it->init) { gen_expr(it->init); gen(";"); @@ -629,7 +631,9 @@ gen_ast(Ast *ast){ For(node->cases){ For_Named(it->labels, label){ - genln("case "); + gen_line(it); + genln(""); + gen("case "); gen_expr(label); gen(":"); } diff --git a/typechecking.cpp b/typechecking.cpp index ad0c7fc..582fb24 100644 --- a/typechecking.cpp +++ b/typechecking.cpp @@ -614,7 +614,7 @@ resolve_stmt(Ast *ast, Ast_Type *ret){ } For_Named(it->scope->stmts, stmt) resolve_stmt(stmt, ret); } - For_Named(node->default_scope->stmts, stmt) resolve_stmt(stmt, ret); + if(node->default_scope) For_Named(node->default_scope->stmts, stmt) resolve_stmt(stmt, ret); BREAK(); } @@ -1187,11 +1187,14 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){ // @note: check if all arguments are included and cleanup For(node->exprs){ if(!is_flag_set(it->call_flags, CALL_INCLUDED)) - compiler_error(it->pos, "Invalid argument to function call"); + compiler_error(it->pos, "Unknown argument to a function call, couldn't match it with any of the declared arguments"); else unset_flag(it->call_flags, CALL_INCLUDED); } return operand_rvalue(name.type->func.ret); + // + // CALL End + // BREAK(); }