summary refs log tree commit diff stats
path: root/src/vm/mod.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-10-30 20:28:37 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-10-30 20:28:37 -0300
commit477a1fd5ea7603dd261bcfef9cd443f98310e5db (patch)
treeb7e805ff44569f7094e35c5581574ea554b64117 /src/vm/mod.rs
parenta66111d9f9c99f91d9256209b5e9a65e42cde7f5 (diff)
Finish most of Packer and Parser
This is still broken even tho it passes the tests
Diffstat (limited to 'src/vm/mod.rs')
-rw-r--r--src/vm/mod.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/vm/mod.rs b/src/vm/mod.rs
index 06f12e5..131e48a 100644
--- a/src/vm/mod.rs
+++ b/src/vm/mod.rs
@@ -355,8 +355,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) {
-        for (left, right) in self.subpacks.iter_mut().zip(other.subpacks) {
-            left.extend(right)
+        match (self.subpacks.len(), other.subpacks.len()) {
+            (0, _) => {
+                *self = other;
+            },
+            (_, 0) => {},
+            (a, b) if a == b => {
+                for (l, r) in self.subpacks.iter_mut().zip(other.subpacks) {
+                    l.extend(r)
+                }
+            },
+            _ => unreachable!("merge_from unbalanced iterations"),
         }
     }
 
@@ -476,7 +485,7 @@ impl<'pat> Frame<'pat> {
     /// Panics if called on a non-matching frame or if iteration hasn't begun.
     fn op(&self) -> PatternElement {
         assert!(self.active(), "op() called on inactive frame");
-        self.ops[self.iar.expect("ops[iar]")]
+        self.raw_op()
     }
 
     /// Counts the number of *active* subtrees, if any, and whether any
@@ -486,7 +495,7 @@ impl<'pat> Frame<'pat> {
     ///
     /// Panics if iteration hasn't begun.
     fn num_subtrees(&self) -> Option<(usize, bool)> {
-        let iar = self.iar?;
+        let iar = self.iar.unwrap();
         // check if there are any subtrees
         matches!(
             self.ops[iar],