diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-03-28 23:25:12 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-03-28 23:25:12 -0400 |
| commit | 032fccf6151ff201ce4b8c7ab28ca460fed794c0 (patch) | |
| tree | c784d6f1359e765f640dea70bdc71b77eaec0756 /src | |
| parent | 5627347bab01fa767c29d1434fcd6a600c98811a (diff) | |
| download | zig-032fccf6151ff201ce4b8c7ab28ca460fed794c0.tar.gz zig-032fccf6151ff201ce4b8c7ab28ca460fed794c0.zip | |
fix compile time array concatenation for slices
closes #866
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index ea001adb93..18fd02c297 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11058,6 +11058,24 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * result_type = get_array_type(ira->codegen, child_type, new_len); out_array_val = out_val; + } else if (is_slice(op1_type) || is_slice(op2_type)) { + TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, child_type, true); + result_type = get_slice_type(ira->codegen, ptr_type); + out_array_val = create_const_vals(1); + out_array_val->special = ConstValSpecialStatic; + out_array_val->type = get_array_type(ira->codegen, child_type, new_len); + + out_val->data.x_struct.fields = create_const_vals(2); + + out_val->data.x_struct.fields[slice_ptr_index].type = ptr_type; + out_val->data.x_struct.fields[slice_ptr_index].special = ConstValSpecialStatic; + out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.special = ConstPtrSpecialBaseArray; + out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.data.base_array.array_val = out_array_val; + out_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.data.base_array.elem_index = 0; + + out_val->data.x_struct.fields[slice_len_index].type = ira->codegen->builtin_types.entry_usize; + out_val->data.x_struct.fields[slice_len_index].special = ConstValSpecialStatic; + bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index].data.x_bigint, new_len); } else { new_len += 1; // null byte |
