bobcat_panic/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[cfg(feature = "alloc")]
4extern crate alloc;
5
6#[cfg(all(target_arch = "wasm32", feature = "console"))]
7mod wasm {
8    #[link(wasm_import_module = "vm_hooks")]
9    unsafe extern "C" {
10        pub(crate) fn log_txt(ptr: *const u8, len: usize);
11    }
12}
13
14#[macro_export]
15#[cfg(all(target_arch = "wasm32", feature = "console"))]
16macro_rules! console_dbg {
17    ($val:expr) => {
18    {
19        let tmp = $val;
20        let msg = alloc::format!("[{}:{}] {} = {:#?}\n", file!(), line!(), stringify!($val), &tmp);
21        unsafe { $crate::host::log_txt(msg.as_ptr(), msg.len()) };
22        tmp
23    }};
24    ($($vals:expr),+ $(,)?) => {
25    {
26        let tup = ($($vals),+);
27        let msg = alloc::format!("[{}:{}] {} = {:#?}\n", file!(), line!(), stringify!(($($vals),+)), &tup);
28        unsafe { $crate::host::log_txt(msg.as_ptr(), msg.len()) };
29        tup
30    }};
31}
32
33#[macro_export]
34#[cfg(all(not(target_arch = "wasm32"), feature = "std"))]
35macro_rules! harness_dbg {
36    ($val:expr) => { dbg!($val) };
37    ($($vals:expr),+ $(,)?) => { dbg!($($vals),+) };
38}
39
40#[macro_export]
41#[cfg(any(
42    all(not(target_arch = "wasm32"), not(feature = "std")),
43    all(target_arch = "wasm32", not(feature = "console"))
44))]
45macro_rules! harness_dbg {
46    ($val:expr) => { dbg!($val) };
47    ($($vals:expr),+ $(,)?) => { dbg!($($vals),+) };
48}
49
50#[cfg(all(not(feature = "std"), target_arch = "wasm32"))]
51#[panic_handler]
52pub fn panic_handler(_msg: &core::panic::PanicInfo) -> ! {
53    #[cfg(feature = "console")]
54    {
55        let msg = alloc::format!("{_msg}");
56        unsafe { wasm::log_txt(msg.as_ptr(), msg.len()) }
57    }
58    core::arch::wasm32::unreachable()
59}