Change interval syntax: .. open range, ..< half-closed range

This commit is contained in:
Ginger Bill
2017-04-20 23:22:45 +01:00
parent c5411a25a9
commit a713e33007
15 changed files with 98 additions and 59 deletions
+5 -5
View File
@@ -339,7 +339,7 @@ __bounds_check_error :: proc(file: string, line, column: int, index, count: int)
if 0 <= index && index < count {
return;
}
fmt.fprintf(os.stderr, "%s(%d:%d) Index %d is out of bounds range 0..%d\n",
fmt.fprintf(os.stderr, "%s(%d:%d) Index %d is out of bounds range 0..<%d\n",
file, line, column, index, count);
__debug_trap();
}
@@ -348,7 +348,7 @@ __slice_expr_error :: proc(file: string, line, column: int, low, high, max: int)
if 0 <= low && low <= high && high <= max {
return;
}
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid slice indices: [%d..%d..%d]\n",
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid slice indices: [%d..<%d..<%d]\n",
file, line, column, low, high, max);
__debug_trap();
}
@@ -356,7 +356,7 @@ __substring_expr_error :: proc(file: string, line, column: int, low, high: int)
if 0 <= low && low <= high {
return;
}
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid substring indices: [%d..%d]\n",
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid substring indices: [%d..<%d]\n",
file, line, column, low, high);
__debug_trap();
}
@@ -395,7 +395,7 @@ __mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr {
}
__mem_compare :: proc(a, b: ^byte, n: int) -> int {
for i in 0..n {
for i in 0..<n {
match {
case (a+i)^ < (b+i)^:
return -1;
@@ -602,7 +602,7 @@ __dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int) {
__dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count);
__dynamic_array_reserve(^nm.entries, entry_size, entry_align, m.entries.len);
for i in 0..new_count {
for i in 0..<new_count {
nm.hashes[i] = -1;
}
+9 -9
View File
@@ -22,29 +22,29 @@ decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
// TODO(bill): make this work with a buffer that's not big enough
assert(len(buf) >= n);
buf = buf[..n];
buf = buf[0..<n];
if a.count == 0 {
buf[0] = '0';
return cast(string)buf[0..1];
return cast(string)buf[0..<1];
}
w := 0;
if a.decimal_point <= 0 {
buf[w] = '0'; w++;
buf[w] = '.'; w++;
w += digit_zero(buf[w .. w-a.decimal_point]);
w += copy(buf[w..], a.digits[0..a.count]);
w += digit_zero(buf[w ..< w-a.decimal_point]);
w += copy(buf[w..], a.digits[0..<a.count]);
} else if a.decimal_point < a.count {
w += copy(buf[w..], a.digits[0..a.decimal_point]);
w += copy(buf[w..], a.digits[0..<a.decimal_point]);
buf[w] = '.'; w++;
w += copy(buf[w..], a.digits[a.decimal_point .. a.count]);
w += copy(buf[w..], a.digits[a.decimal_point ..< a.count]);
} else {
w += copy(buf[w..], a.digits[0..a.count]);
w += digit_zero(buf[w .. w+a.decimal_point-a.count]);
w += copy(buf[w..], a.digits[0..<a.count]);
w += digit_zero(buf[w ..< w+a.decimal_point-a.count]);
}
return cast(string)buf[0..w];
return cast(string)buf[0..<w];
}
// trim trailing zeros
+23 -23
View File
@@ -21,7 +21,7 @@ write_rune :: proc(buf: ^[]byte, r: rune) {
}
b, n := utf8.encode_rune(r);
append(buf, ..b[..n]);
append(buf, ..b[0..<n]);
}
Fmt_Info :: struct {
@@ -47,24 +47,24 @@ Fmt_Info :: struct {
fprint :: proc(fd: os.Handle, args: ..any) -> int {
data: [_BUFFER_SIZE]byte;
buf := data[..0];
buf := data[0..<0];
bprint(^buf, ..args);
os.write(fd, buf[..len(buf)]);
os.write(fd, buf);
return len(buf);
}
fprintln :: proc(fd: os.Handle, args: ..any) -> int {
data: [_BUFFER_SIZE]byte;
buf := data[..0];
buf := data[0..<0];
bprintln(^buf, ..args);
os.write(fd, buf[..len(buf)]);
os.write(fd, buf);
return len(buf);
}
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
data: [_BUFFER_SIZE]byte;
buf := data[..0];
buf := data[0..<0];
bprintf(^buf, fmt, ..args);
os.write(fd, buf[..len(buf)]);
os.write(fd, buf);
return len(buf);
}
@@ -82,9 +82,9 @@ printf :: proc(fmt: string, args: ..any) -> int {
fprint_type :: proc(fd: os.Handle, info: ^Type_Info) {
data: [_BUFFER_SIZE]byte;
buf := data[..0];
buf := data[0..<0];
write_type(^buf, info);
os.write(fd, buf[..len(buf)]);
os.write(fd, buf);
}
write_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
@@ -305,15 +305,15 @@ bprintln :: proc(buf: ^[]byte, args: ..any) -> int {
sprint :: proc(buf: []byte, args: ..any) -> string {
count := bprint(^buf, ..args);
return cast(string)buf[..count];
return cast(string)buf[0..<count];
}
sprintln :: proc(buf: []byte, args: ..any) -> string {
count := bprintln(^buf, ..args);
return cast(string)buf[..count];
return cast(string)buf[0..<count];
}
sprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
count := bprintf(^buf, fmt, ..args);
return cast(string)buf[..count];
return cast(string)buf[0..<count];
}
@@ -519,7 +519,7 @@ _write_int :: proc(fi: ^Fmt_Info, u: u64, base: int, is_signed: bool, bit_size:
if fi.hash { flags |= strconv.Int_Flag.PREFIX; }
if fi.plus { flags |= strconv.Int_Flag.PLUS; }
if fi.space { flags |= strconv.Int_Flag.SPACE; }
s := strconv.append_bits(buf[..0], u, base, is_signed, bit_size, digits, flags);
s := strconv.append_bits(buf[0..<0], u, base, is_signed, bit_size, digits, flags);
prev_zero := fi.zero;
defer fi.zero = prev_zero;
@@ -584,8 +584,8 @@ fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) {
prec = fi.prec;
}
buf: [128]byte;
str := strconv.append_float(buf[1..1], v, 'f', prec, bit_size);
str = cast(string)buf[..len(str)+1];
str := strconv.append_float(buf[1..<1], v, 'f', prec, bit_size);
str = cast(string)buf[0..<len(str)];
if str[1] == '+' || str[1] == '-' {
str = str[1..];
} else {
@@ -605,7 +605,7 @@ fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) {
if fi.zero && fi.width_set && fi.width > len(str) {
write_byte(fi.buf, str[0]);
fmt_write_padding(fi, fi.width - len(str));
write_string(fi.buf, str[1..]);
write_string(fi.buf, str[1..<]);
} else {
_pad(fi, str);
}
@@ -628,7 +628,7 @@ fmt_string :: proc(fi: ^Fmt_Info, s: string, verb: rune) {
fi.space = false;
defer fi.space = space;
for i in 0..len(s) {
for i in 0..<len(s) {
if i > 0 && space {
write_byte(fi.buf, ' ');
}
@@ -776,7 +776,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_byte(fi.buf, '[');
defer write_byte(fi.buf, ']');
for i in 0..info.count {
for i in 0..<info.count {
if i > 0 {
write_string(fi.buf, ", ");
}
@@ -793,7 +793,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_byte(fi.buf, '[');
defer write_byte(fi.buf, ']');
array := cast(^raw.Dynamic_Array)v.data;
for i in 0..array.len {
for i in 0..<array.len {
if i > 0 {
write_string(fi.buf, ", ");
}
@@ -815,7 +815,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
entry_type := union_cast(^Struct)ed.elem;
entry_size := ed.elem_size;
for i in 0..entries.len {
for i in 0..<entries.len {
if i > 0 {
write_string(fi.buf, ", ");
}
@@ -844,7 +844,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_byte(fi.buf, '[');
defer write_byte(fi.buf, ']');
slice := cast(^[]byte)v.data;
for i in 0..len(slice) {
for _, i in slice {
if i > 0 {
write_string(fi.buf, ", ");
}
@@ -856,7 +856,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_byte(fi.buf, '<');
defer write_byte(fi.buf, '>');
for i in 0..info.count {
for i in 0..<info.count {
if i > 0 {
write_string(fi.buf, ", ");
}
@@ -1011,7 +1011,7 @@ bprintf :: proc(b: ^[]byte, fmt: string, args: ..any) -> int {
i++;
}
if i > prev_i {
write_string(b, fmt[prev_i..i]);
write_string(b, fmt[prev_i..<i]);
}
if i >= end {
break;
+1 -1
View File
@@ -175,7 +175,7 @@ murmur64 :: proc(data: []byte) -> u64 {
}
// TODO(bill): Fix this
#no_bounds_check data8 := slice_to_bytes(data32[i..])[..3];
#no_bounds_check data8 := slice_to_bytes(data32[i..])[..<3];
match len {
case 3:
h2 ~= cast(u32)data8[2] << 16;
+4 -4
View File
@@ -160,8 +160,8 @@ mat4_identity :: proc() -> Mat4 {
}
mat4_transpose :: proc(m: Mat4) -> Mat4 {
for j in 0..4 {
for i in 0..4 {
for j in 0..<4 {
for i in 0..<4 {
m[i][j], m[j][i] = m[j][i], m[i][j];
}
}
@@ -170,8 +170,8 @@ mat4_transpose :: proc(m: Mat4) -> Mat4 {
mul :: proc(a, b: Mat4) -> Mat4 {
c: Mat4;
for j in 0..4 {
for i in 0..4 {
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] +
+2 -2
View File
@@ -96,7 +96,7 @@ Arena_Temp_Memory :: struct {
init_arena_from_memory :: proc(using a: ^Arena, data: []byte) {
backing = Allocator{};
memory = data[..0];
memory = data[0..<0];
temp_count = 0;
}
@@ -169,7 +169,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory {
end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) {
assert(len(arena.memory) >= original_count);
assert(arena.temp_count > 0);
arena.memory = arena.memory[..original_count];
arena.memory = arena.memory[0..<original_count];
arena.temp_count--;
}
+1 -1
View File
@@ -37,7 +37,7 @@ _libgl := win32.LoadLibraryA(_string_data("opengl32.dll\x00"));
GetProcAddress :: proc(name: string) -> proc() #cc_c {
if name[len(name)-1] == 0 {
name = name[..len(name)-1];
name = name[0..<len(name)-1];
}
// NOTE(bill): null terminated
assert((^name[0] + len(name))^ == 0);
+1 -1
View File
@@ -335,7 +335,7 @@ _alloc_command_line_arguments :: proc() -> []string {
}
}
return cast(string)buf[..i];
return cast(string)buf[0..<i];
}
arg_count: i32;
+3 -3
View File
@@ -182,7 +182,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
// integer, padded with zeros when needed
if digs.decimal_point > 0 {
m := min(digs.count, digs.decimal_point);
append(buf, ..digs.digits[..m]);
append(buf, ..digs.digits[0..<m]);
for ; m < digs.decimal_point; m++ {
append(buf, '0');
}
@@ -194,7 +194,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
// fractional part
if prec > 0 {
append(buf, '.');
for i in 0..prec {
for i in 0..<prec {
c: byte = '0';
if j := digs.decimal_point + i; 0 <= j && j < digs.count {
c = digs.digits[j];
@@ -258,7 +258,7 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^Float_Info) {
inclusive := mant%2 == 0;
for i in 0..d.count {
for i in 0..<d.count {
l: byte = '0'; // lower digit
if i < lower.count {
l = lower.digits[i];
+1 -1
View File
@@ -160,7 +160,7 @@ decode_last_rune :: proc(s: []byte) -> (rune, int) {
}
start = max(start, 0);
r, size = decode_rune(s[start..end]);
r, size = decode_rune(s[start..<end]);
if start+size != end {
return RUNE_ERROR, 1;
}