diff --git a/src/std/collections/pair.rs b/src/std/collections/pair.rs index 64319a0..3127b68 100644 --- a/src/std/collections/pair.rs +++ b/src/std/collections/pair.rs @@ -11,6 +11,9 @@ pub struct Pair { pub b: B, } +pub type PairObject = StaticPairObject>; +pub type PairFactory<'a, Ctx, A, B> = StaticPairFactory<'a, Ctx, Pair>; + impl StaticPairSerializable for Pair { type SA = A; type SB = B; diff --git a/src/std/collections/stack.rs b/src/std/collections/stack.rs index 979f031..e3bf910 100644 --- a/src/std/collections/stack.rs +++ b/src/std/collections/stack.rs @@ -172,6 +172,31 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for St } } +impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> InlineableFactory + for StackNodeFactory<'a, Ctx, A> +where + A::Fctr: InlineableFactory, +{ +} + +impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> FixedSizeFactory + for StackNodeFactory<'a, Ctx, A> +where + A::Fctr: FixedSizeFactory, +{ + fn size(&self) -> usize { + Stack::<'a, Ctx, A>::SIZE + self.element_factory.size() + } +} + +impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ConstSizeFactory + for StackNodeFactory<'a, Ctx, A> +where + A::Fctr: ConstSizeFactory, +{ + const SIZE: usize = Stack::<'a, Ctx, A>::SIZE + A::Fctr::SIZE; +} + #[cfg(test)] mod tests { use super::*; @@ -214,37 +239,10 @@ mod tests { validate_stack(&stack); - let stack: T = TypelessMentionable::from_typed(stack.into()) - .cast(Stack::f(Plain::f())) - .expect("cast failed"); + let stack: T = reparse(stack.into()); validate_stack(&stack); Ok(()) } } - -impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> InlineableFactory - for StackNodeFactory<'a, Ctx, A> -where - A::Fctr: InlineableFactory, -{ -} - -impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> FixedSizeFactory - for StackNodeFactory<'a, Ctx, A> -where - A::Fctr: FixedSizeFactory, -{ - fn size(&self) -> usize { - Stack::<'a, Ctx, A>::SIZE + self.element_factory.size() - } -} - -impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ConstSizeFactory - for StackNodeFactory<'a, Ctx, A> -where - A::Fctr: ConstSizeFactory, -{ - const SIZE: usize = Stack::<'a, Ctx, A>::SIZE + A::Fctr::SIZE; -} diff --git a/src/std/inlining/static_pair.rs b/src/std/inlining/static_pair.rs index 6214147..cc93cc5 100644 --- a/src/std/inlining/static_pair.rs +++ b/src/std/inlining/static_pair.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use super::*; use crate::core::*; @@ -36,6 +38,26 @@ pub struct StaticPairObject { pair: SP, } +impl From for StaticPairObject { + fn from(value: SP) -> Self { + StaticPairObject { pair: value } + } +} + +impl AsRef for StaticPairObject { + fn as_ref(&self) -> &SP { + &self.pair + } +} + +impl Deref for StaticPairObject { + type Target = SP; + + fn deref(&self) -> &Self::Target { + &self.pair + } +} + pub struct StaticPairFactory<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> { factory_data: SP::FactoryData, } diff --git a/src/testing.rs b/src/testing.rs index 9139bb5..7028d30 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -1,5 +1,6 @@ use std::error::Error; use std::fmt::Display; +use std::rc::Rc; use crate::core::*; use crate::func::*; @@ -65,3 +66,10 @@ impl<'a> Resolver<'a, TestContext> for EmptyResolver { Err(TestLookupError::EmptyResolverAccess(address)) } } + +pub fn reparse<'a, A: Mentionable<'a, TestContext>>(mentionable: Rc) -> A { + let factory = mentionable.factory(); + TypelessMentionable::from_typed(mentionable) + .cast(factory) + .expect("cast failed") +}