aaaaaa macro magic!

This commit is contained in:
elfein 2021-11-11 01:09:14 -08:00
parent de7c831233
commit 01c0c118dd

View file

@ -1,5 +1,7 @@
#[macro_use]
#[repr(usize)]
pub enum SysCall {
declum! {
SysCall,
KILL = 0, // Provide a PID
CONSOLE_RESET = 1, // Reset the console
CONSOLE_IN = 2, // Console Input
@ -32,37 +34,24 @@ pub enum SysCall {
FILE_WRITE = 31,
// Security Syscalls
ENCRYPT = 50,
EMPTY = u32::MAX as usize,
ENCRYPT = 50;
EMPTY = u32::MAX as usize
}
impl From<usize> for SysCall {
macro_rules! declum {
($nym:ident, $($variant:ident = $value:expr),*; $catch_all:ident = $max:expr) => {
pub enum $nym {
$($variant = $value),*
$catch_all = $max
}
impl From<usize> for $nym {
fn from(n: usize) -> Self {
match n {
0x0 => Self::KILL,
0x1 => Self::CONSOLE_RESET,
0x2 => Self::CONSOLE_IN,
0x3 => Self::CONSOLE_OUT,
0x4 => Self::CONSOLE_GET_TITLE,
0x5 => Self::CONSOLE_SET_TITLE,
0xA => Self::GET_PRIORITY,
0xB => Self::SET_PRIORITY,
0xC => Self::GET_HOSTNAME,
0xD => Self::SET_HOSTNAME,
0x14 => Self::GET_CONFIG,
0x15 => Self::SET_CONFIG,
0x16 => Self::MAKE_DIRECTORY,
0x17 => Self::DELETE_DIRECTORY,
0x18 => Self::RENAME_DIRECTORY,
0x19 => Self::SET_DIRECTORY_ACCESS,
0x1A => Self::MAKE_FILE,
0x1B => Self::DELETE_FILE,
0x1C => Self::RENAME_FILE,
0x1D => Self::SET_FILE_ACCESS,
0x1E => Self::FILE_READ,
0x1F => Self::FILE_WRITE,
0x32 => Self::ENCRYPT,
_ => Self::EMPTY,
$($value => Self::$variant),*
_ => Self::$catch_all
}
}
}
};
}