From 0718f14774c152b84edb747c03ca53b9400407b9 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 1 Aug 2018 21:34:59 +0100 Subject: [PATCH] Reduce number of range and slice operators #239 Replace .. and ... with : and .. --- core/decimal/decimal.odin | 18 ++--- core/fmt/fmt.odin | 118 ++++++++++++++-------------- core/hash/hash.odin | 4 +- core/math/math.odin | 16 ++-- core/mem/mem.odin | 4 +- core/opengl/opengl.odin | 2 +- core/os/os.odin | 2 +- core/os/os_essence.odin | 2 +- core/os/os_linux.odin | 2 +- core/os/os_osx.odin | 2 +- core/os/os_windows.odin | 6 +- core/runtime/core.odin | 8 +- core/runtime/internal.odin | 14 ++-- core/sort/sort.odin | 36 ++++----- core/strconv/strconv.odin | 56 ++++++------- core/strings/strings.odin | 2 +- core/unicode/utf16/utf16.odin | 4 +- core/unicode/utf8/utf8.odin | 2 +- examples/demo/demo.odin | 18 ++--- examples/old_demos/demo002.odin | 6 +- examples/old_demos/demo004.odin | 4 +- examples/old_demos/demo006.odin | 4 +- examples/old_demos/demo007.odin | 12 +-- examples/old_demos/demo008.odin | 12 +-- examples/old_stuff/demo_backup.odin | 8 +- src/check_expr.cpp | 4 +- src/check_stmt.cpp | 9 +-- src/check_type.cpp | 2 +- src/ir.cpp | 10 +-- src/parser.cpp | 18 ++--- src/tokenizer.cpp | 18 +++-- 31 files changed, 204 insertions(+), 219 deletions(-) diff --git a/core/decimal/decimal.odin b/core/decimal/decimal.odin index 497c51918..22498cb8a 100644 --- a/core/decimal/decimal.odin +++ b/core/decimal/decimal.odin @@ -20,29 +20,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[0..n]; + buf = buf[0:n]; if a.count == 0 { buf[0] = '0'; - return string(buf[0..1]); + return string(buf[0:1]); } w := 0; if a.decimal_point <= 0 { buf[w] = '0'; w += 1; buf[w] = '.'; w += 1; - 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 += 1; - 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 string(buf[0..w]); + return string(buf[0:w]); } // trim trailing zeros diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index bfa108aad..fb5bb2f70 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -45,7 +45,7 @@ string_buffer_from_slice :: proc(backing: []byte) -> String_Buffer { to_string :: proc(buf: String_Buffer) -> string { - return string(buf[..]); + return string(buf[:]); } @@ -53,7 +53,7 @@ write_string :: proc(buf: ^String_Buffer, s: string) { append_string(buf, s); } write_bytes :: proc(buf: ^String_Buffer, data: []byte) { - append(buf, ...data); + append(buf, ..data); } write_byte :: proc(buf: ^String_Buffer, data: byte) { append(buf, data); @@ -65,79 +65,79 @@ write_rune :: proc(buf: ^String_Buffer, r: rune) { } b, n := utf8.encode_rune(r); - write_bytes(buf, b[..n]); + write_bytes(buf, b[:n]); } write_i64 :: proc(buf: ^String_Buffer, i: i64, base: int) { b: [129]byte; - s := strconv.append_bits(b[..], u64(i), base, true, 64, strconv.digits, 0); + s := strconv.append_bits(b[:], u64(i), base, true, 64, strconv.digits, 0); write_string(buf, s); } -fprint :: proc(fd: os.Handle, args: ...any) -> int { +fprint :: proc(fd: os.Handle, args: ..any) -> int { data: [_BUFFER_SIZE]byte; - buf := string_buffer_from_slice(data[..]); - res := sbprint(&buf, ...args); + buf := string_buffer_from_slice(data[:]); + res := sbprint(&buf, ..args); os.write_string(fd, res); return len(res); } -fprintln :: proc(fd: os.Handle, args: ...any) -> int { +fprintln :: proc(fd: os.Handle, args: ..any) -> int { data: [_BUFFER_SIZE]byte; - buf := string_buffer_from_slice(data[..]); - res := sbprintln(&buf, ...args); + buf := string_buffer_from_slice(data[:]); + res := sbprintln(&buf, ..args); os.write_string(fd, res); return len(res); } -fprintf :: proc(fd: os.Handle, fmt: string, args: ...any) -> int { +fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int { data: [_BUFFER_SIZE]byte; - buf := string_buffer_from_slice(data[..]); - res := sbprintf(&buf, fmt, ...args); + buf := string_buffer_from_slice(data[:]); + res := sbprintf(&buf, fmt, ..args); os.write_string(fd, res); return len(res); } // print* procedures return the number of bytes written -print :: proc(args: ...any) -> int { return fprint(os.stdout, ...args); } -print_err :: proc(args: ...any) -> int { return fprint(os.stderr, ...args); } -println :: proc(args: ...any) -> int { return fprintln(os.stdout, ...args); } -println_err :: proc(args: ...any) -> int { return fprintln(os.stderr, ...args); } -printf :: proc(fmt: string, args: ...any) -> int { return fprintf(os.stdout, fmt, ...args); } -printf_err :: proc(fmt: string, args: ...any) -> int { return fprintf(os.stderr, fmt, ...args); } +print :: proc(args: ..any) -> int { return fprint(os.stdout, ..args); } +print_err :: proc(args: ..any) -> int { return fprint(os.stderr, ..args); } +println :: proc(args: ..any) -> int { return fprintln(os.stdout, ..args); } +println_err :: proc(args: ..any) -> int { return fprintln(os.stderr, ..args); } +printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args); } +printf_err :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args); } // aprint* procedures return a string that was allocated with the current context // They must be freed accordingly -aprint :: proc(args: ...any) -> string { +aprint :: proc(args: ..any) -> string { buf := String_Buffer(make([dynamic]byte)); - sbprint(&buf, ...args); + sbprint(&buf, ..args); return to_string(buf); } -aprintln :: proc(args: ...any) -> string { +aprintln :: proc(args: ..any) -> string { buf := String_Buffer(make([dynamic]byte)); - sbprintln(&buf, ...args); + sbprintln(&buf, ..args); return to_string(buf); } -aprintf :: proc(fmt: string, args: ...any) -> string { +aprintf :: proc(fmt: string, args: ..any) -> string { buf := String_Buffer(make([dynamic]byte)); - sbprintf(&buf, fmt, ...args); + sbprintf(&buf, fmt, ..args); return to_string(buf); } // bprint* procedures return a string using a buffer from an array -bprint :: proc(buf: []byte, args: ...any) -> string { - sb := string_buffer_from_slice(buf[0..len(buf)]); - return sbprint(&sb, ...args); +bprint :: proc(buf: []byte, args: ..any) -> string { + sb := string_buffer_from_slice(buf[0:len(buf)]); + return sbprint(&sb, ..args); } -bprintln :: proc(buf: []byte, args: ...any) -> string { - sb := string_buffer_from_slice(buf[0..len(buf)]); - return sbprintln(&sb, ...args); +bprintln :: proc(buf: []byte, args: ..any) -> string { + sb := string_buffer_from_slice(buf[0:len(buf)]); + return sbprintln(&sb, ..args); } -bprintf :: proc(buf: []byte, fmt: string, args: ...any) -> string { - sb := string_buffer_from_slice(buf[0..len(buf)]); - return sbprintf(&sb, fmt, ...args); +bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string { + sb := string_buffer_from_slice(buf[0:len(buf)]); + return sbprintf(&sb, fmt, ..args); } @@ -147,9 +147,9 @@ bprintf :: proc(buf: []byte, fmt: string, args: ...any) -> string { fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) { data: [_BUFFER_SIZE]byte; - buf := string_buffer_from_slice(data[..]); + buf := string_buffer_from_slice(data[:]); write_type(&buf, info); - os.write(fd, buf[..]); + os.write(fd, buf[:]); } write_typeid :: proc(buf: ^String_Buffer, id: typeid) { @@ -336,7 +336,7 @@ _arg_number :: proc(fi: ^Fmt_Info, arg_index: int, format: string, offset, arg_c parse_arg_number :: proc(format: string) -> (int, int, bool) { if len(format) < 3 do return 0, 1, false; - for i in 1...len(format) { + for i in 1..len(format)-1 { if format[i] == ']' { width, new_index, ok := _parse_int(format, 1); if !ok || new_index != i { @@ -356,7 +356,7 @@ _arg_number :: proc(fi: ^Fmt_Info, arg_index: int, format: string, offset, arg_c fi.reordered = true; width: int; - index, width, ok = parse_arg_number(format[offset..]); + index, width, ok = parse_arg_number(format[offset:]); if ok && 0 <= index && index < arg_count { return index, offset+width, true; } @@ -421,7 +421,7 @@ fmt_write_padding :: proc(fi: ^Fmt_Info, width: int) { pad_byte: byte = '0'; if fi.space do pad_byte = ' '; - for _ in 0..width { + for _ in 0..width-1 { write_byte(fi.buf, pad_byte); } } @@ -470,7 +470,7 @@ _fmt_int :: proc(fi: ^Fmt_Info, u: u64, base: int, is_signed: bool, bit_size: in if fi.hash && !fi.zero do flags |= strconv.Int_Flag.Prefix; if fi.plus do flags |= strconv.Int_Flag.Plus; if fi.space do flags |= strconv.Int_Flag.Space; - s := strconv.append_bits(buf[start..], u, base, is_signed, bit_size, digits, flags); + s := strconv.append_bits(buf[start:], u, base, is_signed, bit_size, digits, flags); if fi.hash && fi.zero { c: byte = 0; @@ -557,10 +557,10 @@ fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) { if fi.prec_set do prec = fi.prec; buf: [386]byte; - str := strconv.append_float(buf[1..], v, 'f', prec, bit_size); - str = string(buf[...len(str)]); + str := strconv.append_float(buf[1:], v, 'f', prec, bit_size); + str = string(buf[:len(str)+1]); if str[1] == '+' || str[1] == '-' { - str = str[1..]; + str = str[1:]; } else { str[0] = '+'; } @@ -578,12 +578,12 @@ 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); } } else { - _pad(fi, str[1..]); + _pad(fi, str[1:]); } case: @@ -600,7 +600,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)-1 { if i > 0 && space do write_byte(fi.buf, ' '); char_set := __DIGITS_UPPER; if verb == 'x' do char_set = __DIGITS_LOWER; @@ -747,7 +747,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { for _, i in b.names { if !hash && i > 0 do write_string(fi.buf, ", "); - if hash do for in 0..fi.indent do write_byte(fi.buf, '\t'); + if hash do for in 0..fi.indent-1 do write_byte(fi.buf, '\t'); write_string(fi.buf, b.names[i]); write_string(fi.buf, " = "); @@ -762,7 +762,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { if hash do write_string(fi.buf, ",\n"); } - if hash do for in 0..indent do write_byte(fi.buf, '\t'); + if hash do for in 0..indent-1 do write_byte(fi.buf, '\t'); write_byte(fi.buf, '}'); case: @@ -786,7 +786,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { case runtime.Type_Info_Array: write_byte(fi.buf, '['); defer write_byte(fi.buf, ']'); - for i in 0..info.count { + for i in 0..info.count-1 { if i > 0 do write_string(fi.buf, ", "); data := uintptr(v.data) + uintptr(i*info.elem_size); @@ -797,7 +797,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { write_byte(fi.buf, '['); defer write_byte(fi.buf, ']'); array := cast(^mem.Raw_Dynamic_Array)v.data; - for i in 0..array.len { + for i in 0..array.len-1 { if i > 0 do write_string(fi.buf, ", "); data := uintptr(array.data) + uintptr(i*info.elem_size); @@ -808,7 +808,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { write_byte(fi.buf, '['); defer write_byte(fi.buf, ']'); slice := cast(^mem.Raw_Slice)v.data; - for i in 0..slice.len { + for i in 0..slice.len-1 { if i > 0 do write_string(fi.buf, ", "); data := uintptr(slice.data) + uintptr(i*info.elem_size); @@ -833,7 +833,7 @@ fmt_value :: proc(fi: ^Fmt_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 { + for i in 0..entries.len-1 { if i > 0 do write_string(fi.buf, ", "); data := uintptr(entries.data) + uintptr(i*entry_size); @@ -872,7 +872,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) { for _, i in info.names { if !hash && i > 0 do write_string(fi.buf, ", "); if hash { - for in 0..fi.indent { + for in 0..fi.indent-1 { write_byte(fi.buf, '\t'); } } @@ -1007,7 +1007,7 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) { -sbprint :: proc(buf: ^String_Buffer, args: ...any) -> string { +sbprint :: proc(buf: ^String_Buffer, args: ..any) -> string { fi: Fmt_Info; prev_string := false; @@ -1024,7 +1024,7 @@ sbprint :: proc(buf: ^String_Buffer, args: ...any) -> string { return to_string(buf^); } -sbprintln :: proc(buf: ^String_Buffer, args: ...any) -> string { +sbprintln :: proc(buf: ^String_Buffer, args: ..any) -> string { fi: Fmt_Info; fi.buf = buf; @@ -1037,7 +1037,7 @@ sbprintln :: proc(buf: ^String_Buffer, args: ...any) -> string { return to_string(buf^); } -sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string { +sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ..any) -> string { fi: Fmt_Info; arg_index: int = 0; end := len(fmt); @@ -1052,7 +1052,7 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string { i += 1; } if i > prev_i { - write_string(b, fmt[prev_i..i]); + write_string(b, fmt[prev_i:i]); } if i >= end { break loop; @@ -1138,7 +1138,7 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string { break loop; } - verb, w := utf8.decode_rune_from_string(fmt[i..]); + verb, w := utf8.decode_rune_from_string(fmt[i:]); i += w; switch { @@ -1156,7 +1156,7 @@ sbprintf :: proc(b: ^String_Buffer, fmt: string, args: ...any) -> string { if !fi.reordered && arg_index < len(args) { write_string(b, "%!(EXTRA "); - for arg, index in args[arg_index..] { + for arg, index in args[arg_index:] { if index > 0 do write_string(b, ", "); if arg == nil do write_string(b, ""); diff --git a/core/hash/hash.odin b/core/hash/hash.odin index 2c3a503cb..47f0be8a6 100644 --- a/core/hash/hash.odin +++ b/core/hash/hash.odin @@ -80,7 +80,7 @@ murmur32 :: proc(data: []byte) -> u32 { h1 = h1*5 + 0xe6546b64; } - tail := data[nblocks*4 ..]; + tail := data[nblocks*4:]; k1: u32; switch len(tail)&3 { case 3: @@ -187,7 +187,7 @@ murmur64 :: proc(data: []byte) -> u64 { } // TODO(bill): Fix this - #no_bounds_check data8 := mem.slice_to_bytes(data32[i..])[..3]; + #no_bounds_check data8 := mem.slice_to_bytes(data32[i:])[:3]; switch len { case 3: h2 ~= u32(data8[2]) << 16; diff --git a/core/math/math.odin b/core/math/math.odin index d85a1f300..4b891f942 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -164,7 +164,7 @@ cross :: proc[cross2, cross3]; vec_dot :: proc(a, b: $T/[$N]$E) -> E { res: E; - for i in 0..N { + for i in 0..N-1 { res += a[i] * b[i]; } return res; @@ -194,13 +194,13 @@ norm0 :: proc(v: $T/[$N]$E) -> T { identity :: proc(T: type/[$N][N]$E) -> T { m: T; - for i in 0..N do m[i][i] = E(1); + for i in 0..N-1 do m[i][i] = E(1); return m; } transpose :: proc(m: $M/[$N][N]f32) -> M { - for j in 0..N { - for i in 0..N { + for j in 0..N-1 { + for i in 0..N-1 { m[i][j], m[j][i] = m[j][i], m[i][j]; } } @@ -209,8 +209,8 @@ transpose :: proc(m: $M/[$N][N]f32) -> M { mat3_mul :: proc(a, b: Mat3) -> Mat3 { c: Mat3; - for j in 0..3 { - for i in 0..3 { + for j in 0..2 { + for i in 0..2 { c[j][i] = a[0][i]*b[j][0] + a[1][i]*b[j][1] + a[2][i]*b[j][2]; @@ -221,8 +221,8 @@ mat3_mul :: proc(a, b: Mat3) -> Mat3 { mat4_mul :: proc(a, b: Mat4) -> Mat4 { c: Mat4; - for j in 0..4 { - for i in 0..4 { + 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] + diff --git a/core/mem/mem.odin b/core/mem/mem.odin index f8261c026..64bed838a 100644 --- a/core/mem/mem.odin +++ b/core/mem/mem.odin @@ -62,7 +62,7 @@ compare :: proc "contextless" (a, b: []byte) -> int { } compare_byte_ptrs :: proc "contextless" (a, b: ^byte, n: int) -> int { pa :: ptr_offset; - for i in 0..n do switch { + for i in 0..n-1 do switch { case pa(a, i)^ < pa(b, i)^: return -1; case pa(a, i)^ > pa(b, i)^: return +1; } @@ -147,7 +147,7 @@ allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: in ptr := cast(^uint)(ptr_offset(header, 1)); n := ptr_sub(cast(^uint)data, ptr); - for i in 0..n { + for i in 0..n-1 { ptr_offset(ptr, i)^ = ~uint(0); } } diff --git a/core/opengl/opengl.odin b/core/opengl/opengl.odin index 453ab98fc..207b86bbc 100644 --- a/core/opengl/opengl.odin +++ b/core/opengl/opengl.odin @@ -46,7 +46,7 @@ _libgl := win32.load_library_a("opengl32.dll"); get_gl_proc_address :: proc(name: string) -> rawptr { if name[len(name)-1] == 0 { - name = name[..len(name)-1]; + name = name[:len(name)-1]; } // NOTE(bill): null terminated assert(mem.ptr_offset(&name[0], cast(uintptr)len(name))^ == 0); diff --git a/core/os/os.odin b/core/os/os.odin index 714f03b8c..39e21a19e 100644 --- a/core/os/os.odin +++ b/core/os/os.odin @@ -37,7 +37,7 @@ read_entire_file :: proc(name: string) -> (data: []byte, success: bool) { delete(data); return nil, false; } - return data[0..bytes_read], true; + return data[0:bytes_read], true; } write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (success: bool) { diff --git a/core/os/os_essence.odin b/core/os/os_essence.odin index d7cd62a07..d2668d70d 100644 --- a/core/os/os_essence.odin +++ b/core/os/os_essence.odin @@ -49,7 +49,7 @@ OS_Node_Information :: struct { ntype: OS_Node_Type, size: i64, - // Our additions... + // Our additions.. position: i64, } diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index b83411826..4a10232b5 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -74,7 +74,7 @@ Stat :: struct { _reserve1, _reserve2, _reserve3: i64, - serial_numbe: u64, // File serial number...? Maybe. + serial_numbe: u64, // File serial number..? Maybe. _reserve4: i64, }; diff --git a/core/os/os_osx.odin b/core/os/os_osx.odin index 9abd3f6ae..ae777db85 100644 --- a/core/os/os_osx.odin +++ b/core/os/os_osx.odin @@ -73,7 +73,7 @@ Stat :: struct { blocks: i64, // Number of blocks allocated for the file block_size: i32, // Optimal blocksize for I/O flags: u32, // User-defined flags for the file - gen_num: u32, // File generation number ...? + gen_num: u32, // File generation number ..? _spare: i32, // RESERVED _reserve1, _reserve2: i64, // RESERVED diff --git a/core/os/os_windows.odin b/core/os/os_windows.odin index 0f5fd0def..814cb2f4e 100644 --- a/core/os/os_windows.odin +++ b/core/os/os_windows.odin @@ -100,7 +100,7 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errn } buf: [300]byte; - copy(buf[..], cast([]byte)path); + copy(buf[:], cast([]byte)path); handle := Handle(win32.create_file_a(cstring(&buf[0]), access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil)); if handle != INVALID_HANDLE do return handle, ERROR_NONE; @@ -221,7 +221,7 @@ last_write_time_by_name :: proc(name: string) -> File_Time { assert(len(buf) > len(name)); - copy(buf[..], cast([]byte)name); + copy(buf[:], cast([]byte)name); if win32.get_file_attributes_ex_a(cstring(&buf[0]), win32.GetFileExInfoStandard, &data) { last_write_time = data.last_write_time; @@ -279,7 +279,7 @@ _alloc_command_line_arguments :: proc() -> []string { if n > 0 { n -= 1; } - arg_list[i] = string(buf[..n]); + arg_list[i] = string(buf[:n]); } return arg_list; diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 106318533..5b676a6c4 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -350,7 +350,7 @@ delete_key :: proc(m: ^$T/map[$K]$V, key: K) { @(builtin) -append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> int { +append :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location) -> int { if array == nil do return 0; arg_len := len(args); @@ -373,7 +373,7 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i } @(builtin) -append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller_location) -> int { +append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ..string, loc := #caller_location) -> int { for arg in args { append(array = array, args = ([]E)(arg), loc = loc); } @@ -616,9 +616,9 @@ __dynamic_map_rehash :: proc(using header: Map_Header, new_count: int, loc := #c __dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count, loc); __dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len, loc); - for i in 0..new_count do nm.hashes[i] = -1; + for i in 0..new_count-1 do nm.hashes[i] = -1; - for i in 0..m.entries.len { + for i in 0..m.entries.len-1 { if len(nm.hashes) == 0 do __dynamic_map_grow(new_header, loc); entry_header := __dynamic_map_get_entry(header, i); diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 9ef0277db..db074806c 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -17,7 +17,7 @@ __print_u64 :: proc(fd: os.Handle, u: u64) { } i -= 1; a[i] = digits[u % b]; - os.write(fd, a[i..]); + os.write(fd, a[i:]); } __print_i64 :: proc(fd: os.Handle, u: i64) { @@ -38,7 +38,7 @@ __print_i64 :: proc(fd: os.Handle, u: i64) { i -= 1; a[i] = '-'; } - os.write(fd, a[i..]); + os.write(fd, a[i:]); } __print_caller_location :: proc(fd: os.Handle, using loc: Source_Code_Location) { @@ -256,7 +256,7 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index __print_caller_location(fd, Source_Code_Location{file, line, column, ""}); os.write_string(fd, " Index "); __print_i64(fd, i64(index)); - os.write_string(fd, " is out of bounds range 0.."); + os.write_string(fd, " is out of bounds range 0:"); __print_i64(fd, i64(count)); os.write_byte(fd, '\n'); debug_trap(); @@ -270,9 +270,9 @@ slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: __print_caller_location(fd, Source_Code_Location{file, line, column, ""}); os.write_string(fd, " Invalid slice indices: "); __print_i64(fd, i64(lo)); - os.write_string(fd, ".."); + os.write_string(fd, ":"); __print_i64(fd, i64(hi)); - os.write_string(fd, ".."); + os.write_string(fd, ":"); __print_i64(fd, i64(len)); os.write_byte(fd, '\n'); debug_trap(); @@ -285,9 +285,9 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, __print_caller_location(fd, Source_Code_Location{file, line, column, ""}); os.write_string(fd, " Invalid dynamic array values: "); __print_i64(fd, i64(low)); - os.write_string(fd, ".."); + os.write_string(fd, ":"); __print_i64(fd, i64(high)); - os.write_string(fd, ".."); + os.write_string(fd, ":"); __print_i64(fd, i64(max)); os.write_byte(fd, '\n'); debug_trap(); diff --git a/core/sort/sort.odin b/core/sort/sort.odin index 4b69c8c81..f511de226 100644 --- a/core/sort/sort.odin +++ b/core/sort/sort.odin @@ -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 { + for j in init_j..last_j-1 { 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 { + for j in init_j..last_j-1 { if array[j] > array[j+1] { array[j], array[j+1] = array[j+1], array[j]; prev_swap = j; @@ -69,8 +69,8 @@ quick_sort_proc :: proc(array: $A/[]$T, f: proc(T, T) -> int) { j -= 1; } - quick_sort_proc(a[0..i], f); - quick_sort_proc(a[i..n], f); + quick_sort_proc(a[0:i], f); + quick_sort_proc(a[i:n], f); } quick_sort :: proc(array: $A/[]$T) { @@ -92,8 +92,8 @@ quick_sort :: proc(array: $A/[]$T) { j -= 1; } - quick_sort(a[0..i]); - quick_sort(a[i..n]); + quick_sort(a[0:i]); + quick_sort(a[i:n]); } _log2 :: proc(n: int) -> int { @@ -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 { + for k in 0..N1+N2-1 { if j == N2 || i < N1 && j < N2 && f(arr1[i], arr2[j]) < 0 { out[k] = arr1[i]; i += 1; @@ -126,16 +126,16 @@ 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+1 { - for j in 0..a { + for i in 0..M { + for j in 0..a-1 { k := 2*j*m; - merge_slices(arr1[k..k+m], arr1[k+m..k+m+m], arr2[k..], f); + merge_slices(arr1[k:k+m], arr1[k+m:k+m+m], arr2[k:], f); } if N-b > m { k := 2*a*m; - merge_slices(arr1[k..k+m], arr1[k+m..k+m+(N-b)&(m-1)], arr2[k..], f); + merge_slices(arr1[k:k+m], arr1[k+m : k+m+(N-b)&(m-1)], arr2[k:], f); } else { - copy(arr2[b..N], arr1[b..N]); + copy(arr2[b:N], arr1[b:N]); } arr1, arr2 = arr2, arr1; m <<= 1; @@ -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 { + for k in 0..N1+N2-1 { if j == N2 || i < N1 && j < N2 && arr1[i] < arr2[j] { out[k] = arr1[i]; i += 1; @@ -168,16 +168,16 @@ merge_sort :: proc(array: $A/[]$T) { a, b, m, M := N/2, N, 1, _log2(N); - for i in 0..M+1 { - for j in 0..a { + for i in 0..M { + for j in 0..a-1 { k := 2*j*m; - merge_slices(arr1[k..k+m], arr1[k+m..k+m+m], arr2[k..]); + merge_slices(arr1[k:k+m], arr1[k+m:k+m+m], arr2[k:]); } if N-b > m { k := 2*a*m; - merge_slices(arr1[k..k+m], arr1[k+m..k+m+(N-b)&(m-1)], arr2[k..]); + merge_slices(arr1[k:k+m], arr1[k+m : k+m+(N-b)&(m-1)], arr2[k:]); } else { - copy(arr2[b..N], arr1[b..N]); + copy(arr2[b:N], arr1[b:N]); } arr1, arr2 = arr2, arr1; m <<= 1; diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 5e9d3ff70..6e64d3e71 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -23,9 +23,9 @@ _digit_value :: proc(r: rune) -> int { ri := int(r); v: int = 16; switch r { - case '0'...'9': v = ri-'0'; - case 'a'...'z': v = ri-'a'+10; - case 'A'...'Z': v = ri-'A'+10; + case '0'..'9': v = ri-'0'; + case 'a'..'z': v = ri-'a'+10; + case 'A'..'Z': v = ri-'A'+10; } return v; } @@ -36,9 +36,9 @@ parse_i64 :: proc(s: string) -> i64 { switch s[0] { case '-': neg = true; - s = s[1..]; + s = s[1:]; case '+': - s = s[1..]; + s = s[1:]; } } @@ -46,11 +46,11 @@ parse_i64 :: proc(s: string) -> i64 { base: i64 = 10; if len(s) > 2 && s[0] == '0' { switch s[1] { - case 'b': base = 2; s = s[2..]; - case 'o': base = 8; s = s[2..]; - case 'd': base = 10; s = s[2..]; - case 'z': base = 12; s = s[2..]; - case 'x': base = 16; s = s[2..]; + case 'b': base = 2; s = s[2:]; + case 'o': base = 8; s = s[2:]; + case 'd': base = 10; s = s[2:]; + case 'z': base = 12; s = s[2:]; + case 'x': base = 16; s = s[2:]; } } @@ -76,18 +76,18 @@ parse_i64 :: proc(s: string) -> i64 { parse_u64 :: proc(s: string) -> u64 { neg := false; if len(s) > 1 && s[0] == '+' { - s = s[1..]; + s = s[1:]; } base := u64(10); if len(s) > 2 && s[0] == '0' { switch s[1] { - case 'b': base = 2; s = s[2..]; - case 'o': base = 8; s = s[2..]; - case 'd': base = 10; s = s[2..]; - case 'z': base = 12; s = s[2..]; - case 'x': base = 16; s = s[2..]; + case 'b': base = 2; s = s[2:]; + case 'o': base = 8; s = s[2:]; + case 'd': base = 10; s = s[2:]; + case 'z': base = 12; s = s[2:]; + case 'x': base = 16; s = s[2:]; } } @@ -194,7 +194,7 @@ append_bool :: proc(buf: []byte, b: bool) -> string { n := 0; if b do n = copy(buf, cast([]byte)"true"); else do n = copy(buf, cast([]byte)"false"); - return string(buf[..n]); + return string(buf[:n]); } append_uint :: proc(buf: []byte, u: u64, base: int) -> string { @@ -260,7 +260,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> [ s = "+Inf"; } n := copy(buf, cast([]byte)s); - return buf[..n]; + return buf[:n]; case 0: // denormalized exp += 1; @@ -279,7 +279,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> [ shortest := prec < 0; if shortest { round_shortest(d, mant, exp, flt); - digs = DecimalSlice{digits = d.digits[..], count = d.count, decimal_point = d.decimal_point}; + digs = DecimalSlice{digits = d.digits[:], count = d.count, decimal_point = d.decimal_point}; switch fmt { case 'e', 'E': prec = digs.count-1; case 'f', 'F': prec = max(digs.count-digs.decimal_point, 0); @@ -296,7 +296,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> [ round(d, prec); } - digs = DecimalSlice{digits = d.digits[..], count = d.count, decimal_point = d.decimal_point}; + digs = DecimalSlice{digits = d.digits[:], count = d.count, decimal_point = d.decimal_point}; } return format_digits(buf, shortest, neg, digs, prec, fmt); } @@ -309,9 +309,9 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: DecimalSlice n: int, } - to_bytes :: proc(b: Buffer) -> []byte do return b.b[..b.n]; - add_bytes :: proc(buf: ^Buffer, bytes: ...byte) { - buf.n += copy(buf.b[buf.n..], bytes); + to_bytes :: proc(b: Buffer) -> []byte do return b.b[:b.n]; + add_bytes :: proc(buf: ^Buffer, bytes: ..byte) { + buf.n += copy(buf.b[buf.n:], bytes); } b := Buffer{b = buf}; @@ -323,7 +323,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: DecimalSlice // integer, padded with zeros when needed if digs.decimal_point > 0 { m := min(digs.count, digs.decimal_point); - add_bytes(&b, ...digs.digits[0..m]); + add_bytes(&b, ..digs.digits[0:m]); for ; m < digs.decimal_point; m += 1 { add_bytes(&b, '0'); } @@ -335,7 +335,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: DecimalSlice // fractional part if prec > 0 { add_bytes(&b, '.'); - for i in 0..prec { + for i in 0..prec-1 { c: byte = '0'; if j := digs.decimal_point + i; 0 <= j && j < digs.count { c = digs.digits[j]; @@ -398,7 +398,7 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^FloatInfo) { inclusive := mant%2 == 0; - for i in 0..d.count { + for i in 0..d.count-1 { l: byte = '0'; // lower digit if i < lower.count { l = lower.digits[i]; @@ -498,8 +498,8 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i i-=1; a[i] = ' '; } - out := a[i..]; + out := a[i:]; copy(buf, out); - return string(buf[0..len(out)]); + return string(buf[0:len(out)]); } diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 89395e2bb..b3006f36f 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -6,7 +6,7 @@ new_string :: proc(s: string) -> string { c := make([]byte, len(s)+1); copy(c, cast([]byte)s); c[len(s)] = 0; - return string(c[..len(s)]); + return string(c[:len(s)]); } new_cstring :: proc(s: string) -> cstring { diff --git a/core/unicode/utf16/utf16.odin b/core/unicode/utf16/utf16.odin index b0c61e6f4..297ed7277 100644 --- a/core/unicode/utf16/utf16.odin +++ b/core/unicode/utf16/utf16.odin @@ -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, _surr3 .. _surr_self: + case 0.._surr1-1, _surr3 .. _surr_self-1: 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, _surr3 .. _surr_self: + case 0.._surr1-1, _surr3 .. _surr_self-1: if m+1 < n do break loop; d[n] = u16(r); n += 1; diff --git a/core/unicode/utf8/utf8.odin b/core/unicode/utf8/utf8.odin index c7bf56bed..cf67d4655 100644 --- a/core/unicode/utf8/utf8.odin +++ b/core/unicode/utf8/utf8.odin @@ -158,7 +158,7 @@ decode_last_rune :: proc(s: []u8) -> (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; } diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index 558ef94e4..477408e62 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -74,11 +74,9 @@ general_stuff :: proc() { } { - // .. half-closed range - // ... open range + // .. open range - for in 0..2 {} // 0, 1 - for in 0...2 {} // 0, 1, 2 + for in 0..2 {} // 0, 1, 2 } { // Multiple sized booleans @@ -267,17 +265,17 @@ union_type :: proc() { /* Entity :: struct { - ... + .. derived: union{^Frog, ^Monster}, } Frog :: struct { using entity: Entity, - ... + .. } Monster :: struct { using entity: Entity, - ... + .. } new_entity :: proc(T: type) -> ^Entity { @@ -451,7 +449,7 @@ parametric_polymorphism :: proc() { get_hash :: proc(s: string) -> u32 { // fnv32a h: u32 = 0x811c9dc5; - for i in 0..len(s) { + for i in 0..len(s)-1 { h = (h ~ u32(s[i])) * 0x01000193; } return h; @@ -500,12 +498,12 @@ threading_example :: proc() { } ordered_remove :: proc(array: ^[dynamic]$T, index: int, loc := #caller_location) { runtime.bounds_check_error_loc(loc, index, len(array)); - copy(array[index..], array[index+1..]); + copy(array[index:], array[index+1:]); pop(array); } worker_proc :: proc(t: ^thread.Thread) -> int { - for iteration in 1...5 { + for iteration in 1..5 { fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration); fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration); // win32.sleep(1); diff --git a/examples/old_demos/demo002.odin b/examples/old_demos/demo002.odin index e9b9988da..a790aadf3 100644 --- a/examples/old_demos/demo002.odin +++ b/examples/old_demos/demo002.odin @@ -95,7 +95,7 @@ enumerations :: proc() { } variadic_procedures :: proc() { - print_ints :: proc(args: ...int) { + print_ints :: proc(args: ..int) { for arg, i in args { if i > 0 do print(", "); print(arg); @@ -106,7 +106,7 @@ variadic_procedures :: proc() { print_ints(1); nl(); print_ints(1, 2, 3); nl(); - print_prefix_f32s :: proc(prefix: string, args: ...f32) { + print_prefix_f32s :: proc(prefix: string, args: ..f32) { print(prefix); print(": "); for arg, i in args { @@ -323,7 +323,7 @@ match_statement :: proc() { Vector3 :: struct {x, y, z: f32} -print_floats :: proc(args: ...f32) { +print_floats :: proc(args: ..f32) { for arg, i in args { if i > 0 do print(", "); print(arg); diff --git a/examples/old_demos/demo004.odin b/examples/old_demos/demo004.odin index be88a1aa7..c9acc9a15 100644 --- a/examples/old_demos/demo004.odin +++ b/examples/old_demos/demo004.odin @@ -32,7 +32,7 @@ main :: proc() { /* push_allocator x { - ... + .. } is equivalent to: @@ -42,7 +42,7 @@ main :: proc() { __context.allocator = x defer __context.allocator = prev_allocator - ... + .. } */ diff --git a/examples/old_demos/demo006.odin b/examples/old_demos/demo006.odin index 735e7ac50..c2f64151b 100644 --- a/examples/old_demos/demo006.odin +++ b/examples/old_demos/demo006.odin @@ -21,7 +21,7 @@ when true { Removed: * Maybe/option types * Remove `type` keyword and other "reserved" keywords - * ..< and ... removed and replace with .. (half-closed range) + * ..< and .. removed and replace with .. (half-closed range) Changed: * `#assert` and `assert` return the value of the condition for semantic reasons @@ -51,7 +51,7 @@ when true { } { - // Removal of ..< and ... + // Removal of ..< and .. for i in 0..16 { } // Is similar to diff --git a/examples/old_demos/demo007.odin b/examples/old_demos/demo007.odin index 01e1f1645..d19446ecb 100644 --- a/examples/old_demos/demo007.odin +++ b/examples/old_demos/demo007.odin @@ -69,10 +69,10 @@ general_stuff :: proc() { { // .. half-closed range - // ... open range + // .. open range for in 0..2 {} // 0, 1 - for in 0...2 {} // 0, 1, 2 + for in 0..2 {} // 0, 1, 2 } } @@ -287,17 +287,17 @@ union_type :: proc() { /* Entity :: struct { - ... + .. derived: union{^Frog, ^Monster}; } Frog :: struct { using entity: Entity; - ... + .. } Monster :: struct { using entity: Entity; - ... + .. } new_entity :: proc(T: type) -> ^Entity { @@ -522,7 +522,7 @@ threading_example :: proc() { } worker_proc :: proc(t: ^thread.Thread) -> int { - for iteration in 1...5 { + for iteration in 1..5 { fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration); fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration); // win32.sleep(1); diff --git a/examples/old_demos/demo008.odin b/examples/old_demos/demo008.odin index 466eb625e..7916cd5e9 100644 --- a/examples/old_demos/demo008.odin +++ b/examples/old_demos/demo008.odin @@ -72,10 +72,10 @@ general_stuff :: proc() { { // .. half-closed range - // ... open range + // .. open range for in 0..2 {} // 0, 1 - for in 0...2 {} // 0, 1, 2 + for in 0..2 {} // 0, 1, 2 } { // Multiple sized booleans @@ -324,17 +324,17 @@ union_type :: proc() { /* Entity :: struct { - ... + .. derived: union{^Frog, ^Monster}, } Frog :: struct { using entity: Entity, - ... + .. } Monster :: struct { using entity: Entity, - ... + .. } new_entity :: proc(T: type) -> ^Entity { @@ -559,7 +559,7 @@ threading_example :: proc() { } worker_proc :: proc(t: ^thread.Thread) -> int { - for iteration in 1...5 { + for iteration in 1..5 { fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration); fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration); // win32.sleep(1); diff --git a/examples/old_stuff/demo_backup.odin b/examples/old_stuff/demo_backup.odin index 6a7952ae1..b8bbbb02d 100644 --- a/examples/old_stuff/demo_backup.odin +++ b/examples/old_stuff/demo_backup.odin @@ -36,7 +36,7 @@ general_stuff :: proc() { // C-style variadic procedures foreign __llvm_core { // The variadic part allows for extra type checking too which C does not provide - c_printf :: proc(fmt: ^u8, #c_vararg args: ...any) -> i32 #link_name "printf" ---; + c_printf :: proc(fmt: ^u8, #c_vararg args: ..any) -> i32 #link_name "printf" ---; } str := "%d\n\x00"; // c_printf(&str[0], i32(789456123)); @@ -154,8 +154,8 @@ default_return_values :: proc() { match x { case 0: return; case 1: return "Goodbye"; - case 2: return "Goodbye", "cruel world..."; - case 3: return second = "cruel world...", first = "Goodbye"; + case 2: return "Goodbye", "cruel world.."; + case 3: return second = "cruel world..", first = "Goodbye"; } return second = "my old friend."; @@ -231,7 +231,7 @@ explicit_parametric_polymorphic_procedures :: proc() { defer free(another_ptr); - add :: proc(T: type, args: ...T) -> T { + add :: proc(T: type, args: ..T) -> T { res: T; for arg in args do res += arg; return res; diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 5596eb106..479103241 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -6110,8 +6110,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type // It is okay to continue as it will assume the 1st index is zero } - TokenKind interval_kind = se->interval.kind; - i64 indices[2] = {}; Ast *nodes[2] = {se->low, se->high}; for (isize i = 0; i < gb_count_of(nodes); i++) { @@ -6122,7 +6120,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type capacity = max_count; } i64 j = 0; - if (check_index_value(c, interval_kind == Token_Ellipsis, nodes[i], capacity, &j)) { + if (check_index_value(c, false, nodes[i], capacity, &j)) { index = j; } } else if (i == 0) { diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 453127f0c..4a98db600 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -715,8 +715,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { continue; } switch (ie->op.kind) { - case Token_Ellipsis: op = Token_GtEq; break; - case Token_HalfClosed: op = Token_Gt; break; + case Token_Ellipsis: op = Token_GtEq; break; default: error(ie->op, "Invalid interval operator"); continue; } @@ -726,8 +725,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { } switch (ie->op.kind) { - case Token_Ellipsis: op = Token_LtEq; break; - case Token_HalfClosed: op = Token_Lt; break; + case Token_Ellipsis: op = Token_LtEq; break; default: error(ie->op, "Invalid interval operator"); continue; } @@ -1362,8 +1360,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { TokenKind op = Token_Lt; switch (ie->op.kind) { - case Token_Ellipsis: op = Token_LtEq; break; - case Token_HalfClosed: op = Token_Lt; break; + case Token_Ellipsis: op = Token_LtEq; break; default: error(ie->op, "Invalid range operator"); break; } bool ok = compare_exact_values(op, a, b); diff --git a/src/check_type.cpp b/src/check_type.cpp index 77b370619..9d840b0d1 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1548,7 +1548,7 @@ i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { return 0; } if (e->kind == Ast_UnaryExpr && - e->UnaryExpr.op.kind == Token_Ellipsis) { + e->UnaryExpr.op.kind == Token_Question) { return -1; } diff --git a/src/ir.cpp b/src/ir.cpp index 5c58b1a2b..274075dfa 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -5820,10 +5820,6 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) { if (se->low != nullptr) low = ir_build_expr(proc, se->low); if (se->high != nullptr) high = ir_build_expr(proc, se->high); - if (high != nullptr && se->interval.kind == Token_Ellipsis) { - high = ir_emit_arith(proc, Token_Add, high, v_one, t_int); - } - irValue *addr = ir_build_addr_ptr(proc, se->expr); irValue *base = ir_emit_load(proc, addr); Type *type = base_type(ir_type(base)); @@ -6625,8 +6621,7 @@ void ir_build_range_interval(irProcedure *proc, AstBinaryExpr *node, Type *val_t TokenKind op = Token_Lt; switch (node->op.kind) { - case Token_Ellipsis: op = Token_LtEq; break; - case Token_HalfClosed: op = Token_Lt; break; + case Token_Ellipsis: op = Token_LtEq; break; default: GB_PANIC("Invalid interval operator"); break; } @@ -7224,8 +7219,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) { ast_node(ie, BinaryExpr, expr); TokenKind op = Token_Invalid; switch (ie->op.kind) { - case Token_Ellipsis: op = Token_LtEq; break; - case Token_HalfClosed: op = Token_Lt; break; + case Token_Ellipsis: op = Token_LtEq; break; default: GB_PANIC("Invalid interval operator"); break; } irValue *lhs = ir_build_expr(proc, ie->left); diff --git a/src/parser.cpp b/src/parser.cpp index c57fe7365..0b0c77bf0 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1142,7 +1142,7 @@ Token expect_operator(AstFile *f) { if (!gb_is_between(prev.kind, Token__OperatorBegin+1, Token__OperatorEnd-1)) { syntax_error(f->curr_token, "Expected an operator, got '%.*s'", LIT(token_strings[prev.kind])); - } else if (!f->allow_range && (prev.kind == Token_Ellipsis || prev.kind == Token_HalfClosed)) { + } else if (!f->allow_range && (prev.kind == Token_Ellipsis)) { syntax_error(f->curr_token, "Expected an non-range operator, got '%.*s'", LIT(token_strings[prev.kind])); } @@ -2041,7 +2041,7 @@ Ast *parse_call_expr(AstFile *f, Ast *operand) { Token eq = expect_token(f, Token_Eq); if (prefix_ellipsis) { - syntax_error(ellipsis, "'...' must be applied to value rather than the field name"); + syntax_error(ellipsis, "'..' must be applied to value rather than the field name"); } Ast *value = parse_value(f); @@ -2118,18 +2118,14 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { f->expr_level++; open = expect_token(f, Token_OpenBracket); - if (f->curr_token.kind != Token_Ellipsis && - f->curr_token.kind != Token_HalfClosed) { + if (f->curr_token.kind != Token_Colon) { indices[0] = parse_expr(f, false); } - if ((f->curr_token.kind == Token_Ellipsis || - f->curr_token.kind == Token_HalfClosed)) { + if (f->curr_token.kind == Token_Colon) { ellipsis = advance_token(f); is_ellipsis = true; - if (f->curr_token.kind != Token_Ellipsis && - f->curr_token.kind != Token_HalfClosed && - f->curr_token.kind != Token_CloseBracket && + if (f->curr_token.kind != Token_CloseBracket && f->curr_token.kind != Token_EOF) { indices[1] = parse_expr(f, false); } @@ -2214,7 +2210,6 @@ bool is_ast_range(Ast *expr) { TokenKind op = expr->BinaryExpr.op.kind; switch (op) { case Token_Ellipsis: - case Token_HalfClosed: return true; } return false; @@ -2226,7 +2221,6 @@ i32 token_precedence(AstFile *f, TokenKind t) { case Token_Question: return 1; case Token_Ellipsis: - case Token_HalfClosed: if (!f->allow_range) { return 0; } @@ -2690,7 +2684,7 @@ Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_type_token) { Token tok = advance_token(f); Ast *type = parse_type_or_ident(f); if (type == nullptr) { - syntax_error(tok, "variadic field missing type after '...'"); + syntax_error(tok, "variadic field missing type after '..'"); type = ast_bad_expr(f, tok, f->curr_token); } return ast_ellipsis(f, tok, type); diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index c1f4bd4f1..2ec02d9f0 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -76,8 +76,7 @@ TOKEN_KIND(Token__ComparisonEnd, ""), \ TOKEN_KIND(Token_Semicolon, ";"), \ TOKEN_KIND(Token_Period, "."), \ TOKEN_KIND(Token_Comma, ","), \ - TOKEN_KIND(Token_Ellipsis, "..."), \ - TOKEN_KIND(Token_HalfClosed, ".."), \ + TOKEN_KIND(Token_Ellipsis, ".."), \ TOKEN_KIND(Token_BackSlash, "\\"), \ TOKEN_KIND(Token__OperatorEnd, ""), \ \ @@ -226,6 +225,9 @@ void error_va(Token token, char *fmt, va_list va) { gb_bprintf_va(fmt, va)); } gb_mutex_unlock(&global_error_collector.mutex); + if (global_error_collector.count > 20) { + gb_exit(1); + } } void error_no_newline_va(Token token, char *fmt, va_list va) { @@ -241,6 +243,9 @@ void error_no_newline_va(Token token, char *fmt, va_list va) { gb_bprintf_va(fmt, va)); } gb_mutex_unlock(&global_error_collector.mutex); + if (global_error_collector.count > 20) { + gb_exit(1); + } } @@ -258,6 +263,9 @@ void syntax_error_va(Token token, char *fmt, va_list va) { } gb_mutex_unlock(&global_error_collector.mutex); + if (global_error_collector.count > 20) { + gb_exit(1); + } } void syntax_warning_va(Token token, char *fmt, va_list va) { @@ -936,11 +944,7 @@ Token tokenizer_get_token(Tokenizer *t) { case '.': if (t->curr_rune == '.') { // Could be an ellipsis advance_to_next_rune(t); - token.kind = Token_HalfClosed; - if (t->curr_rune == '.') { - advance_to_next_rune(t); - token.kind = Token_Ellipsis; - } + token.kind = Token_Ellipsis; } else if ('0' <= t->curr_rune && t->curr_rune <= '9') { token = scan_number_to_token(t, true); } else {