bugfix with yielding for a polymorphic procedure generation
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 3 Jun 2021 19:26:28 +0000 (14:26 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 3 Jun 2021 19:26:28 +0000 (14:26 -0500)
include/onyxutils.h
src/onyxchecker.c
src/onyxutils.c

index 0dc7f8bc6b46074b5ebf706d155dffec2b08098c..a67833c95d6120544fecbd9b2a4b689e3f999fb8 100644 (file)
@@ -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
index 2637ec5a664f9e6515a705ea2644458d3f141848..43a29c80950097ee28af630a0331bbb44d38961d 100644 (file)
@@ -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);
index b67a66f1f39f847f4373d92569815cd4d67207d0..81a59d411aeffbfdb4baaaa18137f6bb7aa89fcd 100644 (file)
@@ -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");