From 477a1fd5ea7603dd261bcfef9cd443f98310e5db Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 30 Oct 2022 20:28:37 -0300 Subject: Finish most of Packer and Parser This is still broken even tho it passes the tests --- src/vm/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/vm/mod.rs') 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], -- cgit 1.4.1