| author | |
| committer | |
| log | c8a7ab7eff0f261c47926cf0637e919d42e41940 |
| tree | e06648c3784b8fdfcd626b34956565fccc5d7454 |
| parent | 7504be923b1721a5a5e094a306aad029887270e8 |
4 files changed, 27 insertions(+), 18 deletions(-)
src/ir.cpp+3-2| ... | @@ -6173,8 +6173,9 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -6173,8 +6173,9 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 6173 | TypeTableEntry *result_type; | 6173 | TypeTableEntry *result_type; |
| 6174 | ConstExprValue *out_array_val; | 6174 | ConstExprValue *out_array_val; |
| 6175 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); | 6175 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); |
| 6176 | TypeTableEntry *out_array_type = get_array_type(ira->codegen, child_type, new_len); | ||
| 6176 | if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) { | 6177 | if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) { |
| 6177 | result_type = get_array_type(ira->codegen, child_type, new_len); | 6178 | result_type = out_array_type; |
| 6178 | 6179 | ||
| 6179 | out_array_val = out_val; | 6180 | out_array_val = out_val; |
| 6180 | } else { | 6181 | } else { |
| ... | @@ -6182,7 +6183,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * | ... | @@ -6182,7 +6183,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * |
| 6182 | 6183 | ||
| 6183 | out_array_val = allocate<ConstExprValue>(1); | 6184 | out_array_val = allocate<ConstExprValue>(1); |
| 6184 | out_array_val->special = ConstValSpecialStatic; | 6185 | out_array_val->special = ConstValSpecialStatic; |
| 6185 | out_array_val->type = result_type; | 6186 | out_array_val->type = out_array_type; |
| 6186 | out_val->data.x_ptr.base_ptr = out_array_val; | 6187 | out_val->data.x_ptr.base_ptr = out_array_val; |
| 6187 | out_val->data.x_ptr.index = 0; | 6188 | out_val->data.x_ptr.index = 0; |
| 6188 | out_val->data.x_ptr.special = ConstPtrSpecialCStr; | 6189 | out_val->data.x_ptr.special = ConstPtrSpecialCStr; |
src/ir_print.cpp+2| ... | @@ -100,6 +100,8 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { | ... | @@ -100,6 +100,8 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) { |
| 100 | fprintf(irp->f, "&"); | 100 | fprintf(irp->f, "&"); |
| 101 | if (const_val->data.x_ptr.special == ConstPtrSpecialRuntime) { | 101 | if (const_val->data.x_ptr.special == ConstPtrSpecialRuntime) { |
| 102 | fprintf(irp->f, "(runtime pointer value)"); | 102 | fprintf(irp->f, "(runtime pointer value)"); |
| 103 | } else if (const_val->data.x_ptr.special == ConstPtrSpecialCStr) { | ||
| 104 | fprintf(irp->f, "(c str lit)"); | ||
| 103 | } else { | 105 | } else { |
| 104 | ir_print_const_value(irp, const_ptr_pointee(const_val)); | 106 | ir_print_const_value(irp, const_ptr_pointee(const_val)); |
| 105 | } | 107 | } |
test/cases/misc.zig+22| ... | @@ -436,6 +436,28 @@ fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool { | ... | @@ -436,6 +436,28 @@ fn ptrEql(a: &[]const u8, b: &[]const u8) -> bool { |
| 436 | } | 436 | } |
| 437 | 437 | ||
| 438 | 438 | ||
| 439 | fn cStringConcatenation() { | ||
| 440 | @setFnTest(this); | ||
| 441 | |||
| 442 | const a = c"OK" ++ c" IT " ++ c"WORKED"; | ||
| 443 | const b = c"OK IT WORKED"; | ||
| 444 | |||
| 445 | const len = cstrlen(b); | ||
| 446 | const len_with_null = len + 1; | ||
| 447 | {var i: u32 = 0; while (i < len_with_null; i += 1) { | ||
| 448 | assert(a[i] == b[i]); | ||
| 449 | }} | ||
| 450 | assert(a[len] == 0); | ||
| 451 | assert(b[len] == 0); | ||
| 452 | } | ||
| 453 | |||
| 454 | // TODO import from std.cstr | ||
| 455 | pub fn cstrlen(ptr: &const u8) -> usize { | ||
| 456 | var count: usize = 0; | ||
| 457 | while (ptr[count] != 0; count += 1) {} | ||
| 458 | return count; | ||
| 459 | } | ||
| 460 | |||
| 439 | // TODO import from std.str | 461 | // TODO import from std.str |
| 440 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | 462 | pub fn memeql(a: []const u8, b: []const u8) -> bool { |
| 441 | sliceEql(u8, a, b) | 463 | sliceEql(u8, a, b) |
test/self_hosted.zig-16| ... | @@ -58,22 +58,6 @@ fn returnsTen() -> %i32 { | ... | @@ -58,22 +58,6 @@ fn returnsTen() -> %i32 { |
| 58 | 10 | 58 | 10 |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | // TODO not passing | ||
| 62 | fn cStringConcatenation() { | ||
| 63 | @setFnTest(this, true); | ||
| 64 | |||
| 65 | const a = c"OK" ++ c" IT " ++ c"WORKED"; | ||
| 66 | const b = c"OK IT WORKED"; | ||
| 67 | |||
| 68 | const len = cstrlen(b); | ||
| 69 | const len_with_null = len + 1; | ||
| 70 | {var i: u32 = 0; while (i < len_with_null; i += 1) { | ||
| 71 | assert(a[i] == b[i]); | ||
| 72 | }} | ||
| 73 | assert(a[len] == 0); | ||
| 74 | assert(b[len] == 0); | ||
| 75 | } | ||
| 76 | |||
| 77 | // TODO not passing | 61 | // TODO not passing |
| 78 | fn castSliceToU8Slice() { | 62 | fn castSliceToU8Slice() { |
| 79 | @setFnTest(this); | 63 | @setFnTest(this); |