diff options
| author | gingerBill <bill@gingerbill.org> | 2023-07-31 11:46:40 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-07-31 11:46:40 +0100 |
| commit | 44ea82f8452876c4890884506111e243b8b2a541 (patch) | |
| tree | 60125606c148c6c2fa44d921936cdb7157a6046a /core | |
| parent | 0de7df9eab9b256e0d1c8da7c9fc8c422c5ac1a7 (diff) | |
Clean up usage of `using` throughout core and vendor
Diffstat (limited to 'core')
| -rw-r--r-- | core/compress/zlib/zlib.odin | 1 | ||||
| -rw-r--r-- | core/encoding/xml/tokenizer.odin | 32 | ||||
| -rw-r--r-- | core/fmt/fmt.odin | 22 | ||||
| -rw-r--r-- | core/image/netpbm/helpers.odin | 15 | ||||
| -rw-r--r-- | core/mem/allocators.odin | 104 | ||||
| -rw-r--r-- | core/odin/tokenizer/tokenizer.odin | 32 | ||||
| -rw-r--r-- | core/runtime/error_checks.odin | 18 | ||||
| -rw-r--r-- | core/runtime/print.odin | 12 | ||||
| -rw-r--r-- | core/thread/thread_windows.odin | 4 | ||||
| -rw-r--r-- | core/time/time.odin | 36 |
10 files changed, 140 insertions, 136 deletions
diff --git a/core/compress/zlib/zlib.odin b/core/compress/zlib/zlib.odin index 21172e8e8..8062c8d3a 100644 --- a/core/compress/zlib/zlib.odin +++ b/core/compress/zlib/zlib.odin @@ -1,3 +1,4 @@ +//+vet !using-param package zlib /* diff --git a/core/encoding/xml/tokenizer.odin b/core/encoding/xml/tokenizer.odin index d225c5d90..cd055475c 100644 --- a/core/encoding/xml/tokenizer.odin +++ b/core/encoding/xml/tokenizer.odin @@ -125,38 +125,38 @@ error :: proc(t: ^Tokenizer, offset: int, msg: string, args: ..any) { } @(optimization_mode="speed") -advance_rune :: proc(using t: ^Tokenizer) { +advance_rune :: proc(t: ^Tokenizer) { #no_bounds_check { /* Already bounds-checked here. */ - if read_offset < len(src) { - offset = read_offset - if ch == '\n' { - line_offset = offset - line_count += 1 + if t.read_offset < len(t.src) { + t.offset = t.read_offset + if t.ch == '\n' { + t.line_offset = t.offset + t.line_count += 1 } - r, w := rune(src[read_offset]), 1 + r, w := rune(t.src[t.read_offset]), 1 switch { case r == 0: error(t, t.offset, "illegal character NUL") case r >= utf8.RUNE_SELF: - r, w = #force_inline utf8.decode_rune_in_string(src[read_offset:]) + r, w = #force_inline utf8.decode_rune_in_string(t.src[t.read_offset:]) if r == utf8.RUNE_ERROR && w == 1 { error(t, t.offset, "illegal UTF-8 encoding") - } else if r == utf8.RUNE_BOM && offset > 0 { + } else if r == utf8.RUNE_BOM && t.offset > 0 { error(t, t.offset, "illegal byte order mark") } } - read_offset += w - ch = r + t.read_offset += w + t.ch = r } else { - offset = len(src) - if ch == '\n' { - line_offset = offset - line_count += 1 + t.offset = len(t.src) + if t.ch == '\n' { + t.line_offset = t.offset + t.line_count += 1 } - ch = -1 + t.ch = -1 } } } diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index f1f94b1b3..e64b621bf 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -835,22 +835,22 @@ int_from_arg :: proc(args: []any, arg_index: int) -> (int, int, bool) { // - fi: A pointer to an Info structure // - verb: The invalid format verb // -fmt_bad_verb :: proc(using fi: ^Info, verb: rune) { +fmt_bad_verb :: proc(fi: ^Info, verb: rune) { prev_in_bad := fi.in_bad defer fi.in_bad = prev_in_bad fi.in_bad = true - io.write_string(writer, "%!", &fi.n) - io.write_rune(writer, verb, &fi.n) - io.write_byte(writer, '(', &fi.n) - if arg.id != nil { - reflect.write_typeid(writer, arg.id, &fi.n) - io.write_byte(writer, '=', &fi.n) - fmt_value(fi, arg, 'v') + io.write_string(fi.writer, "%!", &fi.n) + io.write_rune(fi.writer, verb, &fi.n) + io.write_byte(fi.writer, '(', &fi.n) + if fi.arg.id != nil { + reflect.write_typeid(fi.writer, fi.arg.id, &fi.n) + io.write_byte(fi.writer, '=', &fi.n) + fmt_value(fi, fi.arg, 'v') } else { - io.write_string(writer, "<nil>", &fi.n) + io.write_string(fi.writer, "<nil>", &fi.n) } - io.write_byte(writer, ')', &fi.n) + io.write_byte(fi.writer, ')', &fi.n) } // Formats a boolean value according to the specified format verb // @@ -859,7 +859,7 @@ fmt_bad_verb :: proc(using fi: ^Info, verb: rune) { // - b: The boolean value to format // - verb: The format verb // -fmt_bool :: proc(using fi: ^Info, b: bool, verb: rune) { +fmt_bool :: proc(fi: ^Info, b: bool, verb: rune) { switch verb { case 't', 'v': fmt_string(fi, b ? "true" : "false", 's') diff --git a/core/image/netpbm/helpers.odin b/core/image/netpbm/helpers.odin index 016f9453e..5307d764b 100644 --- a/core/image/netpbm/helpers.odin +++ b/core/image/netpbm/helpers.odin @@ -4,13 +4,14 @@ import "core:bytes" import "core:image" destroy :: proc(img: ^image.Image) -> bool { - if img == nil do return false + if img == nil { + return false + } defer free(img) bytes.buffer_destroy(&img.pixels) - info, ok := img.metadata.(^image.Netpbm_Info) - if !ok do return false + info := img.metadata.(^image.Netpbm_Info) or_return header_destroy(&info.header) free(info) @@ -19,9 +20,9 @@ destroy :: proc(img: ^image.Image) -> bool { return true } -header_destroy :: proc(using header: ^Header) { - if format == .P7 && tupltype != "" { - delete(tupltype) - tupltype = "" +header_destroy :: proc(header: ^Header) { + if header.format == .P7 && header.tupltype != "" { + delete(header.tupltype) + header.tupltype = "" } } diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index 7767740c9..77cdfb3cf 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -111,11 +111,11 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory { return tmp } -end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) { - assert(arena.offset >= prev_offset) - assert(arena.temp_count > 0) - arena.offset = prev_offset - arena.temp_count -= 1 +end_arena_temp_memory :: proc(tmp: Arena_Temp_Memory) { + assert(tmp.arena.offset >= tmp.prev_offset) + assert(tmp.arena.temp_count > 0) + tmp.arena.offset = tmp.prev_offset + tmp.arena.temp_count -= 1 } @@ -702,11 +702,11 @@ dynamic_pool_init :: proc(pool: ^Dynamic_Pool, pool. used_blocks.allocator = array_allocator } -dynamic_pool_destroy :: proc(using pool: ^Dynamic_Pool) { +dynamic_pool_destroy :: proc(pool: ^Dynamic_Pool) { dynamic_pool_free_all(pool) - delete(unused_blocks) - delete(used_blocks) - delete(out_band_allocations) + delete(pool.unused_blocks) + delete(pool.used_blocks) + delete(pool.out_band_allocations) zero(pool, size_of(pool^)) } @@ -719,90 +719,90 @@ dynamic_pool_alloc :: proc(pool: ^Dynamic_Pool, bytes: int) -> (rawptr, Allocato } @(require_results) -dynamic_pool_alloc_bytes :: proc(using pool: ^Dynamic_Pool, bytes: int) -> ([]byte, Allocator_Error) { - cycle_new_block :: proc(using pool: ^Dynamic_Pool) -> (err: Allocator_Error) { - if block_allocator.procedure == nil { +dynamic_pool_alloc_bytes :: proc(p: ^Dynamic_Pool, bytes: int) -> ([]byte, Allocator_Error) { + cycle_new_block :: proc(p: ^Dynamic_Pool) -> (err: Allocator_Error) { + if p.block_allocator.procedure == nil { panic("You must call pool_init on a Pool before using it") } - if current_block != nil { - append(&used_blocks, current_block) + if p.current_block != nil { + append(&p.used_blocks, p.current_block) } new_block: rawptr - if len(unused_blocks) > 0 { - new_block = pop(&unused_blocks) + if len(p.unused_blocks) > 0 { + new_block = pop(&p.unused_blocks) } else { data: []byte - data, err = block_allocator.procedure(block_allocator.data, Allocator_Mode.Alloc, - block_size, alignment, - nil, 0) + data, err = p.block_allocator.procedure(p.block_allocator.data, Allocator_Mode.Alloc, + p.block_size, p.alignment, + nil, 0) new_block = raw_data(data) } - bytes_left = block_size - current_pos = new_block - current_block = new_block + p.bytes_left = p.block_size + p.current_pos = new_block + p.current_block = new_block return } n := bytes - extra := alignment - (n % alignment) + extra := p.alignment - (n % p.alignment) n += extra - if n >= out_band_size { - assert(block_allocator.procedure != nil) - memory, err := block_allocator.procedure(block_allocator.data, Allocator_Mode.Alloc, - block_size, alignment, - nil, 0) + if n >= p.out_band_size { + assert(p.block_allocator.procedure != nil) + memory, err := p.block_allocator.procedure(p.block_allocator.data, Allocator_Mode.Alloc, + p.block_size, p.alignment, + nil, 0) if memory != nil { - append(&out_band_allocations, raw_data(memory)) + append(&p.out_band_allocations, raw_data(memory)) } return memory, err } - if bytes_left < n { - err := cycle_new_block(pool) + if p.bytes_left < n { + err := cycle_new_block(p) if err != nil { return nil, err } - if current_block == nil { + if p.current_block == nil { return nil, .Out_Of_Memory } } - memory := current_pos - current_pos = ptr_offset((^byte)(current_pos), n) - bytes_left -= n - return byte_slice(memory, bytes), nil + memory := p.current_pos + p.current_pos = ([^]byte)(p.current_pos)[n:] + p.bytes_left -= n + return ([^]byte)(memory)[:bytes], nil } -dynamic_pool_reset :: proc(using pool: ^Dynamic_Pool) { - if current_block != nil { - append(&unused_blocks, current_block) - current_block = nil +dynamic_pool_reset :: proc(p: ^Dynamic_Pool) { + if p.current_block != nil { + append(&p.unused_blocks, p.current_block) + p.current_block = nil } - for block in used_blocks { - append(&unused_blocks, block) + for block in p.used_blocks { + append(&p.unused_blocks, block) } - clear(&used_blocks) + clear(&p.used_blocks) - for a in out_band_allocations { - free(a, block_allocator) + for a in p.out_band_allocations { + free(a, p.block_allocator) } - clear(&out_band_allocations) + clear(&p.out_band_allocations) - bytes_left = 0 // Make new allocations call `cycle_new_block` again. + p.bytes_left = 0 // Make new allocations call `cycle_new_block` again. } -dynamic_pool_free_all :: proc(using pool: ^Dynamic_Pool) { - dynamic_pool_reset(pool) +dynamic_pool_free_all :: proc(p: ^Dynamic_Pool) { + dynamic_pool_reset(p) - for block in unused_blocks { - free(block, block_allocator) + for block in p.unused_blocks { + free(block, p.block_allocator) } - clear(&unused_blocks) + clear(&p.unused_blocks) } diff --git a/core/odin/tokenizer/tokenizer.odin b/core/odin/tokenizer/tokenizer.odin index c06d05e1d..0ec57356e 100644 --- a/core/odin/tokenizer/tokenizer.odin +++ b/core/odin/tokenizer/tokenizer.odin @@ -75,34 +75,34 @@ error :: proc(t: ^Tokenizer, offset: int, msg: string, args: ..any) { t.error_count += 1 } -advance_rune :: proc(using t: ^Tokenizer) { - if read_offset < len(src) { - offset = read_offset - if ch == '\n' { - line_offset = offset - line_count += 1 +advance_rune :: proc(t: ^Tokenizer) { + if t.read_offset < len(t.src) { + t.offset = t.read_offset + if t.ch == '\n' { + t.line_offset = t.offset + t.line_count += 1 } - r, w := rune(src[read_offset]), 1 + r, w := rune(t.src[t.read_offset]), 1 switch { case r == 0: error(t, t.offset, "illegal character NUL") case r >= utf8.RUNE_SELF: - r, w = utf8.decode_rune_in_string(src[read_offset:]) + r, w = utf8.decode_rune_in_string(t.src[t.read_offset:]) if r == utf8.RUNE_ERROR && w == 1 { error(t, t.offset, "illegal UTF-8 encoding") - } else if r == utf8.RUNE_BOM && offset > 0 { + } else if r == utf8.RUNE_BOM && t.offset > 0 { error(t, t.offset, "illegal byte order mark") } } - read_offset += w - ch = r + t.read_offset += w + t.ch = r } else { - offset = len(src) - if ch == '\n' { - line_offset = offset - line_count += 1 + t.offset = len(t.src) + if t.ch == '\n' { + t.line_offset = t.offset + t.line_count += 1 } - ch = -1 + t.ch = -1 } } diff --git a/core/runtime/error_checks.odin b/core/runtime/error_checks.odin index c189642af..9d484979a 100644 --- a/core/runtime/error_checks.odin +++ b/core/runtime/error_checks.odin @@ -235,7 +235,7 @@ make_slice_error_loc :: #force_inline proc "contextless" (loc := #caller_locatio handle_error(loc, len) } -make_dynamic_array_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, len, cap: int) { +make_dynamic_array_error_loc :: #force_inline proc "contextless" (loc := #caller_location, len, cap: int) { if 0 <= len && len <= cap { return } @@ -271,18 +271,18 @@ make_map_expr_error_loc :: #force_inline proc "contextless" (loc := #caller_loca -bounds_check_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, index, count: int) { - bounds_check_error(file_path, line, column, index, count) +bounds_check_error_loc :: #force_inline proc "contextless" (loc := #caller_location, index, count: int) { + bounds_check_error(loc.file_path, loc.line, loc.column, index, count) } -slice_expr_error_hi_loc :: #force_inline proc "contextless" (using loc := #caller_location, hi: int, len: int) { - slice_expr_error_hi(file_path, line, column, hi, len) +slice_expr_error_hi_loc :: #force_inline proc "contextless" (loc := #caller_location, hi: int, len: int) { + slice_expr_error_hi(loc.file_path, loc.line, loc.column, hi, len) } -slice_expr_error_lo_hi_loc :: #force_inline proc "contextless" (using loc := #caller_location, lo, hi: int, len: int) { - slice_expr_error_lo_hi(file_path, line, column, lo, hi, len) +slice_expr_error_lo_hi_loc :: #force_inline proc "contextless" (loc := #caller_location, lo, hi: int, len: int) { + slice_expr_error_lo_hi(loc.file_path, loc.line, loc.column, lo, hi, len) } -dynamic_array_expr_error_loc :: #force_inline proc "contextless" (using loc := #caller_location, low, high, max: int) { - dynamic_array_expr_error(file_path, line, column, low, high, max) +dynamic_array_expr_error_loc :: #force_inline proc "contextless" (loc := #caller_location, low, high, max: int) { + dynamic_array_expr_error(loc.file_path, loc.line, loc.column, low, high, max) } diff --git a/core/runtime/print.odin b/core/runtime/print.odin index 732ed9c12..20788b66f 100644 --- a/core/runtime/print.odin +++ b/core/runtime/print.odin @@ -215,19 +215,19 @@ print_uint :: proc "contextless" (x: uint) { print_u64(u64(x)) } print_uintptr :: proc "contextless" (x: uintptr) { print_u64(u64(x)) } print_int :: proc "contextless" (x: int) { print_i64(i64(x)) } -print_caller_location :: proc "contextless" (using loc: Source_Code_Location) { - print_string(file_path) +print_caller_location :: proc "contextless" (loc: Source_Code_Location) { + print_string(loc.file_path) when ODIN_ERROR_POS_STYLE == .Default { print_byte('(') - print_u64(u64(line)) + print_u64(u64(loc.line)) print_byte(':') - print_u64(u64(column)) + print_u64(u64(loc.column)) print_byte(')') } else when ODIN_ERROR_POS_STYLE == .Unix { print_byte(':') - print_u64(u64(line)) + print_u64(u64(loc.line)) print_byte(':') - print_u64(u64(column)) + print_u64(u64(loc.column)) print_byte(':') } else { #panic("unhandled ODIN_ERROR_POS_STYLE") diff --git a/core/thread/thread_windows.odin b/core/thread/thread_windows.odin index 0d004c8c3..2d6cad1ad 100644 --- a/core/thread/thread_windows.odin +++ b/core/thread/thread_windows.odin @@ -129,8 +129,8 @@ _destroy :: proc(thread: ^Thread) { free(thread, thread.creation_allocator) } -_terminate :: proc(using thread : ^Thread, exit_code: int) { - win32.TerminateThread(win32_thread, u32(exit_code)) +_terminate :: proc(thread: ^Thread, exit_code: int) { + win32.TerminateThread(thread.win32_thread, u32(exit_code)) } _yield :: proc() { diff --git a/core/time/time.odin b/core/time/time.odin index 6c424a62e..90d051a31 100644 --- a/core/time/time.odin +++ b/core/time/time.odin @@ -59,28 +59,30 @@ sleep :: proc "contextless" (d: Duration) { _sleep(d) } -stopwatch_start :: proc "contextless" (using stopwatch: ^Stopwatch) { - if !running { - _start_time = tick_now() - running = true +stopwatch_start :: proc "contextless" (stopwatch: ^Stopwatch) { + if !stopwatch.running { + stopwatch._start_time = tick_now() + stopwatch.running = true } } -stopwatch_stop :: proc "contextless" (using stopwatch: ^Stopwatch) { - if running { - _accumulation += tick_diff(_start_time, tick_now()) - running = false +stopwatch_stop :: proc "contextless" (stopwatch: ^Stopwatch) { + if stopwatch.running { + stopwatch._accumulation += tick_diff(stopwatch._start_time, tick_now()) + stopwatch.running = false } } -stopwatch_reset :: proc "contextless" (using stopwatch: ^Stopwatch) { - _accumulation = {} - running = false +stopwatch_reset :: proc "contextless" (stopwatch: ^Stopwatch) { + stopwatch._accumulation = {} + stopwatch.running = false } -stopwatch_duration :: proc "contextless" (using stopwatch: Stopwatch) -> Duration { - if !running { return _accumulation } - return _accumulation + tick_diff(_start_time, tick_now()) +stopwatch_duration :: proc "contextless" (stopwatch: Stopwatch) -> Duration { + if !stopwatch.running { + return stopwatch._accumulation + } + return stopwatch._accumulation + tick_diff(stopwatch._start_time, tick_now()) } diff :: proc "contextless" (start, end: Time) -> Duration { @@ -171,9 +173,9 @@ day :: proc "contextless" (t: Time) -> (day: int) { } weekday :: proc "contextless" (t: Time) -> (weekday: Weekday) { - abs := _time_abs(t) - sec := (abs + u64(Weekday.Monday) * SECONDS_PER_DAY) % SECONDS_PER_WEEK - return Weekday(int(sec) / SECONDS_PER_DAY) + abs := _time_abs(t) + sec := (abs + u64(Weekday.Monday) * SECONDS_PER_DAY) % SECONDS_PER_WEEK + return Weekday(int(sec) / SECONDS_PER_DAY) } clock :: proc { clock_from_time, clock_from_duration, clock_from_stopwatch } |