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.rs92
1 files changed, 45 insertions, 47 deletions
diff --git a/src/vm/mod.rs b/src/vm/mod.rs
index dca15a9..afb98cc 100644
--- a/src/vm/mod.rs
+++ b/src/vm/mod.rs
@@ -77,23 +77,19 @@ impl<O: Serialize> std::fmt::Debug for PatternConstants<O> {
 }
 
 /// A pattern element.
+// FIXME: docs
 #[derive(Copy, Clone, Debug)]
 pub(crate) enum PatternElement {
-    /// A value is the entry point to a pattern. If present, it's the first
-    /// element.
+    /// A value is the core capturing element.
     Value {
         /// The index of the (string) name to apply to this value and/or the
         /// expected value of this entry.
         name_and_value: These<usize, Value>,
     },
-    /// A tag is the core iterative element, and is repeated up to the desired
-    /// depth of iteration.
+    /// A tag is the core iterative element. It is always followed by a value.
     Tag {
         /// The index of the (proto) key to match against.
         key_subtree: Option<usize>,
-        /// The index of the (string) name to apply to this value and/or the
-        /// expected value of this entry.
-        name_and_value: These<usize, Value>,
     },
     /// Marks the end of pattern iteration and the start of subtrees (if any).
     SubtreeMarker,
@@ -294,43 +290,43 @@ pub(crate) enum SerdeObject<'de> {
 }
 
 impl<'de> SerdeObject<'de> {
-    /// Checks the type of this object.
-    fn check<E: serde::de::Error>(&self, ty: Option<Type>) -> Result<(), E> {
-        let ty = match ty {
-            None => return Ok(()),
-            Some(ty) => ty,
-        };
-        match (ty, self) {
-            | (Type::Any, v)
-            | (Type::IgnoredAny, v)
-            => Ok(()),
-            | (Type::Bool, v @ SerdeObject::Bool(_))
-            | (Type::I8, v @ SerdeObject::I8(_))
-            | (Type::I16, v @ SerdeObject::I16(_))
-            | (Type::I32, v @ SerdeObject::I32(_))
-            | (Type::I64, v @ SerdeObject::I64(_))
-            | (Type::I128, v @ SerdeObject::I128(_))
-            | (Type::U8, v @ SerdeObject::U8(_))
-            | (Type::U16, v @ SerdeObject::U16(_))
-            | (Type::U32, v @ SerdeObject::U32(_))
-            | (Type::U64, v @ SerdeObject::U64(_))
-            | (Type::U128, v @ SerdeObject::U128(_))
-            | (Type::F32, v @ SerdeObject::F32(_))
-            | (Type::F64, v @ SerdeObject::F64(_))
-            | (Type::Char, v @ SerdeObject::Char(_))
-            | (Type::Str, v @ SerdeObject::Str(_))
-            | (Type::String, v @ SerdeObject::Str(_))
-            | (Type::Bytes, v @ SerdeObject::Bytes(_))
-            | (Type::ByteBuf, v @ SerdeObject::Bytes(_))
-            | (Type::Option, v @ SerdeObject::None)
-            | (Type::Option, v @ SerdeObject::Some(_))
-            | (Type::Unit, v @ SerdeObject::Unit)
-            | (Type::Seq, v @ SerdeObject::Seq(_))
-            | (Type::Map, v @ SerdeObject::Map(_))
-            => Ok(()),
-            _ => todo!(),
-        }
-    }
+    ///// Checks the type of this object.
+    //fn check<E: serde::de::Error>(&self, ty: Option<Type>) -> Result<(), E> {
+    //    let ty = match ty {
+    //        None => return Ok(()),
+    //        Some(ty) => ty,
+    //    };
+    //    match (ty, self) {
+    //        | (Type::Any, v)
+    //        | (Type::IgnoredAny, v)
+    //        => Ok(()),
+    //        | (Type::Bool, v @ SerdeObject::Bool(_))
+    //        | (Type::I8, v @ SerdeObject::I8(_))
+    //        | (Type::I16, v @ SerdeObject::I16(_))
+    //        | (Type::I32, v @ SerdeObject::I32(_))
+    //        | (Type::I64, v @ SerdeObject::I64(_))
+    //        | (Type::I128, v @ SerdeObject::I128(_))
+    //        | (Type::U8, v @ SerdeObject::U8(_))
+    //        | (Type::U16, v @ SerdeObject::U16(_))
+    //        | (Type::U32, v @ SerdeObject::U32(_))
+    //        | (Type::U64, v @ SerdeObject::U64(_))
+    //        | (Type::U128, v @ SerdeObject::U128(_))
+    //        | (Type::F32, v @ SerdeObject::F32(_))
+    //        | (Type::F64, v @ SerdeObject::F64(_))
+    //        | (Type::Char, v @ SerdeObject::Char(_))
+    //        | (Type::Str, v @ SerdeObject::Str(_))
+    //        | (Type::String, v @ SerdeObject::Str(_))
+    //        | (Type::Bytes, v @ SerdeObject::Bytes(_))
+    //        | (Type::ByteBuf, v @ SerdeObject::Bytes(_))
+    //        | (Type::Option, v @ SerdeObject::None)
+    //        | (Type::Option, v @ SerdeObject::Some(_))
+    //        | (Type::Unit, v @ SerdeObject::Unit)
+    //        | (Type::Seq, v @ SerdeObject::Seq(_))
+    //        | (Type::Map, v @ SerdeObject::Map(_))
+    //        => Ok(()),
+    //        _ => todo!(),
+    //    }
+    //}
 }
 
 impl<'de, E> serde::de::IntoDeserializer<'de, E> for SerdeObject<'de>
@@ -354,6 +350,7 @@ pub struct Pack<'pat, 'de> {
 }
 
 /// The Datafu interpreter, sorta.
+#[derive(Debug)]
 pub(crate) struct Interpreter<'pat, 'state, O: Serialize> {
     /// The pattern currently being processed.
     pat: &'pat PatternConstants<O>,
@@ -363,6 +360,7 @@ pub(crate) struct Interpreter<'pat, 'state, O: Serialize> {
     frames: &'state mut Vec<Frame<'pat>>,
 }
 
+#[derive(Debug)]
 pub(crate) struct Frame<'pat> {
     /// The instructions/function currently being processed.
     ops: &'pat [PatternElement],
@@ -385,7 +383,7 @@ impl<'pat, 'state, O: Serialize> Interpreter<'pat, 'state, O> {
     ) -> Self {
         debug_assert!(frames.is_empty());
         frames.push(Frame {
-            ops: &pat.protos[0],
+            ops: &pat.protos.last().unwrap(),
             iar: None,
             overstep: 0,
             matches: true,
@@ -410,7 +408,6 @@ impl<'pat> Frame<'pat> {
     ) -> Option<(Type, bool)> {
         match self.op() {
             | PatternElement::Value { name_and_value, .. }
-            | PatternElement::Tag { name_and_value, .. }
             if name_and_value.is_there()
             => {
                 match name_and_value.there() {
@@ -425,6 +422,7 @@ impl<'pat> Frame<'pat> {
                     None => todo!(),
                 }
             },
+            PatternElement::Tag { .. } => panic!("attempt to get type of tag"),
             _ => None,
         }
     }
@@ -437,11 +435,11 @@ impl<'pat> Frame<'pat> {
         let strings = &pat.strings;
         match self.op() {
             | PatternElement::Value { name_and_value, .. }
-            | PatternElement::Tag { name_and_value, .. }
             if name_and_value.is_here()
             => {
                 Some(&*strings[name_and_value.here().unwrap()])
             },
+            PatternElement::Tag { .. } => panic!("attempt to get name of tag"),
             _ => None,
         }
     }