diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-10-28 18:53:43 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-10-28 18:53:43 -0300 |
commit | bdb078a5416a65a976cc96d70521d7da32c9b689 (patch) | |
tree | 769070de6801bc8b956509a333342a0dff9b086c /src/vm/mod.rs | |
parent | 9481722069fc463f2557be61cb9b8fcd4ed7e3bd (diff) |
Implement Packer::visit_map
Diffstat (limited to 'src/vm/mod.rs')
-rw-r--r-- | src/vm/mod.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/vm/mod.rs b/src/vm/mod.rs index dca9faa..8f20aae 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -353,8 +353,17 @@ pub struct Pack<'pat, 'de> { } impl<'pat, 'de> Pack<'pat, 'de> { + /// Merges two packs, with elements from `other` coming after `self`. fn merge_from(&mut self, mut other: Self) { - todo!("merge packs"); + for (left, right) in self.subpacks.iter_mut().zip(other.subpacks) { + left.extend(right) + } + } + + /// Same as `merge_from` but borrows `other` instead of `self`. + fn merge_into(mut self, other: &mut Self) { + std::mem::swap(&mut self, other); + other.merge_from(self); } } @@ -499,6 +508,19 @@ impl<'pat> Frame<'pat> { }) } + /// Returns whether this key has a subtree. + /// + /// # Panics + /// + /// Panics if iteration hasn't begun, or this isn't a key. + fn key_subtree(&self) -> Option<usize> { + if let PatternElement::Tag { key_subtree } = self.op() { + key_subtree + } else { + unreachable!() + } + } + /// Returns the raw instruction. /// /// # Panics |