diff --git a/src/macros.rs b/src/macros.rs index 18c7b63398ec3a2b98584551d9501f556824b1ed..b98d2ce23daaee3c412f08e0fd5cc0cef884b1ac 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,3 +1,37 @@ +/// Print to stdout +#[macro_export] +macro_rules! print { + ($($arg:tt)*) => ({ + use core::fmt::Write; + let _ = write!($crate::platform::FileWriter(1), $($arg)*); + }); +} + +/// Print with new line to stdout +#[macro_export] +macro_rules! println { + () => (print!("\n")); + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + +/// Print to stderr +#[macro_export] +macro_rules! eprint { + ($($arg:tt)*) => ({ + use core::fmt::Write; + let _ = write!($crate::platform::FileWriter(2), $($arg)*); + }); +} + +/// Print with new line to stderr +#[macro_export] +macro_rules! eprintln { + () => (eprint!("\n")); + ($fmt:expr) => (eprint!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*)); +} + #[macro_export] macro_rules! strto_impl { ( @@ -101,13 +135,3 @@ macro_rules! strto_impl { num }}; } - -#[macro_export] -macro_rules! println { - ($($args:tt),*) => { - { - use core::fmt::Write as _Trait; - writeln!(::platform::FileWriter(1) $(, $args)*).expect("writing a debug message failed"); - } - } -}