From: Brendan Hansen Date: Thu, 3 Jun 2021 19:26:28 +0000 (-0500) Subject: bugfix with yielding for a polymorphic procedure generation X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b6009649580e97dfa19e3620cdd9290435131c34;p=onyx.git bugfix with yielding for a polymorphic procedure generation --- diff --git a/include/onyxutils.h b/include/onyxutils.h index 0dc7f8bc..a67833c9 100644 --- a/include/onyxutils.h +++ b/include/onyxutils.h @@ -38,3 +38,5 @@ i32 string_process_escape_seqs(char* dest, char* src, i32 len); // another time. -brendanfh 2020/10/09 // :RelativeFiles This should lookup for the file relative to "relative_to" char* lookup_included_file(char* filename, char* relative_to, b32 add_onyx_suffix, b32 search_included_folders); + +extern AstNode node_that_signals_a_yield; \ No newline at end of file diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 2637ec5a..43a29c80 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -428,6 +428,7 @@ CheckStatus check_call(AstCall* call) { if (call->callee->kind == Ast_Kind_Polymorphic_Proc) { AstTyped* new_callee = (AstTyped *) polymorphic_proc_lookup((AstPolyProc *) call->callee, PPLM_By_Arguments, &call->args, call->token); + if (new_callee == (AstTyped *) &node_that_signals_a_yield) return Check_Yield_Macro; if (new_callee == NULL) return Check_Error; arguments_remove_baked(&call->args); diff --git a/src/onyxutils.c b/src/onyxutils.c index b67a66f1..81a59d41 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -220,6 +220,9 @@ void scope_clear(Scope* scope) { // // Polymorphic Procedures // + +AstNode node_that_signals_a_yield = {}; + static void ensure_polyproc_cache_is_created(AstPolyProc* pp) { if (pp->concrete_funcs == NULL) { bh_table_init(global_heap_allocator, pp->concrete_funcs, 16); @@ -652,6 +655,9 @@ static void solve_for_polymorphic_param_type(PolySolveResult* resolved, AstPolyP *resolved = solve_poly_type(param->poly_sym, param->type_expr, actual_type); } +// HACK HACK HACK nocheckin +static b32 flag_to_yield = 0; + // NOTE: The job of this function is to look through the arguments provided and find a matching // value that is to be baked into the polymorphic procedures poly-scope. It expected that param // will be of kind PPK_Baked_Value. @@ -683,6 +689,8 @@ static void solve_for_polymorphic_param_value(PolySolveResult* resolved, AstPoly } Type* resolved_type = type_build_from_ast(context.ast_alloc, (AstType *) value); + if (resolved_type == NULL) flag_to_yield = 1; + *resolved = ((PolySolveResult) { PSK_Type, .actual = resolved_type }); } else { @@ -746,6 +754,11 @@ static bh_arr(AstPolySolution) find_polymorphic_slns(AstPolyProc* pp, PolyProcLo default: if (err_msg) *err_msg = "Invalid polymorphic parameter kind. This is a compiler bug."; } + + if (flag_to_yield) { + bh_arr_free(slns); + return NULL; + } switch (resolved.kind) { case PSK_Undefined: @@ -793,6 +806,11 @@ AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lo char *err_msg = NULL; bh_arr(AstPolySolution) slns = find_polymorphic_slns(pp, pp_lookup, actual, &err_msg); if (slns == NULL) { + if (flag_to_yield) { + flag_to_yield = 0; + return (AstFunction *) &node_that_signals_a_yield; + } + if (err_msg != NULL) onyx_report_error(tkn->pos, err_msg); else onyx_report_error(tkn->pos, "Some kind of error occured when generating a polymorphic procedure. You hopefully will not see this");