dbg.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #[allow(unused_macros)]
  2. macro_rules! dbg_log {
  3. ($fmt:expr) => {
  4. println!($fmt);
  5. };
  6. ($fmt:expr, $($arg:tt)*) => {
  7. println!($fmt, $($arg)*);
  8. }
  9. }
  10. #[allow(unused_macros)]
  11. macro_rules! dbg_assert {
  12. ($($arg:tt)*) => {
  13. debug_assert!($($arg)*);
  14. };
  15. }
  16. #[cfg(target_arch = "wasm32")]
  17. #[allow(unused_macros)]
  18. macro_rules! dbg_log {
  19. ($fmt:expr) => {
  20. {
  21. use ::util::{ DEBUG, _log_to_js_console };
  22. if DEBUG { _log_to_js_console($fmt); }
  23. }
  24. };
  25. ($fmt:expr, $($arg:tt)*) => {
  26. {
  27. use ::util::{ DEBUG, _log_to_js_console };
  28. if DEBUG { _log_to_js_console(format!($fmt, $($arg)*)); }
  29. }
  30. };
  31. }
  32. #[cfg(target_arch = "wasm32")]
  33. #[allow(unused_macros)]
  34. macro_rules! dbg_assert {
  35. ($cond:expr) => {{
  36. use util::{_log_to_js_console, abort, DEBUG};
  37. if DEBUG && !$cond {
  38. _log_to_js_console(format!(
  39. "Assertion failed at {}:{}:{}: '{}'",
  40. file!(),
  41. line!(),
  42. column!(),
  43. stringify!($cond),
  44. ));
  45. unsafe {
  46. abort();
  47. }
  48. }
  49. }};
  50. ($cond:expr, $desc:expr) => {{
  51. use util::{_log_to_js_console, abort, DEBUG};
  52. if DEBUG && !$cond {
  53. _log_to_js_console(format!(
  54. "Assertion failed at {}:{}:{}: '{}' - '{}'",
  55. file!(),
  56. line!(),
  57. column!(),
  58. stringify!($cond),
  59. $desc,
  60. ));
  61. unsafe {
  62. abort();
  63. }
  64. }
  65. }};
  66. }