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
pub trait GuardedArgs {
type Guard;
unsafe fn unsafe_into_stack(
self,
stack: &mut crate::Stack,
) -> Result<Self::Guard, crate::VmError>;
fn count() -> usize;
}
macro_rules! impl_into_args {
() => {
impl_into_args!{@impl 0,}
};
({$ty:ident, $value:ident, $count:expr}, $({$l_ty:ident, $l_value:ident, $l_count:expr},)*) => {
impl_into_args!{@impl $count, {$ty, $value, $count}, $({$l_ty, $l_value, $l_count},)*}
impl_into_args!{$({$l_ty, $l_value, $l_count},)*}
};
(@impl $count:expr, $({$ty:ident, $value:ident, $ignore_count:expr},)*) => {
impl<$($ty,)*> GuardedArgs for ($($ty,)*)
where
$($ty: $crate::UnsafeToValue,)*
{
type Guard = ($($ty::Guard,)*);
#[allow(unused)]
unsafe fn unsafe_into_stack(self, stack: &mut $crate::Stack) -> Result<Self::Guard, $crate::VmError> {
let ($($value,)*) = self;
$(let $value = $value.unsafe_to_value()?;)*
$(stack.push($value.0);)*
Ok(($($value.1,)*))
}
fn count() -> usize {
$count
}
}
};
}
repeat_macro!(impl_into_args);