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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
use core::cmp::{Eq, Ordering, PartialEq};
use core::hash;
use core::ops::ControlFlow;

use crate::alloc::{self, HashMap};
use crate::runtime as rt;
use crate::runtime::{RawStr, TypeInfo};
use crate::Hash;

/// Static type information.
#[derive(Debug)]
#[repr(C)]
pub struct StaticType {
    /// The name of the static type.
    pub(crate) name: RawStr,
    /// The hash of the static type.
    pub(crate) hash: Hash,
}

impl StaticType {
    #[inline]
    pub(crate) fn type_info(&'static self) -> TypeInfo {
        TypeInfo::StaticType(self)
    }
}

impl PartialEq for &'static StaticType {
    fn eq(&self, other: &Self) -> bool {
        self.hash == other.hash
    }
}

impl Eq for &'static StaticType {}

impl hash::Hash for &'static StaticType {
    fn hash<H: hash::Hasher>(&self, state: &mut H) {
        self.hash.hash(state)
    }
}

/// Hash for `::std::u8`.
pub(crate) const BYTE_TYPE_HASH: Hash = ::rune_macros::hash!(::std::u8);

/// The specialized type information for a byte type.
pub(crate) static BYTE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("u8"),
    hash: BYTE_TYPE_HASH,
};

impl_static_type!(u8 => BYTE_TYPE);

/// The specialized type information for a bool type.
pub(crate) static BOOL_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("bool"),
    hash: ::rune_macros::hash!(::std::bool),
};

impl_static_type!(bool => BOOL_TYPE);

/// The specialized type information for a char type.
pub(crate) static CHAR_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("char"),
    hash: ::rune_macros::hash!(::std::char),
};

impl_static_type!(char => CHAR_TYPE);

/// Hash for `::std::i64`.
pub(crate) const INTEGER_TYPE_HASH: Hash = ::rune_macros::hash!(::std::i64);

/// The specialized type information for a integer type.
pub(crate) static INTEGER_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("i64"),
    hash: INTEGER_TYPE_HASH,
};

impl_static_type!(i8 => INTEGER_TYPE);
// NB: u8 is its own BYTE_TYPE
impl_static_type!(u16 => INTEGER_TYPE);
impl_static_type!(i16 => INTEGER_TYPE);
impl_static_type!(u32 => INTEGER_TYPE);
impl_static_type!(i32 => INTEGER_TYPE);
impl_static_type!(u64 => INTEGER_TYPE);
impl_static_type!(i64 => INTEGER_TYPE);
impl_static_type!(u128 => INTEGER_TYPE);
impl_static_type!(i128 => INTEGER_TYPE);
impl_static_type!(usize => INTEGER_TYPE);
impl_static_type!(isize => INTEGER_TYPE);

/// Hash for `::std::f64`.
pub(crate) const FLOAT_TYPE_HASH: Hash = ::rune_macros::hash!(::std::f64);

pub(crate) static FLOAT_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("f64"),
    hash: FLOAT_TYPE_HASH,
};

impl_static_type!(f32 => FLOAT_TYPE);
impl_static_type!(f64 => FLOAT_TYPE);

pub(crate) static STRING_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("String"),
    hash: ::rune_macros::hash!(::std::string::String),
};

#[cfg(feature = "alloc")]
impl_static_type!(::rust_alloc::string::String => STRING_TYPE);
impl_static_type!(alloc::String => STRING_TYPE);
impl_static_type!(str => STRING_TYPE);

pub(crate) static BYTES_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Bytes"),
    hash: ::rune_macros::hash!(::std::bytes::Bytes),
};

impl_static_type!([u8] => BYTES_TYPE);

pub(crate) static VEC_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Vec"),
    hash: ::rune_macros::hash!(::std::vec::Vec),
};

impl_static_type!([rt::Value] => VEC_TYPE);
#[cfg(feature = "alloc")]
impl_static_type!(impl<T> ::rust_alloc::vec::Vec<T> => VEC_TYPE);
impl_static_type!(impl<T> alloc::Vec<T> => VEC_TYPE);
impl_static_type!(impl<T> rt::VecTuple<T> => VEC_TYPE);

pub(crate) static TUPLE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Tuple"),
    hash: ::rune_macros::hash!(::std::tuple::Tuple),
};

impl_static_type!(rt::OwnedTuple => TUPLE_TYPE);

pub(crate) static OBJECT_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Object"),
    hash: ::rune_macros::hash!(::std::object::Object),
};

impl_static_type!(rt::Struct => OBJECT_TYPE);
impl_static_type!(impl<T> HashMap<::rust_alloc::string::String, T> => OBJECT_TYPE);
impl_static_type!(impl<T> HashMap<alloc::String, T> => OBJECT_TYPE);

cfg_std! {
    impl_static_type!(impl<T> ::std::collections::HashMap<::rust_alloc::string::String, T> => OBJECT_TYPE);
    impl_static_type!(impl<T> ::std::collections::HashMap<alloc::String, T> => OBJECT_TYPE);
}

pub(crate) static RANGE_FROM_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("RangeFrom"),
    hash: ::rune_macros::hash!(::std::ops::RangeFrom),
};

pub(crate) static RANGE_FULL_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("RangeFull"),
    hash: ::rune_macros::hash!(::std::ops::RangeFull),
};

pub(crate) static RANGE_INCLUSIVE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("RangeInclusive"),
    hash: ::rune_macros::hash!(::std::ops::RangeInclusive),
};

pub(crate) static RANGE_TO_INCLUSIVE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("RangeToInclusive"),
    hash: ::rune_macros::hash!(::std::ops::RangeToInclusive),
};

pub(crate) static RANGE_TO_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("RangeTo"),
    hash: ::rune_macros::hash!(::std::ops::RangeTo),
};

pub(crate) static RANGE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Range"),
    hash: ::rune_macros::hash!(::std::ops::Range),
};

pub(crate) static CONTROL_FLOW_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("ControlFlow"),
    hash: ::rune_macros::hash!(::std::ops::ControlFlow),
};

impl_static_type!(impl<C, B> ControlFlow<C, B> => CONTROL_FLOW_TYPE);

pub(crate) static FUTURE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Future"),
    hash: ::rune_macros::hash!(::std::future::Future),
};

pub(crate) static GENERATOR_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Generator"),
    hash: ::rune_macros::hash!(::std::ops::Generator),
};

pub(crate) static GENERATOR_STATE_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("GeneratorState"),
    hash: ::rune_macros::hash!(::std::ops::GeneratorState),
};

pub(crate) static STREAM_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Stream"),
    hash: ::rune_macros::hash!(::std::stream::Stream),
};

pub(crate) static RESULT_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Result"),
    hash: ::rune_macros::hash!(::std::result::Result),
};

impl_static_type!(impl<T, E> Result<T, E> => RESULT_TYPE);

pub(crate) static OPTION_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Option"),
    hash: ::rune_macros::hash!(::std::option::Option),
};

impl_static_type!(impl<T> Option<T> => OPTION_TYPE);

pub(crate) static FUNCTION_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Function"),
    hash: ::rune_macros::hash!(::std::ops::Function),
};

pub(crate) static FORMAT_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Format"),
    hash: ::rune_macros::hash!(::std::fmt::Format),
};

pub(crate) static ITERATOR_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Iterator"),
    hash: ::rune_macros::hash!(::std::iter::Iterator),
};

pub(crate) static ORDERING_TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Ordering"),
    hash: ::rune_macros::hash!(::std::cmp::Ordering),
};

impl_static_type!(Ordering => ORDERING_TYPE);

pub(crate) static TYPE: &StaticType = &StaticType {
    name: RawStr::from_str("Type"),
    hash: ::rune_macros::hash!(::std::any::Type),
};

impl_static_type!(rt::Type => TYPE);