logger : Logger = .{ default_logger, null };
- assert_handler : (msg: str, file: str) -> void;
+ assert_handler : (msg: str, site: CallSite) -> void;
}
#if runtime.Runtime != runtime.Runtime_Custom {
// first parameter to ALL procedures in a compilation unit.
context : OnyxContext;
-assert :: (cond: bool, msg: str, file: str = null_str) {
- if !cond do context.assert_handler(msg, file);
+assert :: (cond: bool, msg: str, site := #callsite) {
+ if !cond do context.assert_handler(msg, site);
}
}
+
+// This structure represents the result of a '#callsite' expression. Currently,
+// #callsite is only valid (and parsed) as a default value for a procedure parameter.
+// It allows the function to get the address of the calling site, which can be
+// used for error printing, unique hashes, and much more.
CallSite :: struct {
file : str;
line : u32;
// The default assert handler. This assumes that __output_string
// and __exit are defined in the 'runtime' package.
-__assert_handler :: (msg: str, file: str) {
+__assert_handler :: (msg: str, site: CallSite) {
__output_string("Assert failed: ");
__output_string(msg);
- if file.data != null {
+ if site.file.data != null {
__output_string(" in ");
- __output_string(file);
+ __output_string(site.file);
}
__output_string("\n");