get #[hdl] struct S<A: KnownSize, B: KnownSize> to work
All checks were successful
/ test (push) Successful in 39m2s

This commit is contained in:
Jacob Lifshay 2024-10-11 17:30:49 -07:00
parent 4909724995
commit d0229fbcfb
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c
3 changed files with 32 additions and 25 deletions

View file

@ -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 { pub fn new_static(element: T) -> Self {
Self::new(element, Len::SizeType::default()) Self::new(element, Len::SizeType::default())
} }

View file

@ -32,8 +32,23 @@ mod sealed {
pub const DYN_SIZE: usize = !0; pub const DYN_SIZE: usize = !0;
pub type DynSize = ConstUsize<DYN_SIZE>; 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; 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 { macro_rules! known_widths {
@ -44,6 +59,7 @@ macro_rules! known_widths {
v v
}> { }> {
const SIZE: Self = Self; const SIZE: Self = Self;
type ArrayMatch<Element: Type> = [Expr<Element>; Self::VALUE];
} }
}; };
([2 $($rest:tt)*] $($bits:literal)+) => { ([2 $($rest:tt)*] $($bits:literal)+) => {
@ -55,6 +71,7 @@ macro_rules! known_widths {
known_widths!([$($rest)*] 1); known_widths!([$($rest)*] 1);
impl KnownSize for ConstUsize<{2 $(* $rest)*}> { impl KnownSize for ConstUsize<{2 $(* $rest)*}> {
const SIZE: Self = Self; 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> sealed::SizeTypeSealed for ConstUsize<VALUE> {}
impl<const VALUE: usize> SizeType for ConstUsize<VALUE> impl<T: KnownSize> SizeType for T {
where type Size = T;
ConstUsize<VALUE>: KnownSize,
{
type Size = ConstUsize<VALUE>;
} }
impl<const VALUE: usize> Size for ConstUsize<VALUE> impl<T: KnownSize> Size for T {
where type ArrayMatch<Element: Type> = <T as KnownSize>::ArrayMatch<Element>;
ConstUsize<VALUE>: KnownSize,
{
type ArrayMatch<Element: Type> = [Expr<Element>; VALUE];
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 { fn as_usize(_size_type: Self::SizeType) -> usize {
VALUE T::VALUE
} }
fn try_from_usize(v: usize) -> Option<Self::SizeType> { fn try_from_usize(v: usize) -> Option<Self::SizeType> {
if v == VALUE { if v == T::VALUE {
Some(ConstUsize) Some(T::SIZE)
} else { } else {
None None
} }
@ -252,9 +263,7 @@ macro_rules! impl_int {
impl<Width: KnownSize> $name<Width> { impl<Width: KnownSize> $name<Width> {
pub fn new_static() -> Self { pub fn new_static() -> Self {
Self { Self { width: Width::SIZE }
width: Width::SizeType::default(),
}
} }
} }
@ -526,9 +535,9 @@ pub trait BoolOrIntType: Type + sealed::BoolOrIntTypeSealed {
fn new(width: <Self::Width as Size>::SizeType) -> Self; fn new(width: <Self::Width as Size>::SizeType) -> Self;
fn new_static() -> Self fn new_static() -> Self
where 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> { fn as_same_width_sint(self) -> SIntType<Self::Width> {
SIntType::new(Self::Width::from_usize(self.width())) SIntType::new(Self::Width::from_usize(self.width()))

View file

@ -1,11 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// See Notices.txt for copyright information // See Notices.txt for copyright information
use fayalite::prelude::*;
#[cfg(todo)]
use fayalite::{ use fayalite::{
bundle::BundleType, bundle::BundleType,
enum_::EnumType, enum_::EnumType,
int::{BoolOrIntType, IntType}, int::{BoolOrIntType, IntType},
prelude::*,
ty::StaticType, ty::StaticType,
}; };
use std::marker::PhantomData; use std::marker::PhantomData;
@ -121,7 +120,6 @@ mod bound_kind {
macro_rules! check_bounds { macro_rules! check_bounds {
($name:ident<$(#[$field:ident, $kind:ident] $var:ident: $($bound:ident +)*),*>) => { ($name:ident<$(#[$field:ident, $kind:ident] $var:ident: $($bound:ident +)*),*>) => {
#[cfg(todo)]
#[hdl(outline_generated)] #[hdl(outline_generated)]
struct $name<$($var: $($bound +)*,)*> { struct $name<$($var: $($bound +)*,)*> {
$($field: bound_kind::$kind<$var>,)* $($field: bound_kind::$kind<$var>,)*