forked from libre-chip/fayalite
		
	get #[hdl] struct S<A: KnownSize, B: KnownSize> to work
This commit is contained in:
		
							parent
							
								
									4909724995
								
							
						
					
					
						commit
						d0229fbcfb
					
				
					 3 changed files with 32 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -85,7 +85,7 @@ impl<T: Type, Len: Size> ArrayType<T, Len> {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: Type, Len: KnownSize> ArrayType<T, Len> {
 | 
			
		||||
impl<T: Type, Len: KnownSize + Size<SizeType = Len>> ArrayType<T, Len> {
 | 
			
		||||
    pub fn new_static(element: T) -> Self {
 | 
			
		||||
        Self::new(element, Len::SizeType::default())
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,8 +32,23 @@ mod sealed {
 | 
			
		|||
pub const DYN_SIZE: usize = !0;
 | 
			
		||||
pub type DynSize = ConstUsize<DYN_SIZE>;
 | 
			
		||||
 | 
			
		||||
pub trait KnownSize: GenericConstUsize + Size<SizeType = Self> {
 | 
			
		||||
pub trait KnownSize:
 | 
			
		||||
    GenericConstUsize + sealed::SizeTypeSealed + sealed::SizeSealed + Default
 | 
			
		||||
{
 | 
			
		||||
    const SIZE: Self;
 | 
			
		||||
    type ArrayMatch<Element: Type>: AsRef<[Expr<Element>]>
 | 
			
		||||
        + AsMut<[Expr<Element>]>
 | 
			
		||||
        + BorrowMut<[Expr<Element>]>
 | 
			
		||||
        + 'static
 | 
			
		||||
        + Send
 | 
			
		||||
        + Sync
 | 
			
		||||
        + Eq
 | 
			
		||||
        + Clone
 | 
			
		||||
        + std::hash::Hash
 | 
			
		||||
        + std::fmt::Debug
 | 
			
		||||
        + IntoIterator<Item = Expr<Element>>
 | 
			
		||||
        + TryFrom<Vec<Expr<Element>>>
 | 
			
		||||
        + Into<Vec<Expr<Element>>>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
macro_rules! known_widths {
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +59,7 @@ macro_rules! known_widths {
 | 
			
		|||
            v
 | 
			
		||||
        }> {
 | 
			
		||||
            const SIZE: Self = Self;
 | 
			
		||||
            type ArrayMatch<Element: Type> = [Expr<Element>; Self::VALUE];
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    ([2 $($rest:tt)*] $($bits:literal)+) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -55,6 +71,7 @@ macro_rules! known_widths {
 | 
			
		|||
        known_widths!([$($rest)*] 1);
 | 
			
		||||
        impl KnownSize for ConstUsize<{2 $(* $rest)*}> {
 | 
			
		||||
            const SIZE: Self = Self;
 | 
			
		||||
            type ArrayMatch<Element: Type> = [Expr<Element>; Self::VALUE];
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -124,30 +141,24 @@ impl<const VALUE: usize> sealed::SizeSealed for ConstUsize<VALUE> {}
 | 
			
		|||
 | 
			
		||||
impl<const VALUE: usize> sealed::SizeTypeSealed for ConstUsize<VALUE> {}
 | 
			
		||||
 | 
			
		||||
impl<const VALUE: usize> SizeType for ConstUsize<VALUE>
 | 
			
		||||
where
 | 
			
		||||
    ConstUsize<VALUE>: KnownSize,
 | 
			
		||||
{
 | 
			
		||||
    type Size = ConstUsize<VALUE>;
 | 
			
		||||
impl<T: KnownSize> SizeType for T {
 | 
			
		||||
    type Size = T;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<const VALUE: usize> Size for ConstUsize<VALUE>
 | 
			
		||||
where
 | 
			
		||||
    ConstUsize<VALUE>: KnownSize,
 | 
			
		||||
{
 | 
			
		||||
    type ArrayMatch<Element: Type> = [Expr<Element>; VALUE];
 | 
			
		||||
impl<T: KnownSize> Size for T {
 | 
			
		||||
    type ArrayMatch<Element: Type> = <T as KnownSize>::ArrayMatch<Element>;
 | 
			
		||||
 | 
			
		||||
    const KNOWN_VALUE: Option<usize> = Some(VALUE);
 | 
			
		||||
    const KNOWN_VALUE: Option<usize> = Some(T::VALUE);
 | 
			
		||||
 | 
			
		||||
    type SizeType = ConstUsize<VALUE>;
 | 
			
		||||
    type SizeType = T;
 | 
			
		||||
 | 
			
		||||
    fn as_usize(_size_type: Self::SizeType) -> usize {
 | 
			
		||||
        VALUE
 | 
			
		||||
        T::VALUE
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn try_from_usize(v: usize) -> Option<Self::SizeType> {
 | 
			
		||||
        if v == VALUE {
 | 
			
		||||
            Some(ConstUsize)
 | 
			
		||||
        if v == T::VALUE {
 | 
			
		||||
            Some(T::SIZE)
 | 
			
		||||
        } else {
 | 
			
		||||
            None
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -252,9 +263,7 @@ macro_rules! impl_int {
 | 
			
		|||
 | 
			
		||||
        impl<Width: KnownSize> $name<Width> {
 | 
			
		||||
            pub fn new_static() -> Self {
 | 
			
		||||
                Self {
 | 
			
		||||
                    width: Width::SizeType::default(),
 | 
			
		||||
                }
 | 
			
		||||
                Self { width: Width::SIZE }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -526,9 +535,9 @@ pub trait BoolOrIntType: Type + sealed::BoolOrIntTypeSealed {
 | 
			
		|||
    fn new(width: <Self::Width as Size>::SizeType) -> Self;
 | 
			
		||||
    fn new_static() -> Self
 | 
			
		||||
    where
 | 
			
		||||
        Self::Width: KnownSize,
 | 
			
		||||
        Self::Width: KnownSize + Size<SizeType = Self::Width>,
 | 
			
		||||
    {
 | 
			
		||||
        Self::new(<Self::Width as Size>::SizeType::default())
 | 
			
		||||
        Self::new(Self::Width::default())
 | 
			
		||||
    }
 | 
			
		||||
    fn as_same_width_sint(self) -> SIntType<Self::Width> {
 | 
			
		||||
        SIntType::new(Self::Width::from_usize(self.width()))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,10 @@
 | 
			
		|||
// SPDX-License-Identifier: LGPL-3.0-or-later
 | 
			
		||||
// See Notices.txt for copyright information
 | 
			
		||||
use fayalite::prelude::*;
 | 
			
		||||
#[cfg(todo)]
 | 
			
		||||
use fayalite::{
 | 
			
		||||
    bundle::BundleType,
 | 
			
		||||
    enum_::EnumType,
 | 
			
		||||
    int::{BoolOrIntType, IntType},
 | 
			
		||||
    prelude::*,
 | 
			
		||||
    ty::StaticType,
 | 
			
		||||
};
 | 
			
		||||
use std::marker::PhantomData;
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +120,6 @@ mod bound_kind {
 | 
			
		|||
 | 
			
		||||
macro_rules! check_bounds {
 | 
			
		||||
    ($name:ident<$(#[$field:ident, $kind:ident] $var:ident: $($bound:ident +)*),*>) => {
 | 
			
		||||
        #[cfg(todo)]
 | 
			
		||||
        #[hdl(outline_generated)]
 | 
			
		||||
        struct $name<$($var: $($bound +)*,)*> {
 | 
			
		||||
            $($field: bound_kind::$kind<$var>,)*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue