Files
levlib/basic/basic.odin
2026-03-08 19:00:41 -07:00

64 lines
1.3 KiB
Odin

package basic
import "base:runtime"
import "core:prof/spall"
//----- Spall ----------------------------------
SPALL_TRACE :: #config(SPALL_TRACE, false)
spall_ctx: spall.Context
@(thread_local)
spall_buffer: spall.Buffer
//----- Compile globals ----------------------------------
ODIN_BOUNDS_CHECK :: !ODIN_NO_BOUNDS_CHECK
INT_NUM_BITS :: size_of(int) * 8
//----- Array ----------------------------------
// append unless array doesn't room, then panic
append_elem_capped :: #force_inline proc(
array: ^$T/[dynamic]$E,
arg: E,
loc := #caller_location,
) -> (
n: int,
err: runtime.Allocator_Error,
) #optional_allocator_error {
when ODIN_BOUNDS_CHECK {
if len(array) == cap(array) {
panic("Array would have to expand to accomodate append.")
} else {
return append_elem(array, arg, loc)
}
} else {
return append_elem(array, arg, loc)
}
}
append_soa_elem_capped :: proc(
array: ^$T/#soa[dynamic]$E,
arg: E,
loc := #caller_location,
) -> (
n: int,
err: runtime.Allocator_Error,
) #optional_allocator_error {
when ODIN_BOUNDS_CHECK {
if len(array) == cap(array) {
panic("Array would have to expand to accomodate append.")
} else {
return append_soa_elem(array, arg, loc)
}
} else {
return append_soa_elem(array, arg, loc)
}
}
append_capped :: proc {
append_elem_capped,
append_soa_elem_capped,
}