Use positional and named arguments within the core library

This commit is contained in:
gingerBill
2023-06-21 01:17:05 +01:00
parent 67ca9166d3
commit 9b54b99bf6
15 changed files with 82 additions and 82 deletions
+2 -2
View File
@@ -1118,7 +1118,7 @@ expand_macro :: proc(cpp: ^Preprocessor, rest: ^^Token, tok: ^Token) -> bool {
search_include_next :: proc(cpp: ^Preprocessor, filename: string) -> (path: string, ok: bool) { search_include_next :: proc(cpp: ^Preprocessor, filename: string) -> (path: string, ok: bool) {
for ; cpp.include_next_index < len(cpp.include_paths); cpp.include_next_index += 1 { for ; cpp.include_next_index < len(cpp.include_paths); cpp.include_next_index += 1 {
tpath := filepath.join(elems={cpp.include_paths[cpp.include_next_index], filename}, allocator=context.temp_allocator) tpath := filepath.join({cpp.include_paths[cpp.include_next_index], filename}, allocator=context.temp_allocator)
if os.exists(tpath) { if os.exists(tpath) {
return strings.clone(tpath), true return strings.clone(tpath), true
} }
@@ -1136,7 +1136,7 @@ search_include_paths :: proc(cpp: ^Preprocessor, filename: string) -> (path: str
} }
for include_path in cpp.include_paths { for include_path in cpp.include_paths {
tpath := filepath.join(elems={include_path, filename}, allocator=context.temp_allocator) tpath := filepath.join({include_path, filename}, allocator=context.temp_allocator)
if os.exists(tpath) { if os.exists(tpath) {
path, ok = strings.clone(tpath), true path, ok = strings.clone(tpath), true
cpp.filepath_cache[filename] = path cpp.filepath_cache[filename] = path
+1 -1
View File
@@ -335,7 +335,7 @@ load_from_context :: proc(z: ^$C, buf: ^bytes.Buffer, known_gzip_size := -1, exp
// fmt.printf("GZIP: Expected Payload Size: %v\n", expected_output_size); // fmt.printf("GZIP: Expected Payload Size: %v\n", expected_output_size);
zlib_error := zlib.inflate_raw(z=z, expected_output_size=expected_output_size) zlib_error := zlib.inflate_raw(z, expected_output_size=expected_output_size)
if zlib_error != nil { if zlib_error != nil {
return zlib_error return zlib_error
} }
+3 -3
View File
@@ -471,7 +471,7 @@ inflate_from_context :: proc(using ctx: ^compress.Context_Memory_Input, raw := f
} }
// Parse ZLIB stream without header. // Parse ZLIB stream without header.
inflate_raw(z=ctx, expected_output_size=expected_output_size) or_return inflate_raw(ctx, expected_output_size=expected_output_size) or_return
if !raw { if !raw {
compress.discard_to_next_byte_lsb(ctx) compress.discard_to_next_byte_lsb(ctx)
@@ -665,7 +665,7 @@ inflate_from_byte_array :: proc(input: []u8, buf: ^bytes.Buffer, raw := false, e
ctx.input_data = input ctx.input_data = input
ctx.output = buf ctx.output = buf
return inflate_from_context(ctx=&ctx, raw=raw, expected_output_size=expected_output_size) return inflate_from_context(&ctx, raw=raw, expected_output_size=expected_output_size)
} }
inflate_from_byte_array_raw :: proc(input: []u8, buf: ^bytes.Buffer, raw := false, expected_output_size := -1) -> (err: Error) { inflate_from_byte_array_raw :: proc(input: []u8, buf: ^bytes.Buffer, raw := false, expected_output_size := -1) -> (err: Error) {
@@ -674,7 +674,7 @@ inflate_from_byte_array_raw :: proc(input: []u8, buf: ^bytes.Buffer, raw := fals
ctx.input_data = input ctx.input_data = input
ctx.output = buf ctx.output = buf
return inflate_raw(z=&ctx, expected_output_size=expected_output_size) return inflate_raw(&ctx, expected_output_size=expected_output_size)
} }
inflate :: proc{inflate_from_context, inflate_from_byte_array} inflate :: proc{inflate_from_context, inflate_from_byte_array}
+9 -9
View File
@@ -123,7 +123,7 @@ register_user_formatter :: proc(id: typeid, formatter: User_Formatter) -> Regist
aprint :: proc(args: ..any, sep := " ") -> string { aprint :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str) strings.builder_init(&str)
sbprint(buf=&str, args=args, sep=sep) sbprint(&str, ..args, sep=sep)
return strings.to_string(str) return strings.to_string(str)
} }
// Creates a formatted string with a newline character at the end // Creates a formatted string with a newline character at the end
@@ -139,7 +139,7 @@ aprint :: proc(args: ..any, sep := " ") -> string {
aprintln :: proc(args: ..any, sep := " ") -> string { aprintln :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str) strings.builder_init(&str)
sbprintln(buf=&str, args=args, sep=sep) sbprintln(&str, ..args, sep=sep)
return strings.to_string(str) return strings.to_string(str)
} }
// Creates a formatted string using a format string and arguments // Creates a formatted string using a format string and arguments
@@ -171,7 +171,7 @@ aprintf :: proc(fmt: string, args: ..any) -> string {
tprint :: proc(args: ..any, sep := " ") -> string { tprint :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, context.temp_allocator) strings.builder_init(&str, context.temp_allocator)
sbprint(buf=&str, args=args, sep=sep) sbprint(&str, ..args, sep=sep)
return strings.to_string(str) return strings.to_string(str)
} }
// Creates a formatted string with a newline character at the end // Creates a formatted string with a newline character at the end
@@ -187,7 +187,7 @@ tprint :: proc(args: ..any, sep := " ") -> string {
tprintln :: proc(args: ..any, sep := " ") -> string { tprintln :: proc(args: ..any, sep := " ") -> string {
str: strings.Builder str: strings.Builder
strings.builder_init(&str, context.temp_allocator) strings.builder_init(&str, context.temp_allocator)
sbprintln(buf=&str, args=args, sep=sep) sbprintln(&str, ..args, sep=sep)
return strings.to_string(str) return strings.to_string(str)
} }
// Creates a formatted string using a format string and arguments // Creates a formatted string using a format string and arguments
@@ -217,7 +217,7 @@ tprintf :: proc(fmt: string, args: ..any) -> string {
// //
bprint :: proc(buf: []byte, args: ..any, sep := " ") -> string { bprint :: proc(buf: []byte, args: ..any, sep := " ") -> string {
sb := strings.builder_from_bytes(buf[0:len(buf)]) sb := strings.builder_from_bytes(buf[0:len(buf)])
return sbprint(buf=&sb, args=args, sep=sep) return sbprint(&sb, ..args, sep=sep)
} }
// Creates a formatted string using a supplied buffer as the backing array, appends newline. Writes into the buffer. // Creates a formatted string using a supplied buffer as the backing array, appends newline. Writes into the buffer.
// //
@@ -230,7 +230,7 @@ bprint :: proc(buf: []byte, args: ..any, sep := " ") -> string {
// //
bprintln :: proc(buf: []byte, args: ..any, sep := " ") -> string { bprintln :: proc(buf: []byte, args: ..any, sep := " ") -> string {
sb := strings.builder_from_bytes(buf[0:len(buf)]) sb := strings.builder_from_bytes(buf[0:len(buf)])
return sbprintln(buf=&sb, args=args, sep=sep) return sbprintln(&sb, ..args, sep=sep)
} }
// Creates a formatted string using a supplied buffer as the backing array. Writes into the buffer. // Creates a formatted string using a supplied buffer as the backing array. Writes into the buffer.
// //
@@ -327,7 +327,7 @@ ctprintf :: proc(format: string, args: ..any) -> cstring {
// Returns: A formatted string // Returns: A formatted string
// //
sbprint :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string { sbprint :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string {
wprint(w=strings.to_writer(buf), args=args, sep=sep) wprint(strings.to_writer(buf), ..args, sep=sep)
return strings.to_string(buf^) return strings.to_string(buf^)
} }
// Formats and writes to a strings.Builder buffer using the default print settings // Formats and writes to a strings.Builder buffer using the default print settings
@@ -340,7 +340,7 @@ sbprint :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string {
// Returns: The resulting formatted string // Returns: The resulting formatted string
// //
sbprintln :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string { sbprintln :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string {
wprintln(w=strings.to_writer(buf), args=args, sep=sep) wprintln(strings.to_writer(buf), ..args, sep=sep)
return strings.to_string(buf^) return strings.to_string(buf^)
} }
// Formats and writes to a strings.Builder buffer according to the specified format string // Formats and writes to a strings.Builder buffer according to the specified format string
@@ -353,7 +353,7 @@ sbprintln :: proc(buf: ^strings.Builder, args: ..any, sep := " ") -> string {
// Returns: The resulting formatted string // Returns: The resulting formatted string
// //
sbprintf :: proc(buf: ^strings.Builder, fmt: string, args: ..any) -> string { sbprintf :: proc(buf: ^strings.Builder, fmt: string, args: ..any) -> string {
wprintf(w=strings.to_writer(buf), fmt=fmt, args=args) wprintf(strings.to_writer(buf), fmt, ..args)
return strings.to_string(buf^) return strings.to_string(buf^)
} }
// Formats and writes to an io.Writer using the default print settings // Formats and writes to an io.Writer using the default print settings
+6 -6
View File
@@ -14,7 +14,7 @@ fprint :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
bufio.writer_init_with_buf(&b, {os.stream_from_handle(fd)}, buf[:]) bufio.writer_init_with_buf(&b, {os.stream_from_handle(fd)}, buf[:])
w := bufio.writer_to_writer(&b) w := bufio.writer_to_writer(&b)
return wprint(w=w, args=args, sep=sep) return wprint(w, ..args, sep=sep)
} }
// fprintln formats using the default print settings and writes to fd // fprintln formats using the default print settings and writes to fd
@@ -26,7 +26,7 @@ fprintln :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
bufio.writer_init_with_buf(&b, {os.stream_from_handle(fd)}, buf[:]) bufio.writer_init_with_buf(&b, {os.stream_from_handle(fd)}, buf[:])
w := bufio.writer_to_writer(&b) w := bufio.writer_to_writer(&b)
return wprintln(w=w, args=args, sep=sep) return wprintln(w, ..args, sep=sep)
} }
// fprintf formats according to the specified format string and writes to fd // fprintf formats according to the specified format string and writes to fd
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int { fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
@@ -61,15 +61,15 @@ fprint_typeid :: proc(fd: os.Handle, id: typeid) -> (n: int, err: io.Error) {
} }
// print formats using the default print settings and writes to os.stdout // print formats using the default print settings and writes to os.stdout
print :: proc(args: ..any, sep := " ") -> int { return fprint(fd=os.stdout, args=args, sep=sep) } print :: proc(args: ..any, sep := " ") -> int { return fprint(os.stdout, ..args, sep=sep) }
// println formats using the default print settings and writes to os.stdout // println formats using the default print settings and writes to os.stdout
println :: proc(args: ..any, sep := " ") -> int { return fprintln(fd=os.stdout, args=args, sep=sep) } println :: proc(args: ..any, sep := " ") -> int { return fprintln(os.stdout, ..args, sep=sep) }
// printf formats according to the specified format string and writes to os.stdout // printf formats according to the specified format string and writes to os.stdout
printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args) } printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args) }
// eprint formats using the default print settings and writes to os.stderr // eprint formats using the default print settings and writes to os.stderr
eprint :: proc(args: ..any, sep := " ") -> int { return fprint(fd=os.stderr, args=args, sep=sep) } eprint :: proc(args: ..any, sep := " ") -> int { return fprint(os.stderr, ..args, sep=sep) }
// eprintln formats using the default print settings and writes to os.stderr // eprintln formats using the default print settings and writes to os.stderr
eprintln :: proc(args: ..any, sep := " ") -> int { return fprintln(fd=os.stderr, args=args, sep=sep) } eprintln :: proc(args: ..any, sep := " ") -> int { return fprintln(os.stderr, ..args, sep=sep) }
// eprintf formats according to the specified format string and writes to os.stderr // eprintf formats according to the specified format string and writes to os.stderr
eprintf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args) } eprintf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args) }
+4 -4
View File
@@ -99,7 +99,7 @@ text :: proc(c: image.PNG_Chunk) -> (res: Text, ok: bool) {
case .tEXt: case .tEXt:
ok = true ok = true
fields := bytes.split(s=c.data, sep=[]u8{0}, allocator=context.temp_allocator) fields := bytes.split(c.data, sep=[]u8{0}, allocator=context.temp_allocator)
if len(fields) == 2 { if len(fields) == 2 {
res.keyword = strings.clone(string(fields[0])) res.keyword = strings.clone(string(fields[0]))
res.text = strings.clone(string(fields[1])) res.text = strings.clone(string(fields[1]))
@@ -110,7 +110,7 @@ text :: proc(c: image.PNG_Chunk) -> (res: Text, ok: bool) {
case .zTXt: case .zTXt:
ok = true ok = true
fields := bytes.split_n(s=c.data, sep=[]u8{0}, n=3, allocator=context.temp_allocator) fields := bytes.split_n(c.data, sep=[]u8{0}, n=3, allocator=context.temp_allocator)
if len(fields) != 3 || len(fields[1]) != 0 { if len(fields) != 3 || len(fields[1]) != 0 {
// Compression method must be 0=Deflate, which thanks to the split above turns // Compression method must be 0=Deflate, which thanks to the split above turns
// into an empty slice // into an empty slice
@@ -199,7 +199,7 @@ text_destroy :: proc(text: Text) {
iccp :: proc(c: image.PNG_Chunk) -> (res: iCCP, ok: bool) { iccp :: proc(c: image.PNG_Chunk) -> (res: iCCP, ok: bool) {
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator) runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
fields := bytes.split_n(s=c.data, sep=[]u8{0}, n=3, allocator=context.temp_allocator) fields := bytes.split_n(c.data, sep=[]u8{0}, n=3, allocator=context.temp_allocator)
if len(fields[0]) < 1 || len(fields[0]) > 79 { if len(fields[0]) < 1 || len(fields[0]) > 79 {
// Invalid profile name // Invalid profile name
@@ -263,7 +263,7 @@ splt :: proc(c: image.PNG_Chunk) -> (res: sPLT, ok: bool) {
} }
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator) runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
fields := bytes.split_n(s=c.data, sep=[]u8{0}, n=2, allocator=context.temp_allocator) fields := bytes.split_n(c.data, sep=[]u8{0}, n=2, allocator=context.temp_allocator)
if len(fields) != 2 { if len(fields) != 2 {
return return
} }
+13 -13
View File
@@ -76,43 +76,43 @@ nil_logger :: proc() -> Logger {
} }
debugf :: proc(fmt_str: string, args: ..any, location := #caller_location) { debugf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Debug, fmt_str=fmt_str, args=args, location=location) logf(.Debug, fmt_str, ..args, location=location)
} }
infof :: proc(fmt_str: string, args: ..any, location := #caller_location) { infof :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Info, fmt_str=fmt_str, args=args, location=location) logf(.Info, fmt_str, ..args, location=location)
} }
warnf :: proc(fmt_str: string, args: ..any, location := #caller_location) { warnf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Warning, fmt_str=fmt_str, args=args, location=location) logf(.Warning, fmt_str, ..args, location=location)
} }
errorf :: proc(fmt_str: string, args: ..any, location := #caller_location) { errorf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Error, fmt_str=fmt_str, args=args, location=location) logf(.Error, fmt_str, ..args, location=location)
} }
fatalf :: proc(fmt_str: string, args: ..any, location := #caller_location) { fatalf :: proc(fmt_str: string, args: ..any, location := #caller_location) {
logf(level=.Fatal, fmt_str=fmt_str, args=args, location=location) logf(.Fatal, fmt_str, ..args, location=location)
} }
debug :: proc(args: ..any, sep := " ", location := #caller_location) { debug :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Debug, args=args, sep=sep, location=location) log(.Debug, ..args, sep=sep, location=location)
} }
info :: proc(args: ..any, sep := " ", location := #caller_location) { info :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Info, args=args, sep=sep, location=location) log(.Info, ..args, sep=sep, location=location)
} }
warn :: proc(args: ..any, sep := " ", location := #caller_location) { warn :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Warning, args=args, sep=sep, location=location) log(.Warning, ..args, sep=sep, location=location)
} }
error :: proc(args: ..any, sep := " ", location := #caller_location) { error :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Error, args=args, sep=sep, location=location) log(.Error, ..args, sep=sep, location=location)
} }
fatal :: proc(args: ..any, sep := " ", location := #caller_location) { fatal :: proc(args: ..any, sep := " ", location := #caller_location) {
log(level=.Fatal, args=args, sep=sep, location=location) log(.Fatal, ..args, sep=sep, location=location)
} }
panic :: proc(args: ..any, location := #caller_location) -> ! { panic :: proc(args: ..any, location := #caller_location) -> ! {
log(level=.Fatal, args=args, location=location) log(.Fatal, ..args, location=location)
runtime.panic("log.panic", location) runtime.panic("log.panic", location)
} }
panicf :: proc(fmt_str: string, args: ..any, location := #caller_location) -> ! { panicf :: proc(fmt_str: string, args: ..any, location := #caller_location) -> ! {
logf(level=.Fatal, fmt_str=fmt_str, args=args, location=location) logf(.Fatal, fmt_str, ..args, location=location)
runtime.panic("log.panicf", location) runtime.panic("log.panicf", location)
} }
@@ -127,7 +127,7 @@ log :: proc(level: Level, args: ..any, sep := " ", location := #caller_location)
if level < logger.lowest_level { if level < logger.lowest_level {
return return
} }
str := fmt.tprint(args=args, sep=sep) //NOTE(Hoej): While tprint isn't thread-safe, no logging is. str := fmt.tprint(..args, sep=sep) //NOTE(Hoej): While tprint isn't thread-safe, no logging is.
logger.procedure(logger.data, level, str, logger.options, location) logger.procedure(logger.data, level, str, logger.options, location)
} }
+27 -27
View File
@@ -38,60 +38,60 @@ log_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
switch mode { switch mode {
case .Alloc: case .Alloc:
logf( logf(
level=la.level, la.level,
fmt_str = "%s%s>>> ALLOCATOR(mode=.Alloc, size=%d, alignment=%d)", "%s%s>>> ALLOCATOR(mode=.Alloc, size=%d, alignment=%d)",
args = {la.prefix, padding, size, alignment}, la.prefix, padding, size, alignment,
location = location, location = location,
) )
case .Alloc_Non_Zeroed: case .Alloc_Non_Zeroed:
logf( logf(
level=la.level, la.level,
fmt_str = "%s%s>>> ALLOCATOR(mode=.Alloc_Non_Zeroed, size=%d, alignment=%d)", "%s%s>>> ALLOCATOR(mode=.Alloc_Non_Zeroed, size=%d, alignment=%d)",
args = {la.prefix, padding, size, alignment}, la.prefix, padding, size, alignment,
location = location, location = location,
) )
case .Free: case .Free:
if old_size != 0 { if old_size != 0 {
logf( logf(
level=la.level, la.level,
fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)", "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)",
args = {la.prefix, padding, old_memory, old_size}, la.prefix, padding, old_memory, old_size,
location = location, location = location,
) )
} else { } else {
logf( logf(
level=la.level, la.level,
fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p)", "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p)",
args = {la.prefix, padding, old_memory}, la.prefix, padding, old_memory,
location = location, location = location,
) )
} }
case .Free_All: case .Free_All:
logf( logf(
level=la.level, la.level,
fmt_str = "%s%s<<< ALLOCATOR(mode=.Free_All)", "%s%s<<< ALLOCATOR(mode=.Free_All)",
args = {la.prefix, padding}, la.prefix, padding,
location = location, location = location,
) )
case .Resize: case .Resize:
logf( logf(
level=la.level, la.level,
fmt_str = "%s%s>>> ALLOCATOR(mode=.Resize, ptr=%p, old_size=%d, size=%d, alignment=%d)", "%s%s>>> ALLOCATOR(mode=.Resize, ptr=%p, old_size=%d, size=%d, alignment=%d)",
args = {la.prefix, padding, old_memory, old_size, size, alignment}, la.prefix, padding, old_memory, old_size, size, alignment,
location = location, location = location,
) )
case .Query_Features: case .Query_Features:
logf( logf(
level=la.level, la.level,
fmt_str = "%s%ALLOCATOR(mode=.Query_Features)", "%s%ALLOCATOR(mode=.Query_Features)",
args = {la.prefix, padding}, la.prefix, padding,
location = location, location = location,
) )
case .Query_Info: case .Query_Info:
logf( logf(
level=la.level, la.level,
fmt_str = "%s%ALLOCATOR(mode=.Query_Info)", "%s%ALLOCATOR(mode=.Query_Info)",
args = {la.prefix, padding}, la.prefix, padding,
location = location, location = location,
) )
} }
@@ -103,9 +103,9 @@ log_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
defer la.locked = false defer la.locked = false
if err != nil { if err != nil {
logf( logf(
level=la.level, la.level,
fmt_str = "%s%ALLOCATOR ERROR=%v", "%s%ALLOCATOR ERROR=%v",
args = {la.prefix, padding, error}, la.prefix, padding, error,
location = location, location = location,
) )
} }
+1 -1
View File
@@ -429,7 +429,7 @@ internal_int_write_to_ascii_file :: proc(a: ^Int, filename: string, radix := i8(
len = l, len = l,
} }
ok := os.write_entire_file(name=filename, data=data, truncate=true) ok := os.write_entire_file(filename, data, truncate=true)
return nil if ok else .Cannot_Write_File return nil if ok else .Cannot_Write_File
} }
+1 -1
View File
@@ -120,7 +120,7 @@ arena_alloc :: proc(arena: ^Arena, size: uint, alignment: uint, loc := #caller_l
if arena.minimum_block_size == 0 { if arena.minimum_block_size == 0 {
arena.minimum_block_size = DEFAULT_ARENA_STATIC_RESERVE_SIZE arena.minimum_block_size = DEFAULT_ARENA_STATIC_RESERVE_SIZE
} }
arena_init_static(arena=arena, reserved=arena.minimum_block_size, commit_size=DEFAULT_ARENA_STATIC_COMMIT_SIZE) or_return arena_init_static(arena, reserved=arena.minimum_block_size, commit_size=DEFAULT_ARENA_STATIC_COMMIT_SIZE) or_return
} }
fallthrough fallthrough
case .Buffer: case .Buffer:
+6 -6
View File
@@ -112,7 +112,7 @@ remove_range :: proc(array: ^$D/[dynamic]$T, lo, hi: int, loc := #caller_locatio
// Note: If the dynamic array as no elements (`len(array) == 0`), this procedure will panic. // Note: If the dynamic array as no elements (`len(array) == 0`), this procedure will panic.
@builtin @builtin
pop :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: E) #no_bounds_check { pop :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: E) #no_bounds_check {
assert(len(array) > 0, "", loc) assert(len(array) > 0, loc=loc)
res = array[len(array)-1] res = array[len(array)-1]
(^Raw_Dynamic_Array)(array).len -= 1 (^Raw_Dynamic_Array)(array).len -= 1
return res return res
@@ -136,7 +136,7 @@ pop_safe :: proc(array: ^$T/[dynamic]$E) -> (res: E, ok: bool) #no_bounds_check
// Note: If the dynamic array as no elements (`len(array) == 0`), this procedure will panic. // Note: If the dynamic array as no elements (`len(array) == 0`), this procedure will panic.
@builtin @builtin
pop_front :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: E) #no_bounds_check { pop_front :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: E) #no_bounds_check {
assert(len(array) > 0, "", loc) assert(len(array) > 0, loc=loc)
res = array[0] res = array[0]
if len(array) > 1 { if len(array) > 1 {
copy(array[0:], array[1:]) copy(array[0:], array[1:])
@@ -424,7 +424,7 @@ append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) ->
a := (^Raw_Dynamic_Array)(array) a := (^Raw_Dynamic_Array)(array)
when size_of(E) != 0 { when size_of(E) != 0 {
data := ([^]E)(a.data) data := ([^]E)(a.data)
assert(condition=data != nil, loc=loc) assert(data != nil, loc=loc)
data[a.len] = arg data[a.len] = arg
} }
a.len += 1 a.len += 1
@@ -459,7 +459,7 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
a := (^Raw_Dynamic_Array)(array) a := (^Raw_Dynamic_Array)(array)
when size_of(E) != 0 { when size_of(E) != 0 {
data := ([^]E)(a.data) data := ([^]E)(a.data)
assert(condition=data != nil, loc=loc) assert(data != nil, loc=loc)
intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len) intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len)
} }
a.len += arg_len a.len += arg_len
@@ -472,7 +472,7 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
@builtin @builtin
append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $A/string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error { append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $A/string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
args := transmute([]E)arg args := transmute([]E)arg
return append_elems(array=array, args=args, loc=loc) return append_elems(array, ..args, loc=loc)
} }
@@ -481,7 +481,7 @@ append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $A/string, loc := #ca
append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ..string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error { append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ..string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_allocator_error {
n_arg: int n_arg: int
for arg in args { for arg in args {
n_arg, err = append(array = array, args = transmute([]E)(arg), loc = loc) n_arg, err = append(array, ..transmute([]E)(arg), loc=loc)
n += n_arg n += n_arg
if err != nil { if err != nil {
return return
+1 -1
View File
@@ -191,7 +191,7 @@ run_internal_test :: proc(t: ^T, it: Internal_Test) {
global_exception_handler = win32.AddVectoredExceptionHandler(0, exception_handler_proc) global_exception_handler = win32.AddVectoredExceptionHandler(0, exception_handler_proc)
context.assertion_failure_proc = proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! { context.assertion_failure_proc = proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! {
errorf(t=global_current_t, format="%s %s", args={prefix, message}, loc=loc) errorf(global_current_t, "%s %s", prefix, message, loc=loc)
intrinsics.trap() intrinsics.trap()
} }
+5 -5
View File
@@ -46,15 +46,15 @@ errorf :: proc(t: ^T, format: string, args: ..any, loc := #caller_location) {
} }
fail :: proc(t: ^T, loc := #caller_location) { fail :: proc(t: ^T, loc := #caller_location) {
error(t=t, args={"FAIL"}, loc=loc) error(t, "FAIL", loc=loc)
t.error_count += 1 t.error_count += 1
} }
fail_now :: proc(t: ^T, msg := "", loc := #caller_location) { fail_now :: proc(t: ^T, msg := "", loc := #caller_location) {
if msg != "" { if msg != "" {
error(t=t, args={"FAIL:", msg}, loc=loc) error(t, "FAIL:", msg, loc=loc)
} else { } else {
error(t=t, args={"FAIL"}, loc=loc) error(t, "FAIL", loc=loc)
} }
t.error_count += 1 t.error_count += 1
if t._fail_now != nil { if t._fail_now != nil {
@@ -84,14 +84,14 @@ cleanup :: proc(t: ^T, procedure: proc(rawptr), user_data: rawptr) {
expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bool { expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bool {
if !ok { if !ok {
error(t=t, args={msg}, loc=loc) error(t, msg, loc=loc)
} }
return ok return ok
} }
expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) { expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) {
ok := value == expected ok := value == expected
if !ok { if !ok {
errorf(t=t, format="expected %v, got %v", args={expected, value}, loc=loc) errorf(t, "expected %v, got %v", expected, value, loc=loc)
} }
return ok return ok
} }
+1 -1
View File
@@ -114,7 +114,7 @@ set_cell_alignment :: proc(tbl: ^Table, row, col: int, alignment: Cell_Alignment
format :: proc(tbl: ^Table, _fmt: string, args: ..any, loc := #caller_location) -> string { format :: proc(tbl: ^Table, _fmt: string, args: ..any, loc := #caller_location) -> string {
context.allocator = tbl.format_allocator context.allocator = tbl.format_allocator
return fmt.aprintf(fmt = _fmt, args = args) return fmt.aprintf(_fmt, ..args)
} }
header :: proc(tbl: ^Table, values: ..any, loc := #caller_location) { header :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
+2 -2
View File
@@ -1175,13 +1175,13 @@ threading_example :: proc() {
N :: 3 N :: 3
pool: thread.Pool pool: thread.Pool
thread.pool_init(pool=&pool, allocator=context.allocator, thread_count=N) thread.pool_init(&pool, allocator=context.allocator, thread_count=N)
defer thread.pool_destroy(&pool) defer thread.pool_destroy(&pool)
for i in 0..<30 { for i in 0..<30 {
// be mindful of the allocator used for tasks. The allocator needs to be thread safe, or be owned by the task for exclusive use // be mindful of the allocator used for tasks. The allocator needs to be thread safe, or be owned by the task for exclusive use
thread.pool_add_task(pool=&pool, allocator=context.allocator, procedure=task_proc, data=nil, user_index=i) thread.pool_add_task(&pool, allocator=context.allocator, procedure=task_proc, data=nil, user_index=i)
} }
thread.pool_start(&pool) thread.pool_start(&pool)