diff options
Diffstat (limited to 'src/vm/mod.rs')
-rw-r--r-- | src/vm/mod.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/vm/mod.rs b/src/vm/mod.rs index 190fa3d..8122778 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -355,9 +355,9 @@ pub(crate) struct Interpreter<'pat, 'state, O: Serialize> { /// The pattern currently being processed. pat: &'pat PatternConstants<O>, /// The error override (if any). - error: &'state Cell<Option<crate::errors::MatchError>>, + error: &'state mut Option<crate::errors::MatchError>, /// The current interpreter frames. - frames: &'state RefCell<Vec<Frame<'pat>>>, + frames: &'state mut Vec<Frame<'pat>>, ///// The final output. //output: &'state Cell<Pack<'pat, 'de>>, } @@ -367,8 +367,8 @@ pub(crate) struct Frame<'pat> { ops: &'pat [PatternElement], /// The instruction index being processed. iar: Option<usize>, - /// Whether this frame matches. - matches: bool, + /// How many steps this frame has failed to match. + overstep: Option<usize>, ///// Elements collected while processing this frame? //path: Pack<'pat, 'de>, } @@ -377,21 +377,19 @@ impl<'pat, 'state, O: Serialize> Interpreter<'pat, 'state, O> { pub(crate) fn new( pat: &'pat PatternConstants<O>, error: &'state mut Option<crate::errors::MatchError>, - frames: &'state RefCell<Vec<Frame<'pat>>>, + frames: &'state mut Vec<Frame<'pat>>, //output: &'state mut Pack<'pat, 'de>, ) -> Self { - let mut mut_frames = frames.borrow_mut(); - debug_assert!(mut_frames.is_empty()); - mut_frames.push(Frame { + debug_assert!(frames.is_empty()); + frames.push(Frame { ops: &pat.protos[0], iar: None, - matches: true, + overstep: None, //path: Default::default(), }); - drop(mut_frames); Self { pat: pat, - error: Cell::from_mut(error), + error: error, frames: frames, //output: Cell::from_mut(output), } @@ -463,10 +461,14 @@ impl<'pat> Frame<'pat> { /// /// Panics if called on a non-matching frame or if iteration hasn't begun. fn op(&self) -> PatternElement { - assert!(self.matches, "op() called on non-matching frame"); + assert!(self.matches(), "op() called on non-matching frame"); self.ops[self.iar.expect("ops[iar]")] } + fn matches(&self) -> bool { + self.overstep.is_none() + } + /// Rewinds the instruction address register. /// /// # Returns |