summary refs log blame commit diff stats
path: root/src/vm/de.rs
blob: 4d0d097bc90c1da69e72b4cd337f33825a8d74b2 (plain) (tree)
1
2
3
4
5
6
7
8


                                             
                                            
 

                          
 


































































































































                                                                                                                                                                 
// Copyright (C) 2022 Soni L.
// SPDX-License-Identifier: MIT OR Apache-2.0

//! 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 {
}