mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-25 05:09:53 +00:00
Support []int{multiple_returns(), 123}
This commit is contained in:
@@ -10630,8 +10630,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
|
||||
cl->max_count = max;
|
||||
} else {
|
||||
isize index = 0;
|
||||
for (; index < cl->elems.count; index++) {
|
||||
for (isize index = 0; index < cl->elems.count; index++) {
|
||||
defer (max += 1);
|
||||
|
||||
Ast *e = cl->elems[index];
|
||||
if (e == nullptr) {
|
||||
error(node, "Invalid literal element");
|
||||
@@ -10648,17 +10649,25 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
}
|
||||
|
||||
Operand operand = {};
|
||||
check_expr_with_type_hint(c, &operand, e, elem_type);
|
||||
check_assignment(c, &operand, elem_type, context_name);
|
||||
check_multi_expr_with_type_hint(c, &operand, e, elem_type);
|
||||
if (is_type_tuple(operand.type)) {
|
||||
is_constant = false;
|
||||
TypeTuple *tt = &operand.type->Tuple;
|
||||
for_array(jj, tt->variables) {
|
||||
Operand oo = operand;
|
||||
oo.type = tt->variables[jj]->type;
|
||||
check_assignment(c, &oo, elem_type, context_name);
|
||||
}
|
||||
|
||||
if (is_constant) {
|
||||
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
|
||||
max += tt->variables.count-1;
|
||||
} else {
|
||||
check_assignment(c, &operand, elem_type, context_name);
|
||||
|
||||
if (is_constant) {
|
||||
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (max < index) {
|
||||
max = index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10679,6 +10688,12 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
error(node, "Expected %lld values for this #soa array literal, got %lld", cast(long long)t->Struct.soa_count, cast(long long)max);
|
||||
}
|
||||
}
|
||||
} else if (t->kind == Type_FixedCapacityDynamicArray) {
|
||||
if (max > t->FixedCapacityDynamicArray.capacity) {
|
||||
error(node, "Expected a maximum of %lld values for this fixed capacity dynamic array, got %lld",
|
||||
cast(long long)t->FixedCapacityDynamicArray.capacity,
|
||||
cast(long long)max);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10704,6 +10719,8 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
}
|
||||
}
|
||||
|
||||
cl->max_count = max;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1476,17 +1476,24 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
|
||||
return res;
|
||||
} else {
|
||||
// Assume that compound value is an array literal
|
||||
GB_ASSERT_MSG(elem_count == type->Array.count, "%td != %td", elem_count, type->Array.count);
|
||||
GB_ASSERT_MSG(elem_count <= type->Array.count, "%td <= %td", elem_count, type->Array.count);
|
||||
|
||||
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count);
|
||||
|
||||
isize elem_index = 0;
|
||||
for (isize i = 0; i < elem_count; i++) {
|
||||
TypeAndValue tav = cl->elems[i]->tav;
|
||||
GB_ASSERT(tav.mode != Addressing_Invalid);
|
||||
values[i] = lb_const_value(m, elem_type, tav.value, cc, tav.type).value;
|
||||
if (is_type_tuple(tav.type)) {
|
||||
elem_index += tav.type->Tuple.variables.count;
|
||||
} else {
|
||||
values[elem_index++] = lb_const_value(m, elem_type, tav.value, cc, tav.type).value;
|
||||
}
|
||||
}
|
||||
for (isize i = elem_count; i < type->Array.count; i++) {
|
||||
values[i] = LLVMConstNull(lb_type(m, elem_type));
|
||||
for (isize i = 0; i < type->Array.count; i++) {
|
||||
if (values[i] == nullptr) {
|
||||
values[i] = LLVMConstNull(lb_type(m, elem_type));
|
||||
}
|
||||
}
|
||||
|
||||
res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->Array.count, values, cc);
|
||||
@@ -1560,20 +1567,28 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
|
||||
res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->EnumeratedArray.count, values, cc);
|
||||
return res;
|
||||
} else {
|
||||
GB_ASSERT_MSG(elem_count == type->EnumeratedArray.count, "%td != %td", elem_count, type->EnumeratedArray.count);
|
||||
// Assume that compound value is an array literal
|
||||
GB_ASSERT_MSG(elem_count <= type->EnumeratedArray.count, "%td <= %td", elem_count, type->EnumeratedArray.count);
|
||||
|
||||
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->EnumeratedArray.count);
|
||||
|
||||
isize elem_index = 0;
|
||||
for (isize i = 0; i < elem_count; i++) {
|
||||
TypeAndValue tav = cl->elems[i]->tav;
|
||||
GB_ASSERT(tav.mode != Addressing_Invalid);
|
||||
values[i] = lb_const_value(m, elem_type, tav.value, cc, tav.type).value;
|
||||
if (is_type_tuple(tav.type)) {
|
||||
elem_index += tav.type->Tuple.variables.count;
|
||||
} else {
|
||||
values[elem_index++] = lb_const_value(m, elem_type, tav.value, cc, tav.type).value;
|
||||
}
|
||||
}
|
||||
for (isize i = elem_count; i < type->EnumeratedArray.count; i++) {
|
||||
values[i] = LLVMConstNull(lb_type(m, elem_type));
|
||||
for (isize i = 0; i < type->EnumeratedArray.count; i++) {
|
||||
if (values[i] == nullptr) {
|
||||
values[i] = LLVMConstNull(lb_type(m, elem_type));
|
||||
}
|
||||
}
|
||||
|
||||
res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->EnumeratedArray.count, values, cc);
|
||||
res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->Array.count, values, cc);
|
||||
return res;
|
||||
}
|
||||
} else if (is_type_fixed_capacity_dynamic_array(type)) {
|
||||
@@ -1666,16 +1681,23 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
|
||||
|
||||
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)capacity);
|
||||
|
||||
isize elem_index = 0;
|
||||
for (isize i = 0; i < elem_count; i++) {
|
||||
TypeAndValue tav = cl->elems[i]->tav;
|
||||
GB_ASSERT(tav.mode != Addressing_Invalid);
|
||||
values[i] = lb_const_value(m, elem_type, tav.value, cc, tav.type).value;
|
||||
if (is_type_tuple(tav.type)) {
|
||||
elem_index += tav.type->Tuple.variables.count;
|
||||
} else {
|
||||
values[elem_index++] = lb_const_value(m, elem_type, tav.value, cc, tav.type).value;
|
||||
}
|
||||
}
|
||||
for (isize i = elem_count; i < capacity; i++) {
|
||||
values[i] = LLVMConstNull(lb_type(m, elem_type));
|
||||
for (isize i = 0; i < capacity; i++) {
|
||||
if (values[i] == nullptr) {
|
||||
values[i] = LLVMConstNull(lb_type(m, elem_type));
|
||||
}
|
||||
}
|
||||
|
||||
res.value = lb_fill_fixed_capacity_dynamic_array(m, elem_count, original_type, values, cc);
|
||||
res.value = lb_fill_fixed_capacity_dynamic_array(m, elem_index, original_type, values, cc);
|
||||
return res;
|
||||
}
|
||||
} else if (is_type_simd_vector(type)) {
|
||||
|
||||
@@ -4516,9 +4516,9 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *
|
||||
GB_ASSERT(et != nullptr);
|
||||
|
||||
|
||||
isize elem_index = 0;
|
||||
// NOTE(bill): Separate value, gep, store into their own chunks
|
||||
for_array(i, elems) {
|
||||
Ast *elem = elems[i];
|
||||
for (Ast *elem : elems) {
|
||||
if (elem->kind == Ast_FieldValue) {
|
||||
ast_node(fv, FieldValue, elem);
|
||||
if (bt->kind != Type_DynamicArray && lb_is_elem_const(fv->value, et)) {
|
||||
@@ -4588,22 +4588,39 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *
|
||||
|
||||
} else {
|
||||
if (bt->kind != Type_DynamicArray && lb_is_elem_const(elem, et)) {
|
||||
elem_index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
lbValue field_expr = lb_build_expr(p, elem);
|
||||
GB_ASSERT(!is_type_tuple(field_expr.type));
|
||||
|
||||
lbValue ev = lb_emit_conv(p, field_expr, et);
|
||||
if (is_type_tuple(field_expr.type)) {
|
||||
TypeTuple *tt = &field_expr.type->Tuple;
|
||||
for_array(jj, tt->variables) {
|
||||
lbValue sub_field_expr = lb_emit_struct_ev(p, field_expr, cast(i32)jj);
|
||||
lbValue ev = lb_emit_conv(p, sub_field_expr, et);
|
||||
|
||||
lbCompoundLitElemTempData data = {};
|
||||
data.value = ev;
|
||||
if (bt->kind == Type_Matrix) {
|
||||
data.elem_index = matrix_row_major_index_to_offset(bt, i);
|
||||
lbCompoundLitElemTempData data = {};
|
||||
data.value = ev;
|
||||
if (bt->kind == Type_Matrix) {
|
||||
data.elem_index = matrix_row_major_index_to_offset(bt, elem_index++);
|
||||
} else {
|
||||
data.elem_index = elem_index++;
|
||||
}
|
||||
array_add(temp_data, data);
|
||||
}
|
||||
} else {
|
||||
data.elem_index = i;
|
||||
lbValue ev = lb_emit_conv(p, field_expr, et);
|
||||
|
||||
lbCompoundLitElemTempData data = {};
|
||||
data.value = ev;
|
||||
if (bt->kind == Type_Matrix) {
|
||||
data.elem_index = matrix_row_major_index_to_offset(bt, elem_index++);
|
||||
} else {
|
||||
data.elem_index = elem_index++;
|
||||
}
|
||||
array_add(temp_data, data);
|
||||
}
|
||||
array_add(temp_data, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user