79 lines
1.6 KiB
Rust
79 lines
1.6 KiB
Rust
#![feature(lang_items, prelude_import)]
|
|
#![feature(panic_info_message)]
|
|
#![no_std]
|
|
|
|
mod entry;
|
|
pub mod env;
|
|
pub mod exit;
|
|
pub mod io;
|
|
pub mod panic;
|
|
|
|
use core::{arch::asm, fmt::Display};
|
|
|
|
#[prelude_import]
|
|
pub use prelude::rust_2021::*;
|
|
|
|
pub mod prelude;
|
|
|
|
use versioning::Version;
|
|
|
|
pub const VERSION: Version = Version::new(0, 1, 0);
|
|
|
|
// extern crate alloc;
|
|
|
|
pub fn print(s: &str) {
|
|
unsafe {
|
|
asm!(
|
|
"syscall",
|
|
in("rax") 1,
|
|
in("rdi") 1,
|
|
in("rsi") s.as_ptr(),
|
|
in("rdx") s.len(),
|
|
out("rcx") _,
|
|
out("r11") _,
|
|
);
|
|
}
|
|
}
|
|
|
|
pub fn print_char(c: char) {
|
|
let array = [c];
|
|
|
|
unsafe {
|
|
asm!(
|
|
"syscall",
|
|
in("rax") 1,
|
|
in("rdi") 1,
|
|
in("rsi") array.as_ptr(),
|
|
in("rdx") 1,
|
|
out("rcx") _,
|
|
out("r11") _,
|
|
);
|
|
}
|
|
}
|
|
#[derive(Debug)]
|
|
pub struct LocationInFile<'a> {
|
|
// TODO: replace &str with ableOS path
|
|
file_path: &'a str,
|
|
|
|
line: u16,
|
|
column: u16,
|
|
}
|
|
impl<'a> Display for Error<'a> {
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
write!(f, "{}{}{}", self.file_path, self.line, self.column)
|
|
}
|
|
}
|
|
|
|
pub struct Error<'a> {
|
|
error_id: u128,
|
|
// Optional location of the error
|
|
location: Option<LocationInFile<'a>>,
|
|
a_lil_message_as_a_treat: &'a str,
|
|
}
|
|
|
|
impl<'a> Display for Error<'a> {
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
write!(f, "EID: {}\nSRC: {}", self.error_id, self.location)
|
|
}
|
|
}
|