Try loading code at runtime
This commit is contained in:
61
src/io.rs
61
src/io.rs
@@ -1,61 +0,0 @@
|
||||
use crate::println;
|
||||
|
||||
use alloc::format;
|
||||
use alloc::string::String;
|
||||
use log::{Level, Metadata, Record};
|
||||
use log::{LevelFilter, SetLoggerError};
|
||||
|
||||
use crate::uart::write_uart;
|
||||
|
||||
fn print(content: String) {
|
||||
write_uart(content);
|
||||
}
|
||||
|
||||
struct Logger;
|
||||
|
||||
impl log::Log for Logger {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
metadata.level() <= Level::Info
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
if let Some((file, line)) = record.file().zip(record.line()) {
|
||||
println!(
|
||||
"[{}] at {}:{} - {}",
|
||||
record.level(),
|
||||
file,
|
||||
line,
|
||||
record.args()
|
||||
);
|
||||
} else {
|
||||
println!("[{}] - {}", record.level(), record.args());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
static LOGGER: Logger = Logger;
|
||||
|
||||
pub fn init_log() -> Result<(), SetLoggerError> {
|
||||
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Info))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! print {
|
||||
($($args:expr),*) => {
|
||||
$crate::io::print(format!($($args),*))
|
||||
};
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! println {
|
||||
() => {
|
||||
$crate::print!("\n\r");
|
||||
};
|
||||
($($args:expr),*) => {
|
||||
$crate::print!($($args),*);
|
||||
$crate::println!();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user