use core::fmt; struct Writer; impl fmt::Write for Writer { fn write_str(&mut self, s: &str) -> fmt::Result { // The log server first; a process without either prints nothing. // A call, not a send: the text is out before the caller goes on. if let Some(log) = crate::start::log() { for chunk in s.as_bytes().chunks(types::log::TEXT_BYTES) { let _ = crate::syscall::call(log, types::log::text_words(chunk), None); } } else if let Some(console) = crate::start::console() { for &b in s.as_bytes() { crate::syscall::debug_putchar(console, b); } } Ok(()) } } pub fn _print(args: fmt::Arguments) { use fmt::Write; Writer.write_fmt(args).ok(); } #[macro_export] macro_rules! print { ($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*))); } #[macro_export] macro_rules! println { () => ($crate::print!("\n")); ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*))); }