From: Brendan Hansen Date: Fri, 7 Jan 2022 17:34:23 +0000 (-0600) Subject: made #solidify better X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5cd2ee8c3a35bead8ba322dc1b1c69e260a0f371;p=onyx.git made #solidify better --- diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 6a328d8f..0979e9e7 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -546,7 +546,7 @@ distributor :: #match {} return distributor(as_iterator(it)); } -#match distributor (it: Iterator($T)) -> Iterator(T) { +#match distributor (it: Iterator) -> Iterator(it.Iter_Type) { Context :: struct (T: type_expr) { mutex: sync.Mutex; iterator: Iterator(T); @@ -570,11 +570,11 @@ distributor :: #match {} cfree(c); } - c := new(Context(T)); + c := new(Context(it.Iter_Type)); sync.mutex_init(^c.mutex); c.iterator = it; - return .{c, #solidify next {T=T}, #solidify close {T=T}}; + return .{c, #solidify next {T=it.Iter_Type}, #solidify close {T=it.Iter_Type}}; } parallel_for :: #match {} diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index 609bea2f..2e8783ad 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -83,6 +83,9 @@ Settings :: struct { ["--tests"] test_folder := "./tests"; + + ["--compile-only"] + compile_only := false; } args_parse :: (c_args: [] cstr, output: ^Settings) -> bool { @@ -146,8 +149,10 @@ main :: (args) => { // The executable to use when compiling onyx_cmd: str; at_least_one_test_failed := false; + compile_only := false; @Bug // why is this necessary? why is settings.compile_only false when in the thread code? } exec_context := init(Execution_Context); + exec_context.compile_only = settings.compile_only; switch runtime.compiler_os { case .Linux { @@ -163,11 +168,18 @@ main :: (args) => { iter.parallel_for(cases, settings.threads, ^exec_context) { // Weird macros mean I have to forward external names use package core - print_color :: print_color - - printf("[{}] Running test {}...\n", context.thread_id, it.source_file); + print_color :: print_color; + + args: [] str; + if thread_data.compile_only { + printf("[{}] Compiling test {}...\n", context.thread_id, it.source_file); + args = .[it.source_file]; + } else { + printf("[{}] Running test {}...\n", context.thread_id, it.source_file); + args = .["run", it.source_file]; + } - proc := os.process_spawn(thread_data.onyx_cmd, .["run", it.source_file]); + proc := os.process_spawn(thread_data.onyx_cmd, args); defer os.process_destroy(^proc); proc_reader := io.reader_make(^proc); @@ -181,6 +193,8 @@ main :: (args) => { continue; } + if thread_data.compile_only do continue; + for expected_file: os.with_file(it.expected_file) { expected_reader := io.reader_make(expected_file); expected_output := io.read_all(^expected_reader); diff --git a/src/checker.c b/src/checker.c index efcdf762..63ef8a18 100644 --- a/src/checker.c +++ b/src/checker.c @@ -103,6 +103,7 @@ CheckStatus check_memres_type(AstMemRes* memres); CheckStatus check_memres(AstMemRes* memres); CheckStatus check_type(AstType** ptype); CheckStatus check_insert_directive(AstDirectiveInsert** pinsert); +CheckStatus check_directive_solidify(AstDirectiveSolidify** psolid); CheckStatus check_do_block(AstDoBlock** pdoblock); CheckStatus check_constraint(AstConstraint *constraint); CheckStatus check_constraint_context(ConstraintContext *cc, Scope *scope, OnyxFilePos pos); @@ -463,9 +464,7 @@ CheckStatus check_argument(AstArgument** parg) { static CheckStatus check_resolve_callee(AstCall* call, AstTyped** effective_callee) { if (call->kind == Ast_Kind_Intrinsic_Call) return Check_Success; - call->callee = (AstTyped *) strip_aliases((AstNode *) call->callee); - - AstTyped* callee = call->callee; + AstTyped* callee = (AstTyped *) strip_aliases((AstNode *) call->callee); b32 calling_a_macro = 0; if (callee->kind == Ast_Kind_Overloaded_Function) { @@ -1777,7 +1776,7 @@ CheckStatus check_expression(AstTyped** pexpr) { break; case Ast_Kind_Directive_Solidify: - *pexpr = (AstTyped *) ((AstDirectiveSolidify *) expr)->resolved_proc; + CHECK(directive_solidify, (AstDirectiveSolidify **) pexpr); break; case Ast_Kind_Directive_Defined: @@ -1884,6 +1883,32 @@ CheckStatus check_insert_directive(AstDirectiveInsert** pinsert) { return Check_Return_To_Symres; } +CheckStatus check_directive_solidify(AstDirectiveSolidify** psolid) { + AstDirectiveSolidify* solid = *psolid; + + bh_arr_each(AstPolySolution, sln, solid->known_polyvars) { + CHECK(expression, &sln->value); + + if (node_is_type((AstNode *) sln->value)) { + sln->type = type_build_from_ast(context.ast_alloc, sln->ast_type); + sln->kind = PSK_Type; + } else { + sln->kind = PSK_Value; + } + } + + solid->resolved_proc = polymorphic_proc_try_solidify(solid->poly_proc, solid->known_polyvars, solid->token); + if (solid->resolved_proc == (AstNode *) &node_that_signals_a_yield) { + solid->resolved_proc = NULL; + YIELD(solid->token->pos, "Waiting for partially solidified procedure."); + } + + // NOTE: Not a DirectiveSolidify. + *psolid = (AstDirectiveSolidify *) solid->resolved_proc; + + return Check_Success; +} + CheckStatus check_statement(AstNode** pstmt) { AstNode* stmt = *pstmt; diff --git a/src/polymorph.h b/src/polymorph.h index 64ecbe04..95781d77 100644 --- a/src/polymorph.h +++ b/src/polymorph.h @@ -758,9 +758,14 @@ AstNode* polymorphic_proc_try_solidify(AstFunction* pp, bh_arr(AstPolySolution) if (found_match) { valid_argument_count++; } else { - onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%b'.", - sln->poly_sym->token->text, sln->poly_sym->token->length, - pp->token->text, pp->token->length); + if (pp->name) { + onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%s'.", + sln->poly_sym->token->text, sln->poly_sym->token->length, pp->name); + } else { + onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%b'.", + sln->poly_sym->token->text, sln->poly_sym->token->length, + pp->token->text, pp->token->length); + } return (AstNode *) pp; } } diff --git a/src/symres.c b/src/symres.c index 452fd877..dc00eff9 100644 --- a/src/symres.c +++ b/src/symres.c @@ -758,13 +758,7 @@ cannot_use: } static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) { - // @Cleanup: A lot of this code should move to the checker? - AstDirectiveSolidify* solid = *psolid; - if (solid->resolved_proc != NULL) { - *psolid = (AstDirectiveSolidify *) solid->resolved_proc; - return Symres_Success; - } SYMRES(expression, (AstTyped **) &solid->poly_proc); if (solid->poly_proc && solid->poly_proc->kind == Ast_Kind_Directive_Solidify) { @@ -778,27 +772,12 @@ static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) { onyx_report_error(solid->token->pos, Error_Critical, "Expected polymorphic procedure in #solidify directive."); return Symres_Error; } - + bh_arr_each(AstPolySolution, sln, solid->known_polyvars) { // HACK: This assumes that 'ast_type' and 'value' are at the same offset. SYMRES(expression, &sln->value); - - if (node_is_type((AstNode *) sln->value)) { - sln->type = type_build_from_ast(context.ast_alloc, sln->ast_type); - sln->kind = PSK_Type; - } else { - sln->kind = PSK_Value; - } - } - - solid->resolved_proc = polymorphic_proc_try_solidify(solid->poly_proc, solid->known_polyvars, solid->token); - if (solid->resolved_proc == (AstNode *) &node_that_signals_a_yield) { - solid->resolved_proc = NULL; - return Symres_Yield_Macro; } - // NOTE: Not a DirectiveSolidify. - *psolid = (AstDirectiveSolidify *) solid->resolved_proc; return Symres_Success; }