mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-08 19:44:20 +00:00
Make core library use a..<b rather than doing a..b-1
This commit is contained in:
@@ -32,7 +32,7 @@ Parser :: struct {
|
||||
|
||||
print_value :: proc(value: Value, pretty := true, indent := 0) {
|
||||
print_indent :: proc(indent: int) {
|
||||
for _ in 0..indent-1 do fmt.print("\t");
|
||||
for _ in 0..<indent do fmt.print("\t");
|
||||
}
|
||||
|
||||
switch v in value {
|
||||
@@ -237,7 +237,7 @@ unquote_char :: proc(s: string, quote: byte) -> (r: rune, multiple_bytes: bool,
|
||||
if len(s) < 2 {
|
||||
return;
|
||||
}
|
||||
for i in 0..len(s)-1 {
|
||||
for i in 0..<len(s) {
|
||||
d := int(s[i]-'0');
|
||||
if d < 0 || d > 7 {
|
||||
return;
|
||||
@@ -262,7 +262,7 @@ unquote_char :: proc(s: string, quote: byte) -> (r: rune, multiple_bytes: bool,
|
||||
return;
|
||||
}
|
||||
|
||||
for i in 0..count-1 {
|
||||
for i in 0..<count {
|
||||
d := hex_to_int(s[i]);
|
||||
if d < 0 {
|
||||
return;
|
||||
|
||||
@@ -144,7 +144,7 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
|
||||
|
||||
case Type_Info_Array:
|
||||
write_byte(b, '[');
|
||||
for i in 0..info.count-1 {
|
||||
for i in 0..<info.count {
|
||||
if i > 0 do write_string(b, ", ");
|
||||
|
||||
data := uintptr(v.data) + uintptr(i*info.elem_size);
|
||||
@@ -155,7 +155,7 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
|
||||
case Type_Info_Dynamic_Array:
|
||||
write_byte(b, '[');
|
||||
array := cast(^mem.Raw_Dynamic_Array)v.data;
|
||||
for i in 0..array.len-1 {
|
||||
for i in 0..<array.len {
|
||||
if i > 0 do write_string(b, ", ");
|
||||
|
||||
data := uintptr(array.data) + uintptr(i*info.elem_size);
|
||||
@@ -166,7 +166,7 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
|
||||
case Type_Info_Slice:
|
||||
write_byte(b, '[');
|
||||
slice := cast(^mem.Raw_Slice)v.data;
|
||||
for i in 0..slice.len-1 {
|
||||
for i in 0..<slice.len {
|
||||
if i > 0 do write_string(b, ", ");
|
||||
|
||||
data := uintptr(slice.data) + uintptr(i*info.elem_size);
|
||||
@@ -188,7 +188,7 @@ marshal_arg :: proc(b: ^strings.Builder, v: any) -> Marshal_Error {
|
||||
entry_type := ed.elem.variant.(Type_Info_Struct);
|
||||
entry_size := ed.elem_size;
|
||||
|
||||
for i in 0..entries.len-1 {
|
||||
for i in 0..<entries.len {
|
||||
if i > 0 do write_string(b, ", ");
|
||||
|
||||
data := uintptr(entries.data) + uintptr(i*entry_size);
|
||||
|
||||
@@ -336,7 +336,7 @@ _arg_number :: proc(fi: ^Info, arg_index: int, format: string, offset, arg_count
|
||||
parse_arg_number :: proc(format: string) -> (int, int, bool) {
|
||||
if len(format) < 3 do return 0, 1, false;
|
||||
|
||||
for i in 1..len(format)-1 {
|
||||
for i in 1..<len(format) {
|
||||
if format[i] == ']' {
|
||||
width, new_index, ok := _parse_int(format, 1);
|
||||
if !ok || new_index != i {
|
||||
@@ -658,7 +658,7 @@ fmt_string :: proc(fi: ^Info, s: string, verb: rune) {
|
||||
fi.space = false;
|
||||
defer fi.space = space;
|
||||
|
||||
for i in 0..len(s)-1 {
|
||||
for i in 0..<len(s) {
|
||||
if i > 0 && space do strings.write_byte(fi.buf, ' ');
|
||||
char_set := __DIGITS_UPPER;
|
||||
if verb == 'x' do char_set = __DIGITS_LOWER;
|
||||
@@ -859,7 +859,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "") {
|
||||
|
||||
e, is_enum := et.variant.(runtime.Type_Info_Enum);
|
||||
commas := 0;
|
||||
loop: for i in 0 .. bit_size-1 {
|
||||
loop: for i in 0 ..< bit_size {
|
||||
if bits & (1<<i) == 0 {
|
||||
continue loop;
|
||||
}
|
||||
@@ -929,7 +929,7 @@ fmt_opaque :: proc(fi: ^Info, v: any) {
|
||||
if n == 0 do return true;
|
||||
|
||||
a := (^byte)(data);
|
||||
for i in 0..n-1 do if mem.ptr_offset(a, i)^ != 0 {
|
||||
for i in 0..<n do if mem.ptr_offset(a, i)^ != 0 {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1001,7 +1001,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
field_count += 1;
|
||||
|
||||
if !hash && field_count > 0 do strings.write_string(fi.buf, ", ");
|
||||
if hash do for in 0..fi.indent-1 do strings.write_byte(fi.buf, '\t');
|
||||
if hash do for in 0..<fi.indent do strings.write_byte(fi.buf, '\t');
|
||||
|
||||
strings.write_string(fi.buf, name);
|
||||
strings.write_string(fi.buf, " = ");
|
||||
@@ -1016,7 +1016,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
if hash do strings.write_string(fi.buf, ",\n");
|
||||
}
|
||||
|
||||
if hash do for in 0..indent-1 do strings.write_byte(fi.buf, '\t');
|
||||
if hash do for in 0..<indent do strings.write_byte(fi.buf, '\t');
|
||||
strings.write_byte(fi.buf, '}');
|
||||
|
||||
case runtime.Type_Info_Bit_Set:
|
||||
@@ -1083,7 +1083,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
case runtime.Type_Info_Array:
|
||||
strings.write_byte(fi.buf, '[');
|
||||
defer strings.write_byte(fi.buf, ']');
|
||||
for i in 0..info.count-1 {
|
||||
for i in 0..<info.count {
|
||||
if i > 0 do strings.write_string(fi.buf, ", ");
|
||||
|
||||
data := uintptr(v.data) + uintptr(i*info.elem_size);
|
||||
@@ -1098,7 +1098,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
strings.write_byte(fi.buf, '[');
|
||||
defer strings.write_byte(fi.buf, ']');
|
||||
array := cast(^mem.Raw_Dynamic_Array)v.data;
|
||||
for i in 0..array.len-1 {
|
||||
for i in 0..<array.len {
|
||||
if i > 0 do strings.write_string(fi.buf, ", ");
|
||||
|
||||
data := uintptr(array.data) + uintptr(i*info.elem_size);
|
||||
@@ -1112,7 +1112,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
}
|
||||
strings.write_byte(fi.buf, '<');
|
||||
defer strings.write_byte(fi.buf, '>');
|
||||
for i in 0..info.count-1 {
|
||||
for i in 0..<info.count {
|
||||
if i > 0 do strings.write_string(fi.buf, ", ");
|
||||
|
||||
data := uintptr(v.data) + uintptr(i*info.elem_size);
|
||||
@@ -1128,7 +1128,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
strings.write_byte(fi.buf, '[');
|
||||
defer strings.write_byte(fi.buf, ']');
|
||||
slice := cast(^mem.Raw_Slice)v.data;
|
||||
for i in 0..slice.len-1 {
|
||||
for i in 0..<slice.len {
|
||||
if i > 0 do strings.write_string(fi.buf, ", ");
|
||||
|
||||
data := uintptr(slice.data) + uintptr(i*info.elem_size);
|
||||
@@ -1155,7 +1155,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
entry_type := ed.elem.variant.(runtime.Type_Info_Struct);
|
||||
entry_size := ed.elem_size;
|
||||
|
||||
for i in 0..entries.len-1 {
|
||||
for i in 0..<entries.len {
|
||||
if i > 0 do strings.write_string(fi.buf, ", ");
|
||||
|
||||
data := uintptr(entries.data) + uintptr(i*entry_size);
|
||||
@@ -1194,7 +1194,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
for _, i in info.names {
|
||||
if !hash && i > 0 do strings.write_string(fi.buf, ", ");
|
||||
if hash {
|
||||
for in 0..fi.indent-1 {
|
||||
for in 0..<fi.indent {
|
||||
strings.write_byte(fi.buf, '\t');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ cross :: proc{cross2, cross3};
|
||||
|
||||
vec_dot :: proc(a, b: $T/[$N]$E) -> E {
|
||||
res: E;
|
||||
for i in 0..N-1 {
|
||||
for i in 0..<N {
|
||||
res += a[i] * b[i];
|
||||
}
|
||||
return res;
|
||||
@@ -298,13 +298,13 @@ norm0 :: proc(v: $T/[$N]$E) -> T {
|
||||
|
||||
identity :: proc($T: typeid/[$N][N]$E) -> T {
|
||||
m: T;
|
||||
for i in 0..N-1 do m[i][i] = E(1);
|
||||
for i in 0..<N do m[i][i] = E(1);
|
||||
return m;
|
||||
}
|
||||
|
||||
transpose :: proc(m: $M/[$N][N]f32) -> M {
|
||||
for j in 0..N-1 {
|
||||
for i in 0..N-1 {
|
||||
for j in 0..<N {
|
||||
for i in 0..<N {
|
||||
m[i][j], m[j][i] = m[j][i], m[i][j];
|
||||
}
|
||||
}
|
||||
@@ -313,8 +313,8 @@ transpose :: proc(m: $M/[$N][N]f32) -> M {
|
||||
|
||||
mat3_mul :: proc(a, b: Mat3) -> Mat3 {
|
||||
c: Mat3;
|
||||
for j in 0..2 {
|
||||
for i in 0..2 {
|
||||
for j in 0..<3 {
|
||||
for i in 0..<3 {
|
||||
c[j][i] = a[0][i]*b[j][0] +
|
||||
a[1][i]*b[j][1] +
|
||||
a[2][i]*b[j][2];
|
||||
@@ -325,8 +325,8 @@ mat3_mul :: proc(a, b: Mat3) -> Mat3 {
|
||||
|
||||
mat4_mul :: proc(a, b: Mat4) -> Mat4 {
|
||||
c: Mat4;
|
||||
for j in 0..3 {
|
||||
for i in 0..3 {
|
||||
for j in 0..<4 {
|
||||
for i in 0..<4 {
|
||||
c[j][i] = a[0][i]*b[j][0] +
|
||||
a[1][i]*b[j][1] +
|
||||
a[2][i]*b[j][2] +
|
||||
|
||||
@@ -892,7 +892,7 @@ __dynamic_map_reserve :: proc(using header: Map_Header, cap: int, loc := #caller
|
||||
|
||||
old_len := len(m.hashes);
|
||||
__slice_resize(&m.hashes, cap, m.entries.allocator, loc);
|
||||
for i in old_len..len(m.hashes)-1 do m.hashes[i] = -1;
|
||||
for i in old_len..<len(m.hashes) do m.hashes[i] = -1;
|
||||
|
||||
}
|
||||
__dynamic_map_rehash :: proc(using header: Map_Header, new_count: int, loc := #caller_location) #no_bounds_check {
|
||||
@@ -909,9 +909,9 @@ __dynamic_map_rehash :: proc(using header: Map_Header, new_count: int, loc := #c
|
||||
|
||||
__dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len, loc);
|
||||
__slice_resize(&nm.hashes, new_count, m.entries.allocator, loc);
|
||||
for i in 0 .. new_count-1 do nm.hashes[i] = -1;
|
||||
for i in 0 ..< new_count do nm.hashes[i] = -1;
|
||||
|
||||
for i in 0 .. m.entries.len-1 {
|
||||
for i in 0 ..< m.entries.len {
|
||||
if len(nm.hashes) == 0 do __dynamic_map_grow(new_header, loc);
|
||||
|
||||
entry_header := __dynamic_map_get_entry(header, i);
|
||||
|
||||
@@ -11,7 +11,7 @@ bubble_sort_proc :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
for {
|
||||
init_swap, prev_swap := -1, -1;
|
||||
|
||||
for j in init_j..last_j-1 {
|
||||
for j in init_j..<last_j {
|
||||
if f(array[j], array[j+1]) > 0 {
|
||||
array[j], array[j+1] = array[j+1], array[j];
|
||||
prev_swap = j;
|
||||
@@ -34,7 +34,7 @@ bubble_sort :: proc(array: $A/[]$T) {
|
||||
for {
|
||||
init_swap, prev_swap := -1, -1;
|
||||
|
||||
for j in init_j..last_j-1 {
|
||||
for j in init_j..<last_j {
|
||||
if array[j] > array[j+1] {
|
||||
array[j], array[j+1] = array[j+1], array[j];
|
||||
prev_swap = j;
|
||||
@@ -106,7 +106,7 @@ merge_sort_proc :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
merge_slices :: proc(arr1, arr2, out: A, f: proc(T, T) -> int) {
|
||||
N1, N2 := len(arr1), len(arr2);
|
||||
i, j := 0, 0;
|
||||
for k in 0..N1+N2-1 {
|
||||
for k in 0..<N1+N2 {
|
||||
if j == N2 || i < N1 && j < N2 && f(arr1[i], arr2[j]) < 0 {
|
||||
out[k] = arr1[i];
|
||||
i += 1;
|
||||
@@ -127,7 +127,7 @@ merge_sort_proc :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
a, b, m, M := N/2, N, 1, _log2(N);
|
||||
|
||||
for i in 0..M {
|
||||
for j in 0..a-1 {
|
||||
for j in 0..<a {
|
||||
k := 2*j*m;
|
||||
merge_slices(arr1[k:k+m], arr1[k+m:k+m+m], arr2[k:], f);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ merge_sort :: proc(array: $A/[]$T) {
|
||||
merge_slices :: proc(arr1, arr2, out: A) {
|
||||
N1, N2 := len(arr1), len(arr2);
|
||||
i, j := 0, 0;
|
||||
for k in 0..N1+N2-1 {
|
||||
for k in 0..<N1+N2 {
|
||||
if j == N2 || i < N1 && j < N2 && arr1[i] < arr2[j] {
|
||||
out[k] = arr1[i];
|
||||
i += 1;
|
||||
@@ -169,7 +169,7 @@ merge_sort :: proc(array: $A/[]$T) {
|
||||
a, b, m, M := N/2, N, 1, _log2(N);
|
||||
|
||||
for i in 0..M {
|
||||
for j in 0..a-1 {
|
||||
for j in 0..<a {
|
||||
k := 2*j*m;
|
||||
merge_slices(arr1[k:k+m], arr1[k+m:k+m+m], arr2[k:]);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
|
||||
// fractional part
|
||||
if prec > 0 {
|
||||
add_bytes(&b, '.');
|
||||
for i in 0..prec-1 {
|
||||
for i in 0..<prec {
|
||||
c: byte = '0';
|
||||
if j := digs.decimal_point + i; 0 <= j && j < digs.count {
|
||||
c = digs.digits[j];
|
||||
@@ -255,7 +255,7 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^Float_Info) {
|
||||
|
||||
inclusive := mant%2 == 0;
|
||||
|
||||
for i in 0..d.count-1 {
|
||||
for i in 0..<d.count {
|
||||
l: byte = '0'; // lower digit
|
||||
if i < lower.count {
|
||||
l = lower.digits[i];
|
||||
|
||||
@@ -33,7 +33,7 @@ encode :: proc(d: []u16, s: []rune) -> int {
|
||||
n, m := 0, len(d);
|
||||
loop: for r in s {
|
||||
switch r {
|
||||
case 0.._surr1-1, _surr3 .. _surr_self-1:
|
||||
case 0..<_surr1, _surr3 ..< _surr_self:
|
||||
if m+1 < n do break loop;
|
||||
d[n] = u16(r);
|
||||
n += 1;
|
||||
@@ -59,7 +59,7 @@ encode_string :: proc(d: []u16, s: string) -> int {
|
||||
n, m := 0, len(d);
|
||||
loop: for r in s {
|
||||
switch r {
|
||||
case 0.._surr1-1, _surr3 .. _surr_self-1:
|
||||
case 0..<_surr1, _surr3 ..< _surr_self:
|
||||
if m+1 < n do break loop;
|
||||
d[n] = u16(r);
|
||||
n += 1;
|
||||
|
||||
Reference in New Issue
Block a user