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

View File

@@ -1,3 +1,4 @@
//+vet !using-param
package zlib
/*

View File

@@ -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
}
}
}

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
// - 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')

View File

@@ -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 = ""
}
}

View File

@@ -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)
}

View File

@@ -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
}
}

View File

@@ -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)
}

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_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")

View File

@@ -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() {

View File

@@ -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 }

View File

@@ -1474,9 +1474,9 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
Type *specialization = nullptr;
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(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");
}

View File

@@ -1,4 +1,5 @@
//+build windows, linux, darwin
//+vet !using-param
package fontstash
import "core:runtime"