From 9481722069fc463f2557be61cb9b8fcd4ed7e3bd Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Thu, 27 Oct 2022 20:20:46 -0300 Subject: Make multiple frames work --- src/vm/mod.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/vm/mod.rs') diff --git a/src/vm/mod.rs b/src/vm/mod.rs index afb98cc..dca9faa 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -344,11 +344,20 @@ where } } +/// Packed serde objects and datafu internal representation. +/// +/// This is an iterative store of key-value pairs. #[derive(Clone, Debug, Default)] pub struct Pack<'pat, 'de> { subpacks: Vec, SerdeObject<'de>)>>, } +impl<'pat, 'de> Pack<'pat, 'de> { + fn merge_from(&mut self, mut other: Self) { + todo!("merge packs"); + } +} + /// The Datafu interpreter, sorta. #[derive(Debug)] pub(crate) struct Interpreter<'pat, 'state, O: Serialize> { @@ -402,9 +411,8 @@ impl<'pat> Frame<'pat> { /// Gets the type currently associated with this frame. /// /// Returns the type and whether it is required to match. - fn get_type( + fn get_type( &self, - pat: &'pat PatternConstants, ) -> Option<(Type, bool)> { match self.op() { | PatternElement::Value { name_and_value, .. } @@ -467,13 +475,14 @@ impl<'pat> Frame<'pat> { self.ops[self.iar.expect("ops[iar]")] } - /// Counts the number of *active* subtrees, if any. + /// Counts the number of *active* subtrees, if any, and whether any + /// subtrees have been unwound. /// /// # Panics /// /// Panics if iteration hasn't begun. - fn num_subtrees(&self) -> Option { - let iar = self.iar.expect("iar"); + fn num_subtrees(&self) -> Option<(usize, bool)> { + let iar = self.iar?; // check if there are any subtrees matches!( self.ops[iar], @@ -481,9 +490,12 @@ impl<'pat> Frame<'pat> { | PatternElement::SubtreeMarker ).then(|| { // count the number of subtrees - self.ops[0..=iar].iter().rev().take_while(|x| { - matches!(x, PatternElement::ValueSubtree { .. }) - }).count() + ( + self.ops[0..=iar].iter().rev().take_while(|x| { + matches!(x, PatternElement::ValueSubtree { .. }) + }).count(), + self.ops.len() - 1 != iar, + ) }) } -- cgit 1.4.1