mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add assertf and panicf
This commit is contained in:
+3
-2
@@ -462,7 +462,6 @@ int_from_arg :: proc(args: []any, arg_index: int) -> (int, int, bool) {
|
|||||||
|
|
||||||
|
|
||||||
fmt_bad_verb :: proc(using fi: ^Fmt_Info, verb: rune) {
|
fmt_bad_verb :: proc(using fi: ^Fmt_Info, verb: rune) {
|
||||||
assert(verb != 'v');
|
|
||||||
write_string(buf, "%!");
|
write_string(buf, "%!");
|
||||||
write_rune(buf, verb);
|
write_rune(buf, verb);
|
||||||
write_byte(buf, '(');
|
write_byte(buf, '(');
|
||||||
@@ -1018,7 +1017,9 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
|||||||
|
|
||||||
m := (^mem.Raw_Map)(v.data);
|
m := (^mem.Raw_Map)(v.data);
|
||||||
if m != nil {
|
if m != nil {
|
||||||
assert(info.generated_struct != nil);
|
if info.generated_struct == nil {
|
||||||
|
return;
|
||||||
|
}
|
||||||
entries := &m.entries;
|
entries := &m.entries;
|
||||||
gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct);
|
gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct);
|
||||||
ed := runtime.type_info_base(gs.types[1]).variant.(runtime.Type_Info_Dynamic_Array);
|
ed := runtime.type_info_base(gs.types[1]).variant.(runtime.Type_Info_Dynamic_Array);
|
||||||
|
|||||||
+26
-1
@@ -5,6 +5,7 @@ package runtime
|
|||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
// Naming Conventions:
|
// Naming Conventions:
|
||||||
// In general, Ada_Case for types and snake_case for values
|
// In general, Ada_Case for types and snake_case for values
|
||||||
@@ -565,7 +566,7 @@ assert :: proc "contextless" (condition: bool, message := "", loc := #caller_loc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(builtin)
|
@(builtin)
|
||||||
panic :: proc "contextless" (message := "", loc := #caller_location) {
|
panic :: proc "contextless" (message: string, loc := #caller_location) {
|
||||||
p := context.assertion_failure_proc;
|
p := context.assertion_failure_proc;
|
||||||
if p == nil {
|
if p == nil {
|
||||||
p = default_assertion_failure_proc;
|
p = default_assertion_failure_proc;
|
||||||
@@ -574,6 +575,30 @@ panic :: proc "contextless" (message := "", loc := #caller_location) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@(builtin)
|
||||||
|
assertf :: proc "contextless" (condition: bool, format: string, args: ..any, loc := #caller_location) -> bool {
|
||||||
|
if !condition {
|
||||||
|
p := context.assertion_failure_proc;
|
||||||
|
if p == nil {
|
||||||
|
p = default_assertion_failure_proc;
|
||||||
|
}
|
||||||
|
message := fmt.tprintf(format, ..args);
|
||||||
|
p("Runtime assertion", message, loc);
|
||||||
|
}
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@(builtin)
|
||||||
|
panicf :: proc "contextless" (format: string, args: ..any, loc := #caller_location) {
|
||||||
|
p := context.assertion_failure_proc;
|
||||||
|
if p == nil {
|
||||||
|
p = default_assertion_failure_proc;
|
||||||
|
}
|
||||||
|
message := fmt.tprintf(format, ..args);
|
||||||
|
p("Panic", message, loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Dynamic Array
|
// Dynamic Array
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user