1#![allow(clippy::crate_in_macro_def)]
2#[macro_export]
7#[doc(hidden)]
8macro_rules! __define_unbox {
9 ($ident:ident, $ty:ty) => {
10 define_unbox!($ident, $ident, $ty);
11 };
12 ($ident:ident, $ty:ident, $self:ty) => {
13 #[allow(unused_qualifications)]
14 impl<'ob> std::convert::TryFrom<crate::object::Object<'ob>> for $self {
15 type Error = crate::error::TypeError;
16 fn try_from(obj: crate::object::Object<'ob>) -> Result<Self, Self::Error> {
17 match obj.untag() {
18 crate::object::Object::$ident(x) => Ok(x),
19 _ => Err(crate::error::TypeError::new(crate::error::Type::$ty, obj)),
20 }
21 }
22 }
23 #[allow(unused_qualifications)]
24 impl<'ob> std::convert::TryFrom<crate::object::Object<'ob>> for Option<$self> {
25 type Error = crate::error::TypeError;
26 fn try_from(obj: crate::object::Object<'ob>) -> Result<Self, Self::Error> {
27 match obj.untag() {
28 crate::object::Object::NIL => Ok(None),
29 crate::object::Object::$ident(x) => Ok(Some(x)),
30 _ => Err(crate::error::TypeError::new(crate::error::Type::$ty, obj)),
31 }
32 }
33 }
34 };
35}
36
37#[macro_export]
38#[doc(hidden)]
39macro_rules! __list {
40 ($x:expr; $cx:expr) => {
41 crate::core::object::Object::from(crate::core::cons::Cons::new1($x, $cx))
42 };
43 ($x:expr, $($y:expr),+ $(,)? ; $cx:expr) => {
44 crate::core::object::Object::from(crate::core::cons::Cons::new($x, list!($($y),+ ; $cx), $cx))
45 };
46}
47
48#[macro_export]
49#[doc(hidden)]
50macro_rules! __error {
51 ($msg:literal $(,)? $($args:expr),* $(,)?) => (crate::eval::EvalError::new_error(anyhow::anyhow!($msg, $($args),*)));
52 ($err:expr) => (crate::eval::EvalError::new($err));
53}
54
55#[macro_export]
56#[doc(hidden)]
57macro_rules! __bail_err {
58 ($($args:expr),* $(,)?) => (return Err($crate::macros::error!($($args),*)));
59}
60
61#[macro_export]
62#[doc(hidden)]
63macro_rules! __root {
64 ($ident:ident, $cx:ident) => {
65 rune_core::macros::root!(@ $ident, unsafe { crate::core::gc::IntoRoot::into_root($ident) }, $cx);
66 };
67 ($ident:ident, init($init:expr), $cx:ident) => {
68 let value = $init;
69 rune_core::macros::root!(@ $ident, value, $cx);
70 };
71 ($ident:ident, new($path:tt$(<$ty:ty>)?), $cx:ident) => {
72 let value = $path$(::<$ty>)?::default();
73 rune_core::macros::root!(@ $ident, value, $cx);
74 };
75 ($ident:ident, $value:expr, $cx:ident) => {
76 rune_core::macros::root!(@ $ident, unsafe { crate::core::gc::IntoRoot::into_root($value) }, $cx);
77 };
78 (@ $ident:ident, $value:expr, $cx:ident) => {
79 let mut rooted = $value;
80 let mut root =
81 unsafe { crate::core::gc::__StackRoot::new(&mut rooted, $cx.get_root_set()) };
82 let $ident = root.as_mut();
83 };
84}
85
86#[macro_export]
87#[doc(hidden)]
88macro_rules! __last {
89 ($arg:expr) => { $arg };
90 ($head:expr, $($rest:expr),+) => {
91 $crate::macros::last!($($rest),+)
92 };
93}
94
95#[macro_export]
96#[doc(hidden)]
97macro_rules! __rebind {
98 ($($path:ident).*($($arg:expr),+)$($x:tt)?) => {{
100 rebind!($($path).*($($arg),+)$($x)?, $crate::macros::last!($($arg),+))
101 }};
102 ($($path:ident).*($($arg:expr),+).unwrap()) => {{
104 rebind!($($path).*($($arg),+).unwrap(), $crate::macros::last!($($arg),+))
105 }};
106 ($value:expr, $cx:expr) => {{
108 let unbound = match $value {
110 v => unsafe { crate::core::object::WithLifetime::<'static>::with_lifetime(v) }
111 };
112 $cx.bind(unbound)
113 }};
114}
115
116#[macro_export]
117#[doc(hidden)]
118macro_rules! __call {
119 ($fn:ident $(,$args:expr)* ; $env:expr, $cx:expr) => {{
120 let frame = &mut crate::core::env::CallFrame::new($env);
121 $(frame.push_arg($args);)*
122 crate::core::gc::Rt::<crate::core::gc::Slot<crate::core::object::Gc::<crate::core::object::FunctionType>>>::call(
123 $fn, frame, None, $cx
124 )
125 }};
126 ($fn:ident $(,$args:expr)* ; $name:expr, $env:expr, $cx:expr) => {{
127 let frame = &mut crate::core::env::CallFrame::new($env);
128 $(frame.push_arg($args);)*
129 crate::core::gc::Rt::<crate::core::gc::Slot<crate::core::object::Gc::<crate::core::object::FunctionType>>>::call(
130 $fn, frame, Some($name), $cx
131 )
132 }};
133}
134
135#[doc(inline)]
137pub use __bail_err as bail_err;
138
139#[doc(inline)]
141pub use __define_unbox as define_unbox;
142
143#[doc(inline)]
145pub use __error as error;
146
147#[doc(inline)]
149pub use __list as list;
150
151#[doc(inline)]
153pub use __last as last;
154
155#[doc(inline)]
157pub use __call as call;
158
159#[doc(inline)]
174pub use __rebind as rebind;
175
176#[doc(inline)]
181pub use __root as root;