Merge pull request #9875 from g-w1/timestimes

stage2: emit Value.repeated for `**` with array len 1
This commit is contained in:
Andrew Kelley
2021-10-02 16:05:12 -04:00
committed by GitHub
3 changed files with 38 additions and 10 deletions

View File

@@ -1024,6 +1024,7 @@ pub const DeclGen = struct {
else => |tag| return self.todo("implement const of pointer type '{}' ({})", .{ tv.ty, tag }),
},
.Array => {
const gpa = self.gpa;
if (tv.val.castTag(.bytes)) |payload| {
const zero_sentinel = if (tv.ty.sentinel()) |sentinel| blk: {
if (sentinel.tag() == .zero) break :blk true;
@@ -1037,7 +1038,6 @@ pub const DeclGen = struct {
);
}
if (tv.val.castTag(.array)) |payload| {
const gpa = self.gpa;
const elem_ty = tv.ty.elemType();
const elem_vals = payload.data;
const sento = tv.ty.sentinel();
@@ -1053,6 +1053,23 @@ pub const DeclGen = struct {
@intCast(c_uint, llvm_elems.len),
);
}
if (tv.val.castTag(.repeated)) |payload| {
const val = payload.data;
const elem_ty = tv.ty.elemType();
const len = tv.ty.arrayLen();
const llvm_elems = try gpa.alloc(*const llvm.Value, len);
defer gpa.free(llvm_elems);
var i: u64 = 0;
while (i < len) : (i += 1) {
llvm_elems[i] = try self.genTypedValue(.{ .ty = elem_ty, .val = val });
}
const llvm_elem_ty = try self.llvmType(elem_ty);
return llvm_elem_ty.constArray(
llvm_elems.ptr,
@intCast(c_uint, llvm_elems.len),
);
}
return self.todo("handle more array values", .{});
},
.Optional => {