stacknode inlining

This commit is contained in:
AF 2023-04-22 21:19:21 +00:00
parent c08e769b82
commit 770d3594e8
4 changed files with 59 additions and 28 deletions

View File

@ -11,6 +11,9 @@ pub struct Pair<A, B> {
pub b: B,
}
pub type PairObject<A, B> = StaticPairObject<Pair<A, B>>;
pub type PairFactory<'a, Ctx, A, B> = StaticPairFactory<'a, Ctx, Pair<A, B>>;
impl<A: Serializable, B: Serializable> StaticPairSerializable for Pair<A, B> {
type SA = A;
type SB = B;

View File

@ -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;
}

View File

@ -1,3 +1,5 @@
use std::ops::Deref;
use super::*;
use crate::core::*;
@ -36,6 +38,26 @@ pub struct StaticPairObject<SP> {
pair: SP,
}
impl<SP> From<SP> for StaticPairObject<SP> {
fn from(value: SP) -> Self {
StaticPairObject { pair: value }
}
}
impl<SP> AsRef<SP> for StaticPairObject<SP> {
fn as_ref(&self) -> &SP {
&self.pair
}
}
impl<SP> Deref for StaticPairObject<SP> {
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,
}

View File

@ -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>) -> A {
let factory = mentionable.factory();
TypelessMentionable::from_typed(mentionable)
.cast(factory)
.expect("cast failed")
}