mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add ranged_fields_for_array_compound_literals
This commit is contained in:
+37
-7
@@ -1194,13 +1194,43 @@ ranged_fields_for_array_compound_literals :: proc() {
|
|||||||
foo := [?]int{1, 4, 9, 16};
|
foo := [?]int{1, 4, 9, 16};
|
||||||
fmt.println(foo);
|
fmt.println(foo);
|
||||||
}
|
}
|
||||||
i := 2;
|
{ // Indexed
|
||||||
foo := [?]int {
|
foo := [?]int{
|
||||||
0 = 123,
|
3 = 16,
|
||||||
5..9 = 54,
|
1 = 4,
|
||||||
10..<16 = i*3 + (i-1)*2,
|
2 = 9,
|
||||||
};
|
0 = 1,
|
||||||
fmt.println(foo); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
};
|
||||||
|
fmt.println(foo);
|
||||||
|
}
|
||||||
|
{ // Ranges
|
||||||
|
i := 2;
|
||||||
|
foo := [?]int {
|
||||||
|
0 = 123,
|
||||||
|
5..9 = 54,
|
||||||
|
10..<16 = i*3 + (i-1)*2,
|
||||||
|
};
|
||||||
|
#assert(len(foo) == 16);
|
||||||
|
fmt.println(foo); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||||
|
}
|
||||||
|
{ // Slice and Dynamic Array support
|
||||||
|
i := 2;
|
||||||
|
foo_slice := []int {
|
||||||
|
0 = 123,
|
||||||
|
5..9 = 54,
|
||||||
|
10..<16 = i*3 + (i-1)*2,
|
||||||
|
};
|
||||||
|
assert(len(foo) == 16);
|
||||||
|
fmt.println(foo_slice); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||||
|
|
||||||
|
foo_dynamic_array := [dynamic]int {
|
||||||
|
0 = 123,
|
||||||
|
5..9 = 54,
|
||||||
|
10..<16 = i*3 + (i-1)*2,
|
||||||
|
};
|
||||||
|
assert(len(foo) == 16);
|
||||||
|
fmt.println(foo_dynamic_array); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
|||||||
+6
-3
@@ -7205,10 +7205,13 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
|
|
||||||
i64 lo = exact_value_to_i64(x.value);
|
i64 lo = exact_value_to_i64(x.value);
|
||||||
i64 hi = exact_value_to_i64(y.value);
|
i64 hi = exact_value_to_i64(y.value);
|
||||||
|
i64 max_index = hi;
|
||||||
if (op.kind == Token_RangeHalf) {
|
if (op.kind == Token_RangeHalf) {
|
||||||
hi -= 1;
|
hi -= 1;
|
||||||
}
|
}
|
||||||
i64 max_index = hi;
|
if (op.kind == Token_Ellipsis) {
|
||||||
|
max_index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
bool new_range = range_cache_add_range(&rc, lo, hi);
|
bool new_range = range_cache_add_range(&rc, lo, hi);
|
||||||
if (!new_range) {
|
if (!new_range) {
|
||||||
@@ -7257,8 +7260,8 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max < index) {
|
if (max < index+1) {
|
||||||
max = index;
|
max = index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Operand operand = {};
|
Operand operand = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user