| ... | @@ -512,12 +512,7 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN | ... | @@ -512,12 +512,7 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN |
| 512 | return &const_instruction->base; | 512 | return &const_instruction->base; |
| 513 | } | 513 | } |
| 514 | | 514 | |
| 515 | static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { | 515 | static void init_const_str_lit(ConstExprValue *const_val, Buf *str) { |
| 516 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); | | |
| 517 | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; | | |
| 518 | TypeTableEntry *type_entry = get_array_type(irb->codegen, u8_type, buf_len(str)); | | |
| 519 | const_instruction->base.type_entry = type_entry; | | |
| 520 | ConstExprValue *const_val = &const_instruction->base.static_value; | | |
| 521 | const_val->special = ConstValSpecialStatic; | 516 | const_val->special = ConstValSpecialStatic; |
| 522 | const_val->data.x_array.elements = allocate<ConstExprValue>(buf_len(str)); | 517 | const_val->data.x_array.elements = allocate<ConstExprValue>(buf_len(str)); |
| 523 | const_val->data.x_array.size = buf_len(str); | 518 | const_val->data.x_array.size = buf_len(str); |
| ... | @@ -527,6 +522,15 @@ static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstN | ... | @@ -527,6 +522,15 @@ static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstN |
| 527 | this_char->special = ConstValSpecialStatic; | 522 | this_char->special = ConstValSpecialStatic; |
| 528 | bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]); | 523 | bignum_init_unsigned(&this_char->data.x_bignum, buf_ptr(str)[i]); |
| 529 | } | 524 | } |
| | 525 | } |
| | 526 | |
| | 527 | static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| | 528 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); |
| | 529 | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; |
| | 530 | TypeTableEntry *type_entry = get_array_type(irb->codegen, u8_type, buf_len(str)); |
| | 531 | const_instruction->base.type_entry = type_entry; |
| | 532 | ConstExprValue *const_val = &const_instruction->base.static_value; |
| | 533 | init_const_str_lit(const_val, str); |
| 530 | | 534 | |
| 531 | return &const_instruction->base; | 535 | return &const_instruction->base; |
| 532 | } | 536 | } |
| ... | @@ -6877,11 +6881,26 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc | ... | @@ -6877,11 +6881,26 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc |
| 6877 | TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true); | 6881 | TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true); |
| 6878 | if (casted_value->static_value.special == ConstValSpecialStatic) { | 6882 | if (casted_value->static_value.special == ConstValSpecialStatic) { |
| 6879 | ErrorTableEntry *err = casted_value->static_value.data.x_pure_err; | 6883 | ErrorTableEntry *err = casted_value->static_value.data.x_pure_err; |
| 6880 | IrInstruction *new_instruction = ir_create_const_str_lit(&ira->new_irb, instruction->base.scope, | 6884 | if (!err->cached_error_name_val) { |
| 6881 | instruction->base.source_node, &err->name); | 6885 | err->cached_error_name_val = allocate<ConstExprValue>(1); |
| 6882 | ir_link_new_instruction(new_instruction, &instruction->base); | 6886 | err->cached_error_name_val->special = ConstValSpecialStatic; |
| 6883 | new_instruction->static_value.special = ConstValSpecialStatic; | 6887 | err->cached_error_name_val->data.x_struct.fields = allocate<ConstExprValue>(2); |
| 6884 | new_instruction->static_value.depends_on_compile_var = casted_value->static_value.depends_on_compile_var; | 6888 | |
| | 6889 | ConstExprValue *array_val = allocate<ConstExprValue>(1); |
| | 6890 | init_const_str_lit(array_val, &err->name); |
| | 6891 | |
| | 6892 | ConstExprValue *ptr_val = &err->cached_error_name_val->data.x_struct.fields[slice_ptr_index]; |
| | 6893 | ptr_val->special = ConstValSpecialStatic; |
| | 6894 | ptr_val->data.x_ptr.base_ptr = array_val; |
| | 6895 | ptr_val->data.x_ptr.index = 0; |
| | 6896 | |
| | 6897 | ConstExprValue *len_val = &err->cached_error_name_val->data.x_struct.fields[slice_len_index]; |
| | 6898 | len_val->special = ConstValSpecialStatic; |
| | 6899 | bignum_init_unsigned(&len_val->data.x_bignum, buf_len(&err->name)); |
| | 6900 | } |
| | 6901 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, |
| | 6902 | casted_value->static_value.depends_on_compile_var); |
| | 6903 | *out_val = *err->cached_error_name_val; |
| 6885 | return str_type; | 6904 | return str_type; |
| 6886 | } | 6905 | } |
| 6887 | | 6906 | |