rune/
macros.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Implementations of macros
macro_rules! define_unbox {
    ($ident:ident, $ty:ty) => {
        define_unbox!($ident, $ident, $ty);
    };
    ($ident:ident, $ty:ident, $self:ty) => {
        #[allow(unused_qualifications)]
        impl<'ob> std::convert::TryFrom<crate::core::object::Object<'ob>> for $self {
            type Error = crate::core::error::TypeError;
            fn try_from(obj: crate::core::object::Object<'ob>) -> Result<Self, Self::Error> {
                match obj.untag() {
                    crate::core::object::ObjectType::$ident(x) => Ok(x),
                    _ => {
                        Err(crate::core::error::TypeError::new(crate::core::error::Type::$ty, obj))
                    }
                }
            }
        }
        #[allow(unused_qualifications)]
        impl<'ob> std::convert::TryFrom<crate::core::object::Object<'ob>> for Option<$self> {
            type Error = crate::core::error::TypeError;
            fn try_from(obj: crate::core::object::Object<'ob>) -> Result<Self, Self::Error> {
                match obj.untag() {
                    crate::core::object::ObjectType::NIL => Ok(None),
                    crate::core::object::ObjectType::$ident(x) => Ok(Some(x)),
                    _ => {
                        Err(crate::core::error::TypeError::new(crate::core::error::Type::$ty, obj))
                    }
                }
            }
        }
    };
}

// Implementation in build.rs
macro_rules! defsym {
    ($sym:ident) => {};
    ($sym:ident, $name:literal) => {};
}

macro_rules! defvar_bool {
    ($sym:ident, $value:literal) => {};
    ($sym:ident, $name:literal, $value:literal) => {};
}

macro_rules! defvar {
    ($sym:ident) => {};
    ($sym:ident, list![$($values:expr),+ $(,)?]) => {};
    ($sym:ident, $value:expr) => {};
    ($sym:ident, $name:literal, $value:expr) => {};
}