diff options
Diffstat (limited to 'src/vm/de.rs')
-rw-r--r-- | src/vm/de.rs | 135 |
1 files changed, 134 insertions, 1 deletions
diff --git a/src/vm/de.rs b/src/vm/de.rs index 7039ea9..4d0d097 100644 --- a/src/vm/de.rs +++ b/src/vm/de.rs @@ -1,6 +1,139 @@ // Copyright (C) 2022 Soni L. // SPDX-License-Identifier: MIT OR Apache-2.0 -use crate::vm; +//! Deserialization-related parts of the VM. +use serde::Serialize; +use serde::de::Error as _; +use super::PatternConstants; +use super::PatternElement; +use super::Pack; + +/// A `DeserializeSeed` for Datafu input. +/// +/// This converts from Serde to Datafu's internal representation (a "pack"). +pub struct Packer<'pat, O: Serialize> { + /// The pattern currently being processed. + pat: &'pat PatternConstants<O>, + /// The instructions/function currently being processed. + ops: &'pat [PatternElement], + /// Maximum number of calls. + call_limit: usize, +} + +impl<'pat, O: Serialize> Packer<'pat, O> { + pub(crate) fn new( + pat: &'pat PatternConstants<O>, + call_limit: usize, + ) -> Self { + Self { + pat, call_limit, ops: &pat.protos.last().unwrap()[..], + } + } +} + +impl<'pat, 'de, O> serde::de::DeserializeSeed<'de> for Packer<'pat, O> +where + O: Serialize, +{ + type Value = Pack; + fn deserialize<D>(self, deserializer: D) -> Result<Pack, D::Error> + where + D: serde::Deserializer<'de> + { + // check the first op + let first = self.ops.first(); + match first { + Some(PatternElement::ApplyPredicate(id, skippable)) => { + let predicate = &self.pat.predicates[*id]; + let ok = predicate(todo!()); + match (ok, skippable) { + (true, _) => { + todo!() + }, + (false, false) => { + return Err(D::Error::custom("predicate didn't match")); + }, + (false, true) => { + todo!() + }, + } + }, + _ => { + dbg!(first); + todo!() + }, + } + } +} + +/// A `Deserializer` for Datafu output. +/// +/// This converts from Datafu's internal representation (a "pack") into the +/// desired output type. +pub struct Unpacker { + pack: Pack, + call_limit: usize, +} + +impl Unpacker { + /// Unpacks a Datafu "pack". + pub fn new(pack: Pack, call_limit: usize) -> Self { + Self { + pack, call_limit, + } + } +} + +impl<'de> serde::Deserializer<'de> for Unpacker { + // TODO datafu errors + type Error = serde::de::value::Error; + fn deserialize_any<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_bool<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_i8<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_i16<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_i32<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_i64<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_u8<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_u16<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_u32<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_u64<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_f32<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_f64<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_char<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_str<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_string<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_bytes<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_byte_buf<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_option<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_unit<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_unit_struct<V>(self, _: &'static str, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_newtype_struct<V>(self, _: &'static str, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_seq<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_tuple_struct<V>(self, _: &'static str, _: usize, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_map<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_struct<V>( + self, + _: &'static str, + fields: &'static [&'static str], + visitor: V, + ) -> Result<V::Value, Self::Error> + where + V: serde::de::Visitor<'de>, + { + todo!() + } + fn deserialize_enum<V>(self, _: &'static str, _: &'static [&'static str], _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_identifier<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } + fn deserialize_ignored_any<V>(self, _: V) -> Result<V::Value, Self::Error> where V: serde::de::Visitor<'de> { todo!() } +} + +/// A Deserializer for collecting matches from [`crate::Predicate`]s. +/// +/// What are we doing? +/// +/// We certainly have regrets. +pub struct PredicateCollector { +} |