summary refs log tree commit diff stats
path: root/src/vm/mod.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-10-27 20:20:46 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-10-27 20:20:46 -0300
commit9481722069fc463f2557be61cb9b8fcd4ed7e3bd (patch)
tree05e264958cf91dd638d06db16882e8ba6da5059a /src/vm/mod.rs
parent8fa3870633377dd626faa2e2145ae068109e6456 (diff)
Make multiple frames work
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,
+            )
         })
     }