2024-05-31 08:26:52 -07:00
|
|
|
package grime
|
2024-02-08 19:33:53 -08:00
|
|
|
|
|
|
|
import "base:runtime"
|
2024-03-19 20:25:48 -07:00
|
|
|
import "core:io"
|
2024-02-08 19:33:53 -08:00
|
|
|
import "core:os"
|
2024-03-19 20:25:48 -07:00
|
|
|
import "core:text/table"
|
|
|
|
|
|
|
|
dump_stacktrace :: proc( allocator := context.temp_allocator ) -> string
|
|
|
|
{
|
|
|
|
trace_result := stacktrace()
|
|
|
|
lines, error := stacktrace_lines( trace_result )
|
|
|
|
|
|
|
|
padding := " "
|
|
|
|
|
|
|
|
log_table := table.init( & table.Table{}, context.temp_allocator, context.temp_allocator )
|
|
|
|
for line in lines {
|
|
|
|
table.row( log_table, padding, line.symbol, " - ", line.location )
|
|
|
|
}
|
|
|
|
table.build(log_table)
|
|
|
|
|
|
|
|
writer_builder : StringBuilder
|
|
|
|
str_builder_init( & writer_builder, allocator = allocator )
|
|
|
|
|
|
|
|
writer := to_writer( & writer_builder )
|
|
|
|
for row in 2 ..< log_table.nr_rows {
|
|
|
|
for col in 0 ..< log_table.nr_cols {
|
|
|
|
table.write_table_cell( writer, log_table, row, col )
|
|
|
|
}
|
|
|
|
io.write_byte( writer, '\n' )
|
|
|
|
}
|
|
|
|
|
|
|
|
return to_string( writer_builder )
|
|
|
|
}
|
2024-02-08 19:33:53 -08:00
|
|
|
|
2024-05-31 08:26:52 -07:00
|
|
|
ensure :: #force_inline proc( condition : b32, msg : string, location := #caller_location )
|
2024-02-08 19:33:53 -08:00
|
|
|
{
|
2024-02-23 06:36:23 -08:00
|
|
|
if condition {
|
2024-02-08 19:33:53 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
log( msg, LogLevel.Warning, location )
|
|
|
|
runtime.debug_trap()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(Ed) : Setup exit codes!
|
2024-05-31 08:26:52 -07:00
|
|
|
fatal :: #force_inline proc( msg : string, exit_code : int = -1, location := #caller_location )
|
2024-02-08 19:33:53 -08:00
|
|
|
{
|
|
|
|
log( msg, LogLevel.Fatal, location )
|
|
|
|
runtime.debug_trap()
|
|
|
|
os.exit( exit_code )
|
|
|
|
}
|
|
|
|
|
2024-05-31 08:26:52 -07:00
|
|
|
// TODO(Ed) : Setup exit codes!
|
|
|
|
verify :: #force_inline proc( condition : b32, msg : string, exit_code : int = -1, location := #caller_location )
|
2024-02-08 19:33:53 -08:00
|
|
|
{
|
2024-02-23 06:36:23 -08:00
|
|
|
if condition {
|
2024-02-08 19:33:53 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
log( msg, LogLevel.Fatal, location )
|
|
|
|
runtime.debug_trap()
|
|
|
|
os.exit( exit_code )
|
|
|
|
}
|