feat(libkos): add print!/println! macros via debug_putchar
This commit is contained in:
28
crates/libkos/src/io.rs
Normal file
28
crates/libkos/src/io.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use core::fmt;
|
||||
|
||||
struct Writer;
|
||||
|
||||
impl fmt::Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for &b in s.as_bytes() {
|
||||
crate::syscall::debug_putchar(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)*)));
|
||||
}
|
||||
@@ -5,6 +5,7 @@ extern crate alloc;
|
||||
mod arch;
|
||||
pub mod syscall;
|
||||
pub mod alloc_impl;
|
||||
pub mod io;
|
||||
mod rt;
|
||||
|
||||
#[cfg(target_os = "none")]
|
||||
|
||||
Reference in New Issue
Block a user