1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use core::fmt::{Write, Error, self};
use crate::syscall;
struct StdIO {}
impl StdIO {
pub fn new() -> Self {
StdIO {}
}
}
impl Write for StdIO {
fn write_str(&mut self, out: &str) -> Result<(), Error> {
syscall::write(1, out.as_bytes());
Ok(())
}
}
#[doc(hidden)]
pub fn _print(args: fmt::Arguments) {
StdIO::new().write_fmt(args).unwrap();
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::print::_print(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ({
$crate::print::_print(format_args_nl!($($arg)*));
})
}
#[macro_export]
macro_rules! format {
($($arg:tt)*) => (core::fmt::format(format_args_nl!($($arg)*)))
}