From e8a11468fefd81c2d9181ca15bceaf71e09a5345 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Tue, 11 Oct 2022 09:50:36 -0300 Subject: Initial support for empty and simple patterns --- src/vm/mod.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/vm/mod.rs') 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, /// The error override (if any). - error: &'state Cell>, + error: &'state mut Option, /// The current interpreter frames. - frames: &'state RefCell>>, + frames: &'state mut Vec>, ///// The final output. //output: &'state Cell>, } @@ -367,8 +367,8 @@ pub(crate) struct Frame<'pat> { ops: &'pat [PatternElement], /// The instruction index being processed. iar: Option, - /// Whether this frame matches. - matches: bool, + /// How many steps this frame has failed to match. + overstep: Option, ///// 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, error: &'state mut Option, - frames: &'state RefCell>>, + frames: &'state mut Vec>, //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 -- cgit 1.4.1