summary refs log tree commit diff stats
path: root/src/vm/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/mod.rs')
-rw-r--r--src/vm/mod.rs28
1 files changed, 20 insertions, 8 deletions
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<IndexMap<&'pat str, (Pack<'pat, 'de>, 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<O: Serialize>(
+    fn get_type(
         &self,
-        pat: &'pat PatternConstants<O>,
     ) -> 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<usize> {
-        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,
+            )
         })
     }