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
#[cfg(not(feature = "no-std"))]
static PANIC_HANDLER_INIT: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
#[cfg(not(feature = "no-std"))]
#[doc(hidden)]
pub fn inital_setup() {
if PANIC_HANDLER_INIT
.compare_exchange(
false,
true,
std::sync::atomic::Ordering::Relaxed,
std::sync::atomic::Ordering::Relaxed,
)
.is_err()
{
return;
}
unsafe {
ocaml_boxroot_sys::boxroot_setup();
}
::std::panic::set_hook(Box::new(|info| unsafe {
let err = info.payload();
let msg = if err.is::<&str>() {
err.downcast_ref::<&str>().unwrap()
} else if err.is::<String>() {
err.downcast_ref::<String>().unwrap().as_ref()
} else {
"rust panic"
};
if let Some(err) = crate::Value::named("Rust_exception") {
crate::Error::raise_value(err, msg);
}
crate::Error::raise_failure(msg)
}))
}
#[macro_export]
#[cfg(not(feature = "no-std"))]
macro_rules! body {
($gc:ident: $code:block) => {{
let $gc = unsafe { $crate::Runtime::recover_handle() };
#[cfg(not(feature = "no-std"))]
$crate::inital_setup();
{
$code
}
}};
}
#[macro_export]
macro_rules! array {
($($x:expr),*) => {{
$crate::ToValue::to_value(&vec![$($crate::ToValue::to_value(&$x)),*])
}}
}
#[macro_export]
macro_rules! list {
($($x:expr),*) => {{
let mut l = $crate::list::empty();
for i in (&[$($x),*]).into_iter().rev() {
$crate::list::push_hd(&mut l, $crate::ToValue::to_value(i));
}
l
}};
}