Clean up usage of using throughout core and vendor

This commit is contained in:
gingerBill
2023-07-31 11:46:40 +01:00
parent 0de7df9eab
commit 44ea82f845
12 changed files with 143 additions and 138 deletions
+1
View File
@@ -1,3 +1,4 @@
//+vet !using-param
package zlib package zlib
/* /*
+16 -16
View File
@@ -125,38 +125,38 @@ error :: proc(t: ^Tokenizer, offset: int, msg: string, args: ..any) {
} }
@(optimization_mode="speed") @(optimization_mode="speed")
advance_rune :: proc(using t: ^Tokenizer) { advance_rune :: proc(t: ^Tokenizer) {
#no_bounds_check { #no_bounds_check {
/* /*
Already bounds-checked here. Already bounds-checked here.
*/ */
if read_offset < len(src) { if t.read_offset < len(t.src) {
offset = read_offset t.offset = t.read_offset
if ch == '\n' { if t.ch == '\n' {
line_offset = offset t.line_offset = t.offset
line_count += 1 t.line_count += 1
} }
r, w := rune(src[read_offset]), 1 r, w := rune(t.src[t.read_offset]), 1
switch { switch {
case r == 0: case r == 0:
error(t, t.offset, "illegal character NUL") error(t, t.offset, "illegal character NUL")
case r >= utf8.RUNE_SELF: 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 { if r == utf8.RUNE_ERROR && w == 1 {
error(t, t.offset, "illegal UTF-8 encoding") 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") error(t, t.offset, "illegal byte order mark")
} }
} }
read_offset += w t.read_offset += w
ch = r t.ch = r
} else { } else {
offset = len(src) t.offset = len(t.src)
if ch == '\n' { if t.ch == '\n' {
line_offset = offset t.line_offset = t.offset
line_count += 1 t.line_count += 1
} }
ch = -1 t.ch = -1
} }
} }
} }
+11 -11
View File
@@ -835,22 +835,22 @@ int_from_arg :: proc(args: []any, arg_index: int) -> (int, int, bool) {
// - fi: A pointer to an Info structure // - fi: A pointer to an Info structure
// - verb: The invalid format verb // - 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 prev_in_bad := fi.in_bad
defer fi.in_bad = prev_in_bad defer fi.in_bad = prev_in_bad
fi.in_bad = true fi.in_bad = true
io.write_string(writer, "%!", &fi.n) io.write_string(fi.writer, "%!", &fi.n)
io.write_rune(writer, verb, &fi.n) io.write_rune(fi.writer, verb, &fi.n)
io.write_byte(writer, '(', &fi.n) io.write_byte(fi.writer, '(', &fi.n)
if arg.id != nil { if fi.arg.id != nil {
reflect.write_typeid(writer, arg.id, &fi.n) reflect.write_typeid(fi.writer, fi.arg.id, &fi.n)
io.write_byte(writer, '=', &fi.n) io.write_byte(fi.writer, '=', &fi.n)
fmt_value(fi, arg, 'v') fmt_value(fi, fi.arg, 'v')
} else { } 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 // 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 // - b: The boolean value to format
// - verb: The format verb // - 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 { switch verb {
case 't', 'v': case 't', 'v':
fmt_string(fi, b ? "true" : "false", 's') fmt_string(fi, b ? "true" : "false", 's')
+8 -7
View File
@@ -4,13 +4,14 @@ import "core:bytes"
import "core:image" import "core:image"
destroy :: proc(img: ^image.Image) -> bool { destroy :: proc(img: ^image.Image) -> bool {
if img == nil do return false if img == nil {
return false
}
defer free(img) defer free(img)
bytes.buffer_destroy(&img.pixels) bytes.buffer_destroy(&img.pixels)
info, ok := img.metadata.(^image.Netpbm_Info) info := img.metadata.(^image.Netpbm_Info) or_return
if !ok do return false
header_destroy(&info.header) header_destroy(&info.header)
free(info) free(info)
@@ -19,9 +20,9 @@ destroy :: proc(img: ^image.Image) -> bool {
return true return true
} }
header_destroy :: proc(using header: ^Header) { header_destroy :: proc(header: ^Header) {
if format == .P7 && tupltype != "" { if header.format == .P7 && header.tupltype != "" {
delete(tupltype) delete(header.tupltype)
tupltype = "" header.tupltype = ""
} }
} }
+52 -52
View File
@@ -111,11 +111,11 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory {
return tmp return tmp
} }
end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) { end_arena_temp_memory :: proc(tmp: Arena_Temp_Memory) {
assert(arena.offset >= prev_offset) assert(tmp.arena.offset >= tmp.prev_offset)
assert(arena.temp_count > 0) assert(tmp.arena.temp_count > 0)
arena.offset = prev_offset tmp.arena.offset = tmp.prev_offset
arena.temp_count -= 1 tmp.arena.temp_count -= 1
} }
@@ -702,11 +702,11 @@ dynamic_pool_init :: proc(pool: ^Dynamic_Pool,
pool. used_blocks.allocator = array_allocator 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) dynamic_pool_free_all(pool)
delete(unused_blocks) delete(pool.unused_blocks)
delete(used_blocks) delete(pool.used_blocks)
delete(out_band_allocations) delete(pool.out_band_allocations)
zero(pool, size_of(pool^)) zero(pool, size_of(pool^))
} }
@@ -719,90 +719,90 @@ dynamic_pool_alloc :: proc(pool: ^Dynamic_Pool, bytes: int) -> (rawptr, Allocato
} }
@(require_results) @(require_results)
dynamic_pool_alloc_bytes :: proc(using pool: ^Dynamic_Pool, bytes: int) -> ([]byte, Allocator_Error) { dynamic_pool_alloc_bytes :: proc(p: ^Dynamic_Pool, bytes: int) -> ([]byte, Allocator_Error) {
cycle_new_block :: proc(using pool: ^Dynamic_Pool) -> (err: Allocator_Error) { cycle_new_block :: proc(p: ^Dynamic_Pool) -> (err: Allocator_Error) {
if block_allocator.procedure == nil { if p.block_allocator.procedure == nil {
panic("You must call pool_init on a Pool before using it") panic("You must call pool_init on a Pool before using it")
} }
if current_block != nil { if p.current_block != nil {
append(&used_blocks, current_block) append(&p.used_blocks, p.current_block)
} }
new_block: rawptr new_block: rawptr
if len(unused_blocks) > 0 { if len(p.unused_blocks) > 0 {
new_block = pop(&unused_blocks) new_block = pop(&p.unused_blocks)
} else { } else {
data: []byte data: []byte
data, err = block_allocator.procedure(block_allocator.data, Allocator_Mode.Alloc, data, err = p.block_allocator.procedure(p.block_allocator.data, Allocator_Mode.Alloc,
block_size, alignment, p.block_size, p.alignment,
nil, 0) nil, 0)
new_block = raw_data(data) new_block = raw_data(data)
} }
bytes_left = block_size p.bytes_left = p.block_size
current_pos = new_block p.current_pos = new_block
current_block = new_block p.current_block = new_block
return return
} }
n := bytes n := bytes
extra := alignment - (n % alignment) extra := p.alignment - (n % p.alignment)
n += extra n += extra
if n >= out_band_size { if n >= p.out_band_size {
assert(block_allocator.procedure != nil) assert(p.block_allocator.procedure != nil)
memory, err := block_allocator.procedure(block_allocator.data, Allocator_Mode.Alloc, memory, err := p.block_allocator.procedure(p.block_allocator.data, Allocator_Mode.Alloc,
block_size, alignment, p.block_size, p.alignment,
nil, 0) nil, 0)
if memory != nil { if memory != nil {
append(&out_band_allocations, raw_data(memory)) append(&p.out_band_allocations, raw_data(memory))
} }
return memory, err return memory, err
} }
if bytes_left < n { if p.bytes_left < n {
err := cycle_new_block(pool) err := cycle_new_block(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if current_block == nil { if p.current_block == nil {
return nil, .Out_Of_Memory return nil, .Out_Of_Memory
} }
} }
memory := current_pos memory := p.current_pos
current_pos = ptr_offset((^byte)(current_pos), n) p.current_pos = ([^]byte)(p.current_pos)[n:]
bytes_left -= n p.bytes_left -= n
return byte_slice(memory, bytes), nil return ([^]byte)(memory)[:bytes], nil
} }
dynamic_pool_reset :: proc(using pool: ^Dynamic_Pool) { dynamic_pool_reset :: proc(p: ^Dynamic_Pool) {
if current_block != nil { if p.current_block != nil {
append(&unused_blocks, current_block) append(&p.unused_blocks, p.current_block)
current_block = nil p.current_block = nil
} }
for block in used_blocks { for block in p.used_blocks {
append(&unused_blocks, block) append(&p.unused_blocks, block)
} }
clear(&used_blocks) clear(&p.used_blocks)
for a in out_band_allocations { for a in p.out_band_allocations {
free(a, block_allocator) 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_free_all :: proc(p: ^Dynamic_Pool) {
dynamic_pool_reset(pool) dynamic_pool_reset(p)
for block in unused_blocks { for block in p.unused_blocks {
free(block, block_allocator) free(block, p.block_allocator)
} }
clear(&unused_blocks) clear(&p.unused_blocks)
} }
+16 -16
View File
@@ -75,34 +75,34 @@ error :: proc(t: ^Tokenizer, offset: int, msg: string, args: ..any) {
t.error_count += 1 t.error_count += 1
} }
advance_rune :: proc(using t: ^Tokenizer) { advance_rune :: proc(t: ^Tokenizer) {
if read_offset < len(src) { if t.read_offset < len(t.src) {
offset = read_offset t.offset = t.read_offset
if ch == '\n' { if t.ch == '\n' {
line_offset = offset t.line_offset = t.offset
line_count += 1 t.line_count += 1
} }
r, w := rune(src[read_offset]), 1 r, w := rune(t.src[t.read_offset]), 1
switch { switch {
case r == 0: case r == 0:
error(t, t.offset, "illegal character NUL") error(t, t.offset, "illegal character NUL")
case r >= utf8.RUNE_SELF: 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 { if r == utf8.RUNE_ERROR && w == 1 {
error(t, t.offset, "illegal UTF-8 encoding") 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") error(t, t.offset, "illegal byte order mark")
} }
} }
read_offset += w t.read_offset += w
ch = r t.ch = r
} else { } else {
offset = len(src) t.offset = len(t.src)
if ch == '\n' { if t.ch == '\n' {
line_offset = offset t.line_offset = t.offset
line_count += 1 t.line_count += 1
} }
ch = -1 t.ch = -1
} }
} }
+9 -9
View File
@@ -235,7 +235,7 @@ make_slice_error_loc :: #force_inline proc "contextless" (loc := #caller_locatio
handle_error(loc, len) 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 { if 0 <= len && len <= cap {
return 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_loc :: #force_inline proc "contextless" (loc := #caller_location, index, count: int) {
bounds_check_error(file_path, line, column, index, count) 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_loc :: #force_inline proc "contextless" (loc := #caller_location, hi: int, len: int) {
slice_expr_error_hi(file_path, line, column, hi, len) 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_loc :: #force_inline proc "contextless" (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.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_loc :: #force_inline proc "contextless" (loc := #caller_location, low, high, max: int) {
dynamic_array_expr_error(file_path, line, column, low, high, max) dynamic_array_expr_error(loc.file_path, loc.line, loc.column, low, high, max)
} }
+6 -6
View File
@@ -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_uintptr :: proc "contextless" (x: uintptr) { print_u64(u64(x)) }
print_int :: proc "contextless" (x: int) { print_i64(i64(x)) } print_int :: proc "contextless" (x: int) { print_i64(i64(x)) }
print_caller_location :: proc "contextless" (using loc: Source_Code_Location) { print_caller_location :: proc "contextless" (loc: Source_Code_Location) {
print_string(file_path) print_string(loc.file_path)
when ODIN_ERROR_POS_STYLE == .Default { when ODIN_ERROR_POS_STYLE == .Default {
print_byte('(') print_byte('(')
print_u64(u64(line)) print_u64(u64(loc.line))
print_byte(':') print_byte(':')
print_u64(u64(column)) print_u64(u64(loc.column))
print_byte(')') print_byte(')')
} else when ODIN_ERROR_POS_STYLE == .Unix { } else when ODIN_ERROR_POS_STYLE == .Unix {
print_byte(':') print_byte(':')
print_u64(u64(line)) print_u64(u64(loc.line))
print_byte(':') print_byte(':')
print_u64(u64(column)) print_u64(u64(loc.column))
print_byte(':') print_byte(':')
} else { } else {
#panic("unhandled ODIN_ERROR_POS_STYLE") #panic("unhandled ODIN_ERROR_POS_STYLE")
+2 -2
View File
@@ -129,8 +129,8 @@ _destroy :: proc(thread: ^Thread) {
free(thread, thread.creation_allocator) free(thread, thread.creation_allocator)
} }
_terminate :: proc(using thread : ^Thread, exit_code: int) { _terminate :: proc(thread: ^Thread, exit_code: int) {
win32.TerminateThread(win32_thread, u32(exit_code)) win32.TerminateThread(thread.win32_thread, u32(exit_code))
} }
_yield :: proc() { _yield :: proc() {
+19 -17
View File
@@ -59,28 +59,30 @@ sleep :: proc "contextless" (d: Duration) {
_sleep(d) _sleep(d)
} }
stopwatch_start :: proc "contextless" (using stopwatch: ^Stopwatch) { stopwatch_start :: proc "contextless" (stopwatch: ^Stopwatch) {
if !running { if !stopwatch.running {
_start_time = tick_now() stopwatch._start_time = tick_now()
running = true stopwatch.running = true
} }
} }
stopwatch_stop :: proc "contextless" (using stopwatch: ^Stopwatch) { stopwatch_stop :: proc "contextless" (stopwatch: ^Stopwatch) {
if running { if stopwatch.running {
_accumulation += tick_diff(_start_time, tick_now()) stopwatch._accumulation += tick_diff(stopwatch._start_time, tick_now())
running = false stopwatch.running = false
} }
} }
stopwatch_reset :: proc "contextless" (using stopwatch: ^Stopwatch) { stopwatch_reset :: proc "contextless" (stopwatch: ^Stopwatch) {
_accumulation = {} stopwatch._accumulation = {}
running = false stopwatch.running = false
} }
stopwatch_duration :: proc "contextless" (using stopwatch: Stopwatch) -> Duration { stopwatch_duration :: proc "contextless" (stopwatch: Stopwatch) -> Duration {
if !running { return _accumulation } if !stopwatch.running {
return _accumulation + tick_diff(_start_time, tick_now()) return stopwatch._accumulation
}
return stopwatch._accumulation + tick_diff(stopwatch._start_time, tick_now())
} }
diff :: proc "contextless" (start, end: Time) -> Duration { 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) { weekday :: proc "contextless" (t: Time) -> (weekday: Weekday) {
abs := _time_abs(t) abs := _time_abs(t)
sec := (abs + u64(Weekday.Monday) * SECONDS_PER_DAY) % SECONDS_PER_WEEK sec := (abs + u64(Weekday.Monday) * SECONDS_PER_DAY) % SECONDS_PER_WEEK
return Weekday(int(sec) / SECONDS_PER_DAY) return Weekday(int(sec) / SECONDS_PER_DAY)
} }
clock :: proc { clock_from_time, clock_from_duration, clock_from_stopwatch } clock :: proc { clock_from_time, clock_from_duration, clock_from_stopwatch }
+2 -2
View File
@@ -1474,9 +1474,9 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
Type *specialization = nullptr; Type *specialization = nullptr;
bool is_using = (p->flags&FieldFlag_using) != 0; bool is_using = (p->flags&FieldFlag_using) != 0;
if ((build_context.vet_flags & VetFlag_UsingParam) && is_using) { if ((check_vet_flags(param) & VetFlag_UsingParam) && is_using) {
ERROR_BLOCK(); ERROR_BLOCK();
error(param, "'using' on a procedure parameter is now allowed when '-vet' or '-vet-using-stmt' is applied"); error(param, "'using' on a procedure parameter is now allowed when '-vet' or '-vet-using-param' is applied");
error_line("\t'using' is considered bad practice to use as a statement/procedure parameter outside of immediate refactoring\n"); error_line("\t'using' is considered bad practice to use as a statement/procedure parameter outside of immediate refactoring\n");
} }
+1
View File
@@ -1,4 +1,5 @@
//+build windows, linux, darwin //+build windows, linux, darwin
//+vet !using-param
package fontstash package fontstash
import "core:runtime" import "core:runtime"