From: Brendan Hansen Date: Fri, 30 Sep 2022 03:33:14 +0000 (-0500) Subject: code cleanup; warning and bug fixes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ec5ed4f79c65c623b46dc7afcb2ad5a486a09a9c;p=onyx.git code cleanup; warning and bug fixes --- diff --git a/compiler/src/checker.c b/compiler/src/checker.c index 67b88746..ed8674a7 100644 --- a/compiler/src/checker.c +++ b/compiler/src/checker.c @@ -2469,7 +2469,11 @@ CheckStatus check_function_header(AstFunction* func) { if (func->constraints.constraints != NULL && func->constraints.constraints_met == 0) { func->constraints.produce_errors = (func->flags & Ast_Flag_Header_Check_No_Error) == 0; - CHECK(constraint_context, &func->constraints, func->scope, func->token->pos); + + OnyxToken *tkn = func->token; + if (func->generated_from) tkn = func->generated_from; + + CHECK(constraint_context, &func->constraints, func->scope, tkn->pos); // All constraints have been met. Return to symbol resolution to finish // looking up all symbols in the function. diff --git a/compiler/src/symres.c b/compiler/src/symres.c index 54a14cf4..e8433bd1 100644 --- a/compiler/src/symres.c +++ b/compiler/src/symres.c @@ -768,75 +768,62 @@ static SymresStatus symres_switch(AstSwitch* switchnode) { return Symres_Success; } -// CLEANUP: A lot of duplication going on in this function. A proper -// "namespace" concept would be useful to remove a lot of the fluff -// code here. There already is try_resolve_symbol_from_node which -// may be able to do what is needed here? static SymresStatus symres_use(AstUse* use) { SYMRES(expression, &use->expr); AstTyped *use_expr = (AstTyped *) strip_aliases((AstNode *) use->expr); + Scope* used_scope = NULL; + // :EliminatingSymres if (use_expr->kind == Ast_Kind_Package) { AstPackage* package = (AstPackage *) use_expr; SYMRES(package, package); - if (package->package->scope == curr_scope) return Symres_Success; - - if (use->only == NULL) { - OnyxFilePos pos = { 0 }; - if (use->token != NULL) - pos = use->token->pos; - - scope_include(curr_scope, package->package->scope, pos); - - } else { - bh_arr_each(QualifiedUse, qu, use->only) { - AstNode* thing = symbol_resolve(package->package->scope, qu->symbol_name); - if (thing == NULL) { // :SymresStall - if (report_unresolved_symbols) { - onyx_report_error(qu->symbol_name->pos, Error_Critical, - "The symbol '%b' was not found in this package.", - qu->symbol_name->text, qu->symbol_name->length); - return Symres_Error; - } else { - return Symres_Yield_Macro; - } - } - - symbol_introduce(curr_scope, qu->as_name, thing); - } - } - if (!use->entity) { add_entities_for_node(NULL, (AstNode *) use, curr_scope, NULL); } package_track_use_package(package->package, use->entity); - return Symres_Success; + used_scope = package->package->scope; } if (use_expr->kind == Ast_Kind_Foreign_Block) { AstForeignBlock* fb = (AstForeignBlock *) use_expr; if (fb->entity->state <= Entity_State_Resolve_Symbols) return Symres_Yield_Macro; - if (fb->scope == curr_scope) return Symres_Success; + used_scope = fb->scope; + } + + if (use_expr->kind == Ast_Kind_Enum_Type) { + AstEnumType* et = (AstEnumType *) use_expr; + used_scope = et->scope; + } + + if (use_expr->kind == Ast_Kind_Struct_Type) { + AstStructType* st = (AstStructType *) use_expr; + if (!st->scope) return Symres_Success; + + used_scope = st->scope; + } + + if (used_scope) { + if (used_scope == curr_scope) return Symres_Success; if (use->only == NULL) { OnyxFilePos pos = { 0 }; if (use->token != NULL) pos = use->token->pos; - scope_include(curr_scope, fb->scope, pos); + scope_include(curr_scope, used_scope, pos); } else { bh_arr_each(QualifiedUse, qu, use->only) { - AstNode* thing = symbol_resolve(fb->scope, qu->symbol_name); + AstNode* thing = symbol_resolve(used_scope, qu->symbol_name); if (thing == NULL) { // :SymresStall if (report_unresolved_symbols) { onyx_report_error(qu->symbol_name->pos, Error_Critical, - "The symbol '%b' was not found in this package.", + "The symbol '%b' was not found in the used scope.", qu->symbol_name->text, qu->symbol_name->length); return Symres_Error; } else { @@ -851,39 +838,6 @@ static SymresStatus symres_use(AstUse* use) { return Symres_Success; } - if (use_expr->kind == Ast_Kind_Enum_Type) { - AstEnumType* et = (AstEnumType *) use_expr; - - bh_arr_each(AstEnumValue *, ev, et->values) - symbol_introduce(curr_scope, (*ev)->token, (AstNode *) *ev); - - return Symres_Success; - } - - if (use_expr->kind == Ast_Kind_Struct_Type) { - AstStructType* st = (AstStructType *) use_expr; - if (!st->scope) return Symres_Success; - - if (use->only == NULL) { - scope_include(curr_scope, st->scope, use->token->pos); - - } else { - bh_arr_each(QualifiedUse, qu, use->only) { - AstNode* thing = symbol_resolve(st->scope, qu->symbol_name); - if (thing == NULL) { - onyx_report_error(qu->symbol_name->pos, Error_Critical, - "The symbol '%b' was not found in this scope.", - qu->symbol_name->text, qu->symbol_name->length); - return Symres_Error; - } - - symbol_introduce(curr_scope, qu->as_name, thing); - } - } - - return Symres_Success; - } - if (use_expr->type_node == NULL && use_expr->type == NULL) goto cannot_use; // :EliminatingSymres diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index c724a136..17e981a5 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -2123,7 +2123,7 @@ EMIT_FUNC(method_call, AstBinaryOp *mcall) { // Do the common assignment pattern found everywhere else. if (!tmp_is_wasm_local) emit_local_location(mod, &code, tmp_local, &offset); - emit_expression(mod, &code, *object); + emit_expression(mod, &code, (AstTyped *) *object); if (!tmp_is_wasm_local) emit_store_instruction(mod, &code, tmp_local->type, offset); else WIL(mcall->token, WI_LOCAL_SET, tmp_local_idx);