From: Brendan Hansen Date: Wed, 2 Jun 2021 20:14:07 +0000 (-0500) Subject: bugfixes with interactions of top level expressions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5aeb6ea3082d31ee8a915174c11ab964c8b2aa80;p=onyx.git bugfixes with interactions of top level expressions --- diff --git a/bin/onyx b/bin/onyx index e9b6fe51..d2adfee3 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 01680a4f..9dc4062f 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -475,6 +475,7 @@ struct Arguments { AstKind kind; \ u32 flags; \ OnyxToken *token; \ + struct Entity* entity; \ AstNode *next struct AstNode { AstNode_base; }; @@ -668,10 +669,11 @@ struct AstSwitch { // without the 'next' member. This is because types // can't be in expressions so a 'next' thing // doesn't make sense. -#define AstType_base \ - AstKind kind; \ - u32 flags; \ - OnyxToken* token; \ +#define AstType_base \ + AstKind kind; \ + u32 flags; \ + OnyxToken* token; \ + struct Entity* entity; \ char* name struct AstType { AstType_base; }; @@ -696,6 +698,9 @@ struct AstStructType { // NOTE: Used to store statically bound expressions in the struct. Scope* scope; + + struct Entity* entity_type; + struct Entity* entity_defaults; }; struct AstStructMember { AstTyped_base; diff --git a/src/onyx.c b/src/onyx.c index dee800b2..767f2199 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -263,9 +263,11 @@ static void process_load_entity(Entity* ent) { } static b32 process_entity(Entity* ent) { + static char verbose_output_buffer[512]; if (context.options->verbose_output == 3) { if (ent->expr && ent->expr->token) - printf("%s | %s (%d, %d) | %s:%i:%i\n", + snprintf(verbose_output_buffer, 511, + "%15s | %20s (%d, %d) | %s:%i:%i \n", entity_state_strings[ent->state], entity_type_strings[ent->type], (u32) ent->macro_attempts, @@ -275,7 +277,8 @@ static b32 process_entity(Entity* ent) { ent->expr->token->pos.column); else if (ent->expr) - printf("%s | %s (%d, %d) \n", + snprintf(verbose_output_buffer, 511, + "%15s | %20s (%d, %d) \n", entity_state_strings[ent->state], entity_type_strings[ent->type], (u32) ent->macro_attempts, @@ -323,7 +326,13 @@ static b32 process_entity(Entity* ent) { case Entity_State_Code_Gen: emit_entity(ent); break; } - return ent->state != before_state; + b32 changed = ent->state != before_state; + if (context.options->verbose_output == 3) { + if (changed) printf("SUCCESS | %s", verbose_output_buffer); + else printf("YIELD | %s", verbose_output_buffer); + } + + return changed; } // Just having fun with some visual output - brendanfh 2020/12/14 diff --git a/src/onyxbuiltins.c b/src/onyxbuiltins.c index 76e4e148..04dd5f27 100644 --- a/src/onyxbuiltins.c +++ b/src/onyxbuiltins.c @@ -3,43 +3,43 @@ #include "onyxerrors.h" #include "onyxutils.h" -AstBasicType basic_type_void = { Ast_Kind_Basic_Type, 0, NULL, "void" , &basic_types[Basic_Kind_Void] }; -AstBasicType basic_type_bool = { Ast_Kind_Basic_Type, 0, NULL, "bool" , &basic_types[Basic_Kind_Bool] }; -AstBasicType basic_type_i8 = { Ast_Kind_Basic_Type, 0, NULL, "i8" , &basic_types[Basic_Kind_I8] }; -AstBasicType basic_type_u8 = { Ast_Kind_Basic_Type, 0, NULL, "u8" , &basic_types[Basic_Kind_U8] }; -AstBasicType basic_type_i16 = { Ast_Kind_Basic_Type, 0, NULL, "i16" , &basic_types[Basic_Kind_I16] }; -AstBasicType basic_type_u16 = { Ast_Kind_Basic_Type, 0, NULL, "u16" , &basic_types[Basic_Kind_U16] }; -AstBasicType basic_type_i32 = { Ast_Kind_Basic_Type, 0, NULL, "i32" , &basic_types[Basic_Kind_I32] }; -AstBasicType basic_type_u32 = { Ast_Kind_Basic_Type, 0, NULL, "u32" , &basic_types[Basic_Kind_U32] }; -AstBasicType basic_type_i64 = { Ast_Kind_Basic_Type, 0, NULL, "i64" , &basic_types[Basic_Kind_I64] }; -AstBasicType basic_type_u64 = { Ast_Kind_Basic_Type, 0, NULL, "u64" , &basic_types[Basic_Kind_U64] }; -AstBasicType basic_type_f32 = { Ast_Kind_Basic_Type, 0, NULL, "f32" , &basic_types[Basic_Kind_F32] }; -AstBasicType basic_type_f64 = { Ast_Kind_Basic_Type, 0, NULL, "f64" , &basic_types[Basic_Kind_F64] }; -AstBasicType basic_type_rawptr = { Ast_Kind_Basic_Type, 0, NULL, "rawptr", &basic_types[Basic_Kind_Rawptr] }; +AstBasicType basic_type_void = { Ast_Kind_Basic_Type, 0, NULL, NULL, "void" , &basic_types[Basic_Kind_Void] }; +AstBasicType basic_type_bool = { Ast_Kind_Basic_Type, 0, NULL, NULL, "bool" , &basic_types[Basic_Kind_Bool] }; +AstBasicType basic_type_i8 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "i8" , &basic_types[Basic_Kind_I8] }; +AstBasicType basic_type_u8 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "u8" , &basic_types[Basic_Kind_U8] }; +AstBasicType basic_type_i16 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "i16" , &basic_types[Basic_Kind_I16] }; +AstBasicType basic_type_u16 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "u16" , &basic_types[Basic_Kind_U16] }; +AstBasicType basic_type_i32 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "i32" , &basic_types[Basic_Kind_I32] }; +AstBasicType basic_type_u32 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "u32" , &basic_types[Basic_Kind_U32] }; +AstBasicType basic_type_i64 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "i64" , &basic_types[Basic_Kind_I64] }; +AstBasicType basic_type_u64 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "u64" , &basic_types[Basic_Kind_U64] }; +AstBasicType basic_type_f32 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "f32" , &basic_types[Basic_Kind_F32] }; +AstBasicType basic_type_f64 = { Ast_Kind_Basic_Type, 0, NULL, NULL, "f64" , &basic_types[Basic_Kind_F64] }; +AstBasicType basic_type_rawptr = { Ast_Kind_Basic_Type, 0, NULL, NULL, "rawptr", &basic_types[Basic_Kind_Rawptr] }; // NOTE: Types used for numeric literals -AstBasicType basic_type_int_unsized = { Ast_Kind_Basic_Type, 0, NULL, "unsized_int", &basic_types[Basic_Kind_Int_Unsized] }; -AstBasicType basic_type_float_unsized = { Ast_Kind_Basic_Type, 0, NULL, "unsized_float", &basic_types[Basic_Kind_Float_Unsized] }; +AstBasicType basic_type_int_unsized = { Ast_Kind_Basic_Type, 0, NULL, NULL, "unsized_int", &basic_types[Basic_Kind_Int_Unsized] }; +AstBasicType basic_type_float_unsized = { Ast_Kind_Basic_Type, 0, NULL, NULL, "unsized_float", &basic_types[Basic_Kind_Float_Unsized] }; static OnyxToken simd_token = { Token_Type_Symbol, 0, "", { 0 } }; -AstBasicType basic_type_i8x16 = { Ast_Kind_Basic_Type, 0, &simd_token, "i8x16", &basic_types[Basic_Kind_I8X16] }; -AstBasicType basic_type_i16x8 = { Ast_Kind_Basic_Type, 0, &simd_token, "i16x8", &basic_types[Basic_Kind_I16X8] }; -AstBasicType basic_type_i32x4 = { Ast_Kind_Basic_Type, 0, &simd_token, "i32x4", &basic_types[Basic_Kind_I32X4] }; -AstBasicType basic_type_i64x2 = { Ast_Kind_Basic_Type, 0, &simd_token, "i64x2", &basic_types[Basic_Kind_I64X2] }; -AstBasicType basic_type_f32x4 = { Ast_Kind_Basic_Type, 0, &simd_token, "f32x4", &basic_types[Basic_Kind_F32X4] }; -AstBasicType basic_type_f64x2 = { Ast_Kind_Basic_Type, 0, &simd_token, "f64x2", &basic_types[Basic_Kind_F64X2] }; -AstBasicType basic_type_v128 = { Ast_Kind_Basic_Type, 0, &simd_token, "v128", &basic_types[Basic_Kind_V128] }; +AstBasicType basic_type_i8x16 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "i8x16", &basic_types[Basic_Kind_I8X16] }; +AstBasicType basic_type_i16x8 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "i16x8", &basic_types[Basic_Kind_I16X8] }; +AstBasicType basic_type_i32x4 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "i32x4", &basic_types[Basic_Kind_I32X4] }; +AstBasicType basic_type_i64x2 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "i64x2", &basic_types[Basic_Kind_I64X2] }; +AstBasicType basic_type_f32x4 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "f32x4", &basic_types[Basic_Kind_F32X4] }; +AstBasicType basic_type_f64x2 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "f64x2", &basic_types[Basic_Kind_F64X2] }; +AstBasicType basic_type_v128 = { Ast_Kind_Basic_Type, 0, &simd_token, NULL, "v128", &basic_types[Basic_Kind_V128] }; OnyxToken builtin_package_token = { Token_Type_Symbol, 7, "builtin ", { 0 } }; static OnyxToken builtin_heap_start_token = { Token_Type_Symbol, 12, "__heap_start ", { 0 } }; static OnyxToken builtin_stack_top_token = { Token_Type_Symbol, 11, "__stack_top ", { 0 } }; -AstNumLit builtin_heap_start = { Ast_Kind_NumLit, Ast_Flag_Const, &builtin_heap_start_token, NULL, (AstType *) &basic_type_rawptr, NULL, 0 }; -AstGlobal builtin_stack_top = { Ast_Kind_Global, Ast_Flag_Const | Ast_Flag_Global_Stack_Top, &builtin_stack_top_token, NULL, (AstType *) &basic_type_rawptr, NULL }; +AstNumLit builtin_heap_start = { Ast_Kind_NumLit, Ast_Flag_Const, &builtin_heap_start_token, NULL, NULL, (AstType *) &basic_type_rawptr, NULL, 0 }; +AstGlobal builtin_stack_top = { Ast_Kind_Global, Ast_Flag_Const | Ast_Flag_Global_Stack_Top, &builtin_stack_top_token, NULL, NULL, (AstType *) &basic_type_rawptr, NULL }; // :TypeExprHack static OnyxToken type_expr_token = { Token_Type_Symbol, 9, "type_expr", { 0 } }; -AstNode type_expr_symbol = { Ast_Kind_Error, 0, &type_expr_token, NULL }; +AstNode type_expr_symbol = { Ast_Kind_Error, 0, &type_expr_token, NULL, NULL }; AstType *builtin_string_type; AstType *builtin_range_type; diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 76c3bd8a..49801d8a 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -410,18 +410,26 @@ CheckStatus check_call(AstCall* call) { arguments_clone(&call->original_args, &call->args); if (call->callee->kind == Ast_Kind_Overloaded_Function) { - call->callee = find_matching_overload_by_arguments(((AstOverloadedFunction *) call->callee)->overloads, &call->args); - if (call->callee == NULL) { - report_unable_to_match_overload(call); - return Check_Error; + AstTyped* new_callee = find_matching_overload_by_arguments(((AstOverloadedFunction *) call->callee)->overloads, &call->args); + if (new_callee == NULL) { + if (call->callee->entity->state > Entity_State_Check_Types) { + report_unable_to_match_overload(call); + return Check_Error; + + } else { + return Check_Yield_Macro; + } } + + call->callee = new_callee; } if (call->callee->kind == Ast_Kind_Polymorphic_Proc) { - call->callee = (AstTyped *) polymorphic_proc_lookup((AstPolyProc *) call->callee, PPLM_By_Arguments, &call->args, call->token); - if (call->callee == NULL) return Check_Error; + AstTyped* new_callee = (AstTyped *) polymorphic_proc_lookup((AstPolyProc *) call->callee, PPLM_By_Arguments, &call->args, call->token); + if (new_callee == NULL) return Check_Error; arguments_remove_baked(&call->args); + call->callee = new_callee; } AstFunction* callee = (AstFunction *) call->callee; @@ -619,8 +627,13 @@ CheckStatus check_binop_assignment(AstBinaryOp* binop, b32 assignment_is_ok) { resolve_expression_type(binop->right); if (binop->right->type == NULL) { - onyx_report_error(binop->token->pos, "Could not resolve type of right hand side to infer."); - return Check_Error; + if (binop->right->entity == NULL || binop->right->entity->state > Entity_State_Check_Types) { + onyx_report_error(binop->token->pos, "Could not resolve type of right hand side to infer."); + return Check_Error; + + } else { + return Check_Yield_Macro; + } } if (binop->right->type->kind == Type_Kind_Compound) { @@ -1048,6 +1061,11 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) { fori (i, 0, mem_count) { CHECK(expression, actual); + // HACK HACK HACK + if ((*actual)->type == NULL && (*actual)->kind == Ast_Kind_Function) { + return Check_Yield_Macro; + } + // NOTE: Not checking the return on this function because // this for loop is bounded by the number of members in the // type. @@ -1272,8 +1290,8 @@ CheckStatus check_field_access(AstFieldAccess** pfield) { AstFieldAccess* field = *pfield; CHECK(expression, &field->expr); if (field->expr->type == NULL) { - onyx_report_error(field->token->pos, "Unable to deduce type of expression for accessing field."); - return Check_Error; + // onyx_report_error(field->token->pos, "Unable to deduce type of expression for accessing field."); + return Check_Yield_Macro; } if (!type_is_structlike(field->expr->type)) { @@ -1598,6 +1616,8 @@ CheckStatus check_function(AstFunction* func) { } CheckStatus check_overloaded_function(AstOverloadedFunction* func) { + b32 done = 1; + bh_arr_each(AstTyped *, node, func->overloads) { if ( (*node)->kind != Ast_Kind_Function && (*node)->kind != Ast_Kind_Polymorphic_Proc @@ -1607,12 +1627,19 @@ CheckStatus check_overloaded_function(AstOverloadedFunction* func) { return Check_Error; } + + if ((*node)->entity && (*node)->entity->state <= Entity_State_Check_Types) { + done = 0; + } } - return Check_Success; + if (done) return Check_Success; + else return Check_Yield_Macro; } CheckStatus check_struct(AstStructType* s_node) { + if (s_node->entity_defaults && s_node->entity_defaults->state < Entity_State_Check_Types) return Check_Yield_Macro; + bh_arr_each(AstStructMember *, smem, s_node->members) { if ((*smem)->type_node == NULL && (*smem)->initial_value != NULL) { CHECK(expression, &(*smem)->initial_value); @@ -1628,7 +1655,7 @@ CheckStatus check_struct(AstStructType* s_node) { // NOTE: fills in the stcache type_build_from_ast(context.ast_alloc, (AstType *) s_node); - if (s_node->stcache == NULL) return Check_Error; + if (s_node->stcache == NULL) return Check_Yield_Macro; bh_arr_each(StructMember *, smem, s_node->stcache->Struct.memarr) { if ((*smem)->type->kind == Type_Kind_Compound) { @@ -1641,6 +1668,8 @@ CheckStatus check_struct(AstStructType* s_node) { } CheckStatus check_struct_defaults(AstStructType* s_node) { + if (s_node->entity_type && s_node->entity_type->state < Entity_State_Code_Gen) return Check_Yield_Macro; + bh_arr_each(StructMember *, smem, s_node->stcache->Struct.memarr) { if ((*smem)->initial_value && *(*smem)->initial_value) { CHECK(expression, (*smem)->initial_value); @@ -1661,6 +1690,8 @@ CheckStatus check_struct_defaults(AstStructType* s_node) { } CheckStatus check_function_header(AstFunction* func) { + if (func->entity_body && func->entity_body->state < Entity_State_Check_Types) return Check_Yield_Macro; + b32 expect_default_param = 0; b32 has_had_varargs = 0; @@ -1714,7 +1745,7 @@ CheckStatus check_function_header(AstFunction* func) { if (local->type == NULL) { onyx_report_error(param->local->token->pos, - "Unable to resolve type for parameter, '%b'.\n", + "Unable to resolve type for parameter, '%b'", local->token->text, local->token->length); return Check_Error; @@ -1781,6 +1812,9 @@ CheckStatus check_memres(AstMemRes* memres) { } } else { + if (memres->initial_value->type == NULL && memres->initial_value->entity != NULL && memres->initial_value->entity->state <= Entity_State_Check_Types) { + return Check_Yield_Macro; + } memres->type = memres->initial_value->type; } } @@ -1847,6 +1881,15 @@ CheckStatus check_static_if(AstIf* static_if) { return Check_Complete; } +CheckStatus check_process_directive(AstNode* directive) { + if (directive->kind == Ast_Kind_Directive_Export) { + AstTyped* export = ((AstDirectiveExport *) directive)->export; + if (export->entity && export->entity->state <= Entity_State_Check_Types) return Check_Yield_Macro; + } + + return Check_Success; +} + CheckStatus check_node(AstNode* node) { switch (node->kind) { case Ast_Kind_Function: return check_function((AstFunction *) node); @@ -1888,10 +1931,16 @@ void check_entity(Entity* ent) { cs = check_type(ent->type_alias); break; + case Entity_Type_Process_Directive: cs = check_process_directive((AstNode *) ent->expr); break; + default: break; } if (cs == Check_Success) ent->state = Entity_State_Code_Gen; if (cs == Check_Complete) ent->state = Entity_State_Finalized; if (cs == Check_Yield_Macro) ent->macro_attempts++; + else { + ent->macro_attempts = 0; + ent->micro_attempts = 0; + } } diff --git a/src/onyxentities.c b/src/onyxentities.c index 630ae73f..e3f6afcc 100644 --- a/src/onyxentities.c +++ b/src/onyxentities.c @@ -4,8 +4,8 @@ static inline i32 entity_phase(Entity* e1) { if (e1->state <= Entity_State_Parse) return 1; - if (e1->state < Entity_State_Code_Gen) return 3; - return 4; + if (e1->state < Entity_State_Code_Gen) return 2; + return 3; } // NOTE: Returns >0 if e1 should be processed after e2. @@ -240,6 +240,7 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s ent.type = Entity_Type_Struct_Member_Default; ent.type_alias = (AstType *) node; ENTITY_INSERT(ent); + ((AstStructType *) node)->entity_defaults = entity; // fallthrough } @@ -248,6 +249,11 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s ent.type = Entity_Type_Type_Alias; ent.type_alias = (AstType *) node; ENTITY_INSERT(ent); + + if (node->kind == Ast_Kind_Struct_Type) { + ((AstStructType *) node)->entity_type = entity; + } + break; } @@ -321,4 +327,6 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s break; } } + + node->entity = entity; } diff --git a/src/onyxsymres.c b/src/onyxsymres.c index b053f77e..4ee4b584 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -127,7 +127,11 @@ static SymresStatus symres_struct_type(AstStructType* s_node) { AstStructMember *member = s_node->members[i]; if (member->type_node) { - SYMRES(type, &member->type_node); + SymresStatus ss = symres_type(&member->type_node); + if (ss != Symres_Success) { + s_node->flags &= ~Ast_Flag_Type_Is_Resolved; + return ss; + } if (!node_is_type((AstNode *) member->type_node)) { onyx_report_error(member->token->pos, "Member type is not a type."); @@ -824,8 +828,6 @@ SymresStatus symres_function(AstFunction* func) { scope_enter(func->scope); if ((func->flags & Ast_Flag_Has_Been_Symres) == 0) { - func->flags |= Ast_Flag_Has_Been_Symres; - bh_arr_each(AstParam, param, func->params) { symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local); @@ -849,6 +851,11 @@ SymresStatus symres_function(AstFunction* func) { if (param->local->flags & Ast_Flag_Param_Use) { if (param->local->type_node != NULL && param->local->type == NULL) { param->local->type = type_build_from_ast(context.ast_alloc, param->local->type_node); + + if (param->local->type == NULL) { + // HACK HACK HACK + return Symres_Yield_Macro; + } } if (type_is_struct(param->local->type)) { @@ -875,6 +882,8 @@ SymresStatus symres_function(AstFunction* func) { } } } + + func->flags |= Ast_Flag_Has_Been_Symres; } SYMRES(block, func->body); diff --git a/src/onyxtypes.c b/src/onyxtypes.c index 7d2a5c61..bfb7b071 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -219,7 +219,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { switch (type_node->kind) { case Ast_Kind_Pointer_Type: { Type* ptr_type = type_make_pointer(alloc, type_build_from_ast(alloc, ((AstPointerType *) type_node)->elem)); - ptr_type->ast_type = type_node; + if (ptr_type) ptr_type->ast_type = type_node; return ptr_type; } @@ -308,7 +308,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { if ((*member)->type == NULL) { // :ExplicitTyping - onyx_report_error((*member)->token->pos, "Unable to resolve member type. Try adding it explicitly."); + // onyx_report_error((*member)->token->pos, "Unable to resolve member type. Try adding it explicitly."); s_node->stcache = NULL; return NULL; } @@ -409,19 +409,19 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { case Ast_Kind_Slice_Type: { Type* slice_type = type_make_slice(alloc, type_build_from_ast(alloc, ((AstSliceType *) type_node)->elem)); - slice_type->ast_type = type_node; + if (slice_type) slice_type->ast_type = type_node; return slice_type; } case Ast_Kind_DynArr_Type: { Type* dynarr_type = type_make_dynarray(alloc, type_build_from_ast(alloc, ((AstDynArrType *) type_node)->elem)); - dynarr_type->ast_type = type_node; + if (dynarr_type) dynarr_type->ast_type = type_node; return dynarr_type; } case Ast_Kind_VarArg_Type: { Type* va_type = type_make_varargs(alloc, type_build_from_ast(alloc, ((AstVarArgType *) type_node)->elem)); - va_type->ast_type = type_node; + if (va_type) va_type->ast_type = type_node; return va_type; } @@ -561,6 +561,8 @@ Type* type_build_compound_type(bh_allocator alloc, AstCompound* compound) { } Type* type_make_pointer(bh_allocator alloc, Type* to) { + if (to == NULL) return NULL; + Type* ptr_type = bh_alloc_item(alloc, Type); ptr_type->kind = Type_Kind_Pointer; @@ -572,6 +574,8 @@ Type* type_make_pointer(bh_allocator alloc, Type* to) { } Type* type_make_array(bh_allocator alloc, Type* to, u32 count) { + if (to == NULL) return NULL; + Type* arr_type = bh_alloc_item(alloc, Type); arr_type->kind = Type_Kind_Array; @@ -583,6 +587,8 @@ Type* type_make_array(bh_allocator alloc, Type* to, u32 count) { } Type* type_make_slice(bh_allocator alloc, Type* of) { + if (of == NULL) return NULL; + Type* slice_type = bh_alloc(alloc, sizeof(Type)); slice_type->kind = Type_Kind_Slice; slice_type->Slice.ptr_to_data = type_make_pointer(alloc, of); @@ -591,6 +597,8 @@ Type* type_make_slice(bh_allocator alloc, Type* of) { } Type* type_make_dynarray(bh_allocator alloc, Type* of) { + if (of == NULL) return NULL; + Type* dynarr = bh_alloc(alloc, sizeof(Type)); dynarr->kind = Type_Kind_DynArray; dynarr->DynArray.ptr_to_data = type_make_pointer(alloc, of); @@ -599,6 +607,8 @@ Type* type_make_dynarray(bh_allocator alloc, Type* of) { } Type* type_make_varargs(bh_allocator alloc, Type* of) { + if (of == NULL) return NULL; + Type* va_type = bh_alloc(alloc, sizeof(Type)); va_type->kind = Type_Kind_VarArgs; va_type->VarArgs.ptr_to_data = type_make_pointer(alloc, of); diff --git a/src/onyxutils.c b/src/onyxutils.c index f0c1b9c0..18bdc5aa 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -1013,6 +1013,7 @@ AstTyped* find_matching_overload_by_arguments(bh_arr(AstTyped *) overloads, Argu // NOTE: Overload is not something that is known to be overloadable. if (overload == NULL) continue; if (overload->kind != Ast_Kind_Function) continue; + if (overload->type == NULL) continue; // NOTE: If the arguments cannot be placed successfully in the parameters list if (!fill_in_arguments(&args, (AstNode *) overload, NULL)) continue; diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 8f40cce8..4e8e9248 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2639,8 +2639,6 @@ EMIT_FUNC(zero_value_for_type, Type* type, OnyxToken* where) { } else if (type->kind == Type_Kind_Function) { - // CLEANUP ROBUSTNESS: This should use the 'null_proc' instead of whatever is at - // function index 0. WID(WI_I32_CONST, mod->null_proc_func_idx); } else {