macros.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /// Variable argument version of `syscall`
  2. #[macro_export]
  3. macro_rules! syscall {
  4. ($nr:ident) => {
  5. $crate::syscall($crate::nr::$nr, 0usize)
  6. };
  7. ($nr:ident, $a1:expr) => {
  8. $crate::syscall($crate::nr::$nr, $a1 as usize)
  9. };
  10. ($nr:ident, $a1:expr, $a2:expr) => {
  11. $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize])
  12. };
  13. ($nr:ident, $a1:expr, $a2:expr, $a3:expr) => {
  14. $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize,
  15. $a3 as usize])
  16. };
  17. ($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
  18. $crate::syscall($crate::nr::$nr, &[$a1 as usize, $a2 as usize,
  19. $a3 as usize, $a4 as usize])
  20. };
  21. }
  22. /// Macro for printing to the **host's** standard stderr
  23. #[macro_export]
  24. macro_rules! ehprint {
  25. ($s:expr) => ($crate::io::ewrite_str($s));
  26. ($($arg:tt)*) => ($crate::io::ewrite_fmt(format_args!($($arg)*)));
  27. }
  28. /// Macro for printing to the **host's** standard error, with a newline.
  29. #[macro_export]
  30. macro_rules! ehprintln {
  31. () => (ehprint!("\n"));
  32. ($fmt:expr) => (ehprint!(concat!($fmt, "\n")));
  33. ($fmt:expr, $($arg:tt)*) => (ehprint!(concat!($fmt, "\n"), $($arg)*));
  34. }
  35. /// Macro for printing to the **host's** standard output
  36. #[macro_export]
  37. macro_rules! hprint {
  38. ($s:expr) => ($crate::io::write_str($s));
  39. ($($arg:tt)*) => ($crate::io::write_fmt(format_args!($($arg)*)));
  40. }
  41. /// Macro for printing to the **host's** standard output, with a newline.
  42. #[macro_export]
  43. macro_rules! hprintln {
  44. () => (hprint!("\n"));
  45. ($fmt:expr) => (hprint!(concat!($fmt, "\n")));
  46. ($fmt:expr, $($arg:tt)*) => (hprint!(concat!($fmt, "\n"), $($arg)*));
  47. }