Guest User

Untitled

a guest
May 20th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. ($num:expr;$($field:ident),*;$($rev:ident),*) => {
  2. impl<$($field,)*> Pop for ($($field,)*)
  3. where
  4. $($field: Pop),*
  5. {
  6. fn tag() -> Ty {
  7. unreachable!()
  8. }
  9.  
  10. fn pop_tags(stack: &mut Stack) -> Result<()> {
  11. stack.expect_tag(Ty::Tuple)?;
  12. let num_elems = stack.pop_u64()?;
  13. if num_elems != $num as u64 {
  14. // we need to re-push length and tuple tag
  15. stack.push_u64(num_elems);
  16. stack.push_tag(Ty::Tuple);
  17.  
  18. return Err(TupleMismatch {
  19. expected: $num as usize,
  20. got: num_elems as usize,
  21. }.into());
  22. }
  23.  
  24. impl_tuple_and_array!(@pop_tags stack num_elems;$($field)*;);
  25.  
  26. Ok(())
  27. }
  28.  
  29. fn pop_value(stack: &mut Stack) -> Result<Self> {
  30. Ok(($($field::pop_value(stack)?,)*))
  31. }
  32. }
  33. };
  34. (@pop_tags $stack:ident $num_elems:ident;;$($pushed:ident)*) => {
  35. };
  36. (@pop_tags $stack:ident $num_elems:ident; $field0:ident $($field:ident)*; $($pushed:ident)*) => {
  37. match $field0::pop_tags($stack) {
  38. Ok(_) => {}
  39. Err(e) => {
  40. // restore popped tags
  41. $(
  42. $pushed::restore_tags($stack);
  43. )*
  44. $stack.push_u64($num_elems);
  45. $stack.push_tag(Ty::Tuple);
  46.  
  47. return Err(e);
  48. }
  49. }
  50. impl_tuple_and_array!(@pop_tags $stack $num_elems; $($field)*; $field0 $($pushed)*);
  51. };
Add Comment
Please, Sign In to add comment