summary refs log tree commit diff stats
path: root/src/vm/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/mod.rs')
-rw-r--r--src/vm/mod.rs24
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