core::typeless
->std::ctypeless
This commit is contained in:
parent
aa4f47baf8
commit
17f974fb0f
@ -9,9 +9,8 @@ mod resolution;
|
|||||||
mod resolver_origin;
|
mod resolver_origin;
|
||||||
mod serialization;
|
mod serialization;
|
||||||
mod slice_deserializer;
|
mod slice_deserializer;
|
||||||
mod typeless;
|
|
||||||
|
|
||||||
use std::{error::Error, fmt::Display, rc::Rc};
|
use std::{error::Error, rc::Rc};
|
||||||
|
|
||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
@ -21,7 +20,6 @@ pub use self::points::TakesPoints;
|
|||||||
pub use self::resolution::*;
|
pub use self::resolution::*;
|
||||||
pub use self::serialization::*;
|
pub use self::serialization::*;
|
||||||
pub use self::slice_deserializer::*;
|
pub use self::slice_deserializer::*;
|
||||||
pub use self::typeless::*;
|
|
||||||
|
|
||||||
/// Basic support for tracing events across the execution.
|
/// Basic support for tracing events across the execution.
|
||||||
pub trait Diagnostic<T: Monad> {
|
pub trait Diagnostic<T: Monad> {
|
||||||
@ -72,8 +70,6 @@ pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable {
|
|||||||
}
|
}
|
||||||
/// References ([Point]s) to other objects. Typed.
|
/// References ([Point]s) to other objects. Typed.
|
||||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>);
|
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>);
|
||||||
/// References ([Point]s) to other objects. Typeless.
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shorthand for the type of vaalues returned by [`Factory::deserialize`].
|
/// Shorthand for the type of vaalues returned by [`Factory::deserialize`].
|
||||||
@ -81,7 +77,7 @@ pub type ParseResult<'a, Ctx, F> =
|
|||||||
Result<<F as Factory<'a, Ctx>>::Mtbl, <F as Factory<'a, Ctx>>::ParseError>;
|
Result<<F as Factory<'a, Ctx>>::Mtbl, <F as Factory<'a, Ctx>>::ParseError>;
|
||||||
|
|
||||||
/// Trait representing deserialisation rules for [Mentionable]s.
|
/// Trait representing deserialisation rules for [Mentionable]s.
|
||||||
/// Crucial for [`TypelessMentionable`] and therefore [`Mentionable::points`].
|
/// Crucial for [`crate::std::ctypeless`].
|
||||||
pub trait Factory<'a, Ctx: 'a + Context>: 'a + Send + Sync + Clone {
|
pub trait Factory<'a, Ctx: 'a + Context>: 'a + Send + Sync + Clone {
|
||||||
/// Type of the associated objects.
|
/// Type of the associated objects.
|
||||||
type Mtbl: Mentionable<'a, Ctx, Fctr = Self>;
|
type Mtbl: Mentionable<'a, Ctx, Fctr = Self>;
|
||||||
|
@ -32,7 +32,7 @@ pub type HashResolution<'a, Ctx> = Wrapped<
|
|||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Address {
|
pub struct Address {
|
||||||
pub point: Hash,
|
pub point: Hash,
|
||||||
/// Index of the point in the [`Mentionable::points()`].
|
/// Index of the point in the [`Mentionable::points_typed()`].
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
pub mod atomic;
|
pub mod atomic;
|
||||||
pub mod cast;
|
pub mod cast;
|
||||||
pub mod collections;
|
pub mod collections;
|
||||||
|
pub mod ctypeless;
|
||||||
pub mod fallible;
|
pub mod fallible;
|
||||||
pub mod inlining;
|
pub mod inlining;
|
||||||
mod local_origin;
|
mod local_origin;
|
||||||
|
@ -12,7 +12,8 @@ use crate::core::*;
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// This trait combines functionality of [`Mentionable`] and [`Factory`],
|
/// This trait combines functionality of [`Mentionable`] and [`Factory`],
|
||||||
/// while limiting [`Mentionable::points`] (and corresponding [`Mentionable::topology`]) to an empty sequence.
|
/// while limiting [`Mentionable::points_typed`] (and corresponding [`Mentionable::topology`])
|
||||||
|
/// to an empty sequence.
|
||||||
pub trait Atomic: 'static + Send + Sync + Send + Clone + Serializable {
|
pub trait Atomic: 'static + Send + Sync + Send + Clone + Serializable {
|
||||||
/// Equivalent of [`Factory::ParseError`].
|
/// Equivalent of [`Factory::ParseError`].
|
||||||
type AParseError: Error;
|
type AParseError: Error;
|
||||||
|
@ -47,8 +47,6 @@ impl<'a, Ctx: 'a + Context, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn points_typed(&self, _points: &mut impl TakesPoints<'a, Ctx>) {}
|
fn points_typed(&self, _points: &mut impl TakesPoints<'a, Ctx>) {}
|
||||||
|
|
||||||
fn points(&self, _points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generic implementation of a [Factory] for [Atomic]s.
|
/// Generic implementation of a [Factory] for [Atomic]s.
|
||||||
|
@ -7,7 +7,7 @@ use std::convert::identity;
|
|||||||
|
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
|
|
||||||
use super::{typeless::*, *};
|
use super::{ctypeless::*, typeless::*, *};
|
||||||
|
|
||||||
struct CastResolver<'a, Ctx: 'a + Context> {
|
struct CastResolver<'a, Ctx: 'a + Context> {
|
||||||
points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>,
|
points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>,
|
||||||
@ -23,7 +23,7 @@ pub enum CastError<'a> {
|
|||||||
/// If you don't know what that means, it's a good idea to [`panic!`].
|
/// If you don't know what that means, it's a good idea to [`panic!`].
|
||||||
/// Happens due to internal resolver using indices rather than `point`s.
|
/// Happens due to internal resolver using indices rather than `point`s.
|
||||||
/// This error usually indicates inconsistent behaviour
|
/// This error usually indicates inconsistent behaviour
|
||||||
/// of [`Mentionable::points`] and/or [`Mentionable::topology`].
|
/// of [`Mentionable::points_typed`] and/or [`Mentionable::topology`].
|
||||||
AddressIndexOutOfBounds {
|
AddressIndexOutOfBounds {
|
||||||
index: usize,
|
index: usize,
|
||||||
length: usize,
|
length: usize,
|
||||||
|
@ -138,13 +138,6 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RB
|
|||||||
RBNode::B(b) => b.points_typed(points),
|
RBNode::B(b) => b.points_typed(points),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
match self {
|
|
||||||
RBNode::R(r) => r.points(points),
|
|
||||||
RBNode::B(b) => b.points(points),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BNode<'a, Ctx, A> {
|
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BNode<'a, Ctx, A> {
|
||||||
@ -161,12 +154,6 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BN
|
|||||||
self.cr.points_typed(points);
|
self.cr.points_typed(points);
|
||||||
self.key.points_typed(points);
|
self.key.points_typed(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
self.cl.points(points);
|
|
||||||
self.cr.points(points);
|
|
||||||
self.key.points(points);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RNode<'a, Ctx, A> {
|
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RNode<'a, Ctx, A> {
|
||||||
@ -183,12 +170,6 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RN
|
|||||||
self.cr.points_typed(points);
|
self.cr.points_typed(points);
|
||||||
self.key.points_typed(points);
|
self.key.points_typed(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
self.cl.points(points);
|
|
||||||
self.cr.points(points);
|
|
||||||
self.key.points(points);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<F> {
|
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<F> {
|
||||||
|
@ -46,11 +46,6 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx>
|
|||||||
self.rest.points_typed(points);
|
self.rest.points_typed(points);
|
||||||
self.element.points_typed(points);
|
self.element.points_typed(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
self.rest.points(points);
|
|
||||||
self.element.points(points);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> {
|
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use super::*;
|
//! Previously part of [`crate::core`].
|
||||||
|
|
||||||
|
use super::{typeless::*, *};
|
||||||
|
|
||||||
type TypelessSerialize<'a> = dyn 'a + Fn(&mut dyn Serializer);
|
type TypelessSerialize<'a> = dyn 'a + Fn(&mut dyn Serializer);
|
||||||
|
|
||||||
/// See [`Mentionable::points`].
|
/// See [`Point::typeless`].
|
||||||
pub struct TypelessMentionable<'a, Ctx: 'a + Context> {
|
pub struct TypelessMentionable<'a, Ctx: 'a + Context> {
|
||||||
t_serialize: Box<TypelessSerialize<'a>>,
|
t_serialize: Box<TypelessSerialize<'a>>,
|
||||||
t_factory: TypelessFactory<'a, Ctx>,
|
t_factory: TypelessFactory<'a, Ctx>,
|
||||||
@ -33,7 +35,7 @@ trait Tut<'a, Ctx: 'a + Context>: 'a + Send + Sync {
|
|||||||
|
|
||||||
type TutBox<'a, Ctx> = Box<dyn Tut<'a, Ctx>>;
|
type TutBox<'a, Ctx> = Box<dyn Tut<'a, Ctx>>;
|
||||||
|
|
||||||
/// See [`Mentionable::points`]/[`TypelessMentionable`].
|
/// See [`Point::typeless`]/[`TypelessMentionable`].
|
||||||
pub struct TypelessFactory<'a, Ctx: 'a + Context> {
|
pub struct TypelessFactory<'a, Ctx: 'a + Context> {
|
||||||
t_deserialize: TdeBox<'a, Ctx>,
|
t_deserialize: TdeBox<'a, Ctx>,
|
||||||
t_unexpected_tail: TutBox<'a, Ctx>,
|
t_unexpected_tail: TutBox<'a, Ctx>,
|
||||||
@ -61,10 +63,6 @@ impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx
|
|||||||
points.take(point)
|
points.take(point)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
points.extend(self.t_points.iter().map(Clone::clone));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context> Clone for TypelessFactory<'a, Ctx> {
|
impl<'a, Ctx: 'a + Context> Clone for TypelessFactory<'a, Ctx> {
|
||||||
@ -76,7 +74,7 @@ impl<'a, Ctx: 'a + Context> Clone for TypelessFactory<'a, Ctx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`Mentionable::points`]/[`TypelessFactory`].
|
/// See [`Point::typeless`]/[`TypelessFactory`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TypelessError<'a>(Box<dyn 'a + Error>);
|
pub struct TypelessError<'a>(Box<dyn 'a + Error>);
|
||||||
|
|
||||||
@ -178,7 +176,7 @@ trait MentionableExt<'a, Ctx: 'a + Context>: Mentionable<'a, Ctx> {
|
|||||||
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
|
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
|
||||||
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> {
|
||||||
let mut points = Vec::new();
|
let mut points = Vec::new();
|
||||||
self.points(&mut points);
|
self.points_typeless(&mut points);
|
||||||
points
|
points
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -113,12 +113,6 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for St
|
|||||||
a.points_typed(points);
|
a.points_typed(points);
|
||||||
b.points_typed(points);
|
b.points_typed(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
let (a, b) = self.pair.elements();
|
|
||||||
a.points(points);
|
|
||||||
b.points(points);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> {
|
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> {
|
||||||
|
@ -47,13 +47,6 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nu
|
|||||||
Nullable::NotNull(point) => points.take(point),
|
Nullable::NotNull(point) => points.take(point),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
match self {
|
|
||||||
Nullable::Null(_) => {}
|
|
||||||
Nullable::NotNull(point) => points.push(point.typeless()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFactory<F> {
|
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFactory<F> {
|
||||||
|
@ -26,10 +26,6 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Po
|
|||||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) {
|
||||||
points.take(self)
|
points.take(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
|
||||||
points.push(self.typeless());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::std::cast::*;
|
use crate::std::{cast::*, ctypeless::*};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
|
|
||||||
use super::*;
|
use super::{ctypeless::*, *};
|
||||||
|
|
||||||
struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
|
struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
|
||||||
w_factory: A::Fctr,
|
w_factory: A::Fctr,
|
||||||
@ -89,7 +89,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for Wrapped
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
||||||
/// Typeless version of the point. Useful for [Mentionable::points] implementaion.
|
/// Typeless version of the point.
|
||||||
pub fn typeless(&self) -> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> {
|
pub fn typeless(&self) -> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> {
|
||||||
Point {
|
Point {
|
||||||
point: self.point,
|
point: self.point,
|
||||||
|
@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
|
|||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
use crate::std::cast::*;
|
use crate::std::cast::*;
|
||||||
|
use crate::std::ctypeless::*;
|
||||||
|
|
||||||
pub struct NoDiagnostic;
|
pub struct NoDiagnostic;
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ use std::cmp::max;
|
|||||||
|
|
||||||
use crate::core::*;
|
use crate::core::*;
|
||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
use crate::std::ctypeless::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user