extern "C" {
#[doc(hidden)]
pub fn vprintf(format: *const u8, valist: *const core::ffi::c_void) -> i32;
#[doc(hidden)]
pub fn __assertfail(
message: *const u8,
file: *const u8,
line: u32,
function: *const u8,
char_size: usize,
);
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => {
let msg = ::alloc::format!($($arg)*);
let cstring = ::alloc::format!("{}\0", msg);
unsafe {
$crate::io::vprintf(cstring.as_ptr(), ::core::ptr::null_mut());
}
}
}
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($fmt:expr) => ($crate::print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => ($crate::print!(concat!($fmt, "\n"), $($arg)*));
}
#[macro_export]
macro_rules! assert_eq {
($a:expr, $b:expr) => {
let _a = $a;
let _b = $b;
if _a != _b {
let msg = ::alloc::format!(
"\nassertion failed: ({} == {})\nleft : {:?}\nright: {:?}",
stringify!($a),
stringify!($b),
_a,
_b
);
unsafe {
$crate::io::__assertfail(msg.as_ptr(), file!().as_ptr(), line!(), "".as_ptr(), 1)
};
}
};
}
#[macro_export]
macro_rules! assert_ne {
($a:expr, $b:expr) => {
let _a = $a;
let _b = $b;
if _a == _b {
let msg = ::alloc::format!(
"\nassertion failed: ({} != {})\nleft : {:?}\nright: {:?}",
stringify!($a),
stringify!($b),
_a,
_b
);
unsafe {
$crate::io::__assertfail(msg.as_ptr(), file!().as_ptr(), line!(), "".as_ptr(), 1)
};
}
};
}