| ... | ... | @@ -4169,9 +4169,17 @@ IrInstruction *ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) { |
| 4169 | 4169 | return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable); |
| 4170 | 4170 | } |
| 4171 | 4171 | |
| 4172 | static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) { |
| 4173 | if (!exec || !exec->source_node || limit < 0) return; |
| 4174 | add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here")); |
| 4175 | add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1); |
| 4176 | } |
| 4177 | |
| 4172 | 4178 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) { |
| 4173 | 4179 | ira->new_irb.exec->invalid = true; |
| 4174 | | return add_node_error(ira->codegen, source_instruction->source_node, msg); |
| 4180 | ErrorMsg *err_msg = add_node_error(ira->codegen, source_instruction->source_node, msg); |
| 4181 | add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10); |
| 4182 | return err_msg; |
| 4175 | 4183 | } |
| 4176 | 4184 | |
| 4177 | 4185 | static IrInstruction *ir_exec_const_result(IrExecutable *exec) { |
| ... | ... | @@ -4680,9 +4688,12 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un |
| 4680 | 4688 | |
| 4681 | 4689 | IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 4682 | 4690 | TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, |
| 4683 | | FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name) |
| 4691 | FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 4692 | IrExecutable *parent_exec) |
| 4684 | 4693 | { |
| 4685 | 4694 | IrExecutable ir_executable = {0}; |
| 4695 | ir_executable.source_node = source_node; |
| 4696 | ir_executable.parent_exec = parent_exec; |
| 4686 | 4697 | ir_executable.name = exec_name; |
| 4687 | 4698 | ir_executable.is_inline = true; |
| 4688 | 4699 | ir_executable.fn_entry = fn_entry; |
| ... | ... | @@ -4700,6 +4711,8 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 4700 | 4711 | fprintf(stderr, "}\n"); |
| 4701 | 4712 | } |
| 4702 | 4713 | IrExecutable analyzed_executable = {0}; |
| 4714 | analyzed_executable.source_node = source_node; |
| 4715 | analyzed_executable.parent_exec = parent_exec; |
| 4703 | 4716 | analyzed_executable.name = exec_name; |
| 4704 | 4717 | analyzed_executable.is_inline = true; |
| 4705 | 4718 | analyzed_executable.fn_entry = fn_entry; |
| ... | ... | @@ -4730,7 +4743,7 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value |
| 4730 | 4743 | return ira->codegen->builtin_types.entry_invalid; |
| 4731 | 4744 | |
| 4732 | 4745 | if (type_value->type_entry->id != TypeTableEntryIdMetaType) { |
| 4733 | | add_node_error(ira->codegen, type_value->source_node, |
| 4746 | ir_add_error(ira, type_value, |
| 4734 | 4747 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->type_entry->name))); |
| 4735 | 4748 | return ira->codegen->builtin_types.entry_invalid; |
| 4736 | 4749 | } |
| ... | ... | @@ -5152,7 +5165,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 5152 | 5165 | ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->type_entry, value); |
| 5153 | 5166 | switch (result) { |
| 5154 | 5167 | case ImplicitCastMatchResultNo: |
| 5155 | | add_node_error(ira->codegen, first_executing_node(value->source_node), |
| 5168 | ir_add_error(ira, value, |
| 5156 | 5169 | buf_sprintf("expected type '%s', found '%s'", |
| 5157 | 5170 | buf_ptr(&expected_type->name), |
| 5158 | 5171 | buf_ptr(&value->type_entry->name))); |
| ... | ... | @@ -6147,7 +6160,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 6147 | 6160 | AstNode *body_node = fn_entry->fn_def_node->data.fn_def.body; |
| 6148 | 6161 | result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type, |
| 6149 | 6162 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry, |
| 6150 | | nullptr, call_instruction->base.source_node, nullptr); |
| 6163 | nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec); |
| 6151 | 6164 | if (result->type_entry->id == TypeTableEntryIdInvalid) |
| 6152 | 6165 | return ira->codegen->builtin_types.entry_invalid; |
| 6153 | 6166 | |
| ... | ... | @@ -8432,7 +8445,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc |
| 8432 | 8445 | TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void; |
| 8433 | 8446 | IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 8434 | 8447 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 8435 | | &cimport_scope->buf, block_node, nullptr); |
| 8448 | &cimport_scope->buf, block_node, nullptr, nullptr); |
| 8436 | 8449 | if (result->type_entry->id == TypeTableEntryIdInvalid) |
| 8437 | 8450 | return ira->codegen->builtin_types.entry_invalid; |
| 8438 | 8451 | |