println 实现

ch2
zhangxinyu 2 years ago
parent fc02e9f961
commit 34f0dde511

@ -1,4 +1,5 @@
use core::fmt::{Arguments, Write, Result};
use crate::syscall::sys_write;
struct Stdout;
@ -6,7 +7,7 @@ const STDOUT: usize = 1;
impl Write for Stdout {
fn write_str(&mut self, s: &str) -> Result {
// ... todo 实现系统调用
sys_write(STDOUT, s.as_bytes());
Ok(())
}
}

@ -1,16 +1,17 @@
use core::panic::PanicInfo;
use crate::println;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
if let Some(location) = info.location() {
// println!(
// "Panicked at {}:{} {}",
// location.file(),
// location.line(),
// info.message().unwrap()
// );
println!(
"Panicked at {}:{} {}",
location.file(),
location.line(),
info.message().unwrap()
);
} else {
// println!("Panicked: {}", info.message().unwrap());
println!("Panicked: {}", info.message().unwrap());
}
loop {

Loading…
Cancel
Save