Compare commits

..

3 commits

23 changed files with 191 additions and 198 deletions

8
Cargo.lock generated
View file

@ -239,7 +239,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]] [[package]]
name = "fayalite" name = "fayalite"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"clap", "clap",
@ -257,14 +257,14 @@ dependencies = [
[[package]] [[package]]
name = "fayalite-proc-macros" name = "fayalite-proc-macros"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"fayalite-proc-macros-impl", "fayalite-proc-macros-impl",
] ]
[[package]] [[package]]
name = "fayalite-proc-macros-impl" name = "fayalite-proc-macros-impl"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"base16ct", "base16ct",
"num-bigint", "num-bigint",
@ -278,7 +278,7 @@ dependencies = [
[[package]] [[package]]
name = "fayalite-visit-gen" name = "fayalite-visit-gen"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"prettyplease", "prettyplease",

View file

@ -5,7 +5,7 @@ resolver = "2"
members = ["crates/*"] members = ["crates/*"]
[workspace.package] [workspace.package]
version = "0.1.0" version = "0.2.0"
license = "LGPL-3.0-or-later" license = "LGPL-3.0-or-later"
edition = "2021" edition = "2021"
repository = "https://git.libre-chip.org/libre-chip/fayalite" repository = "https://git.libre-chip.org/libre-chip/fayalite"
@ -14,9 +14,9 @@ categories = ["simulation", "development-tools", "compilers"]
rust-version = "1.79" rust-version = "1.79"
[workspace.dependencies] [workspace.dependencies]
fayalite-proc-macros = { version = "=0.1.0", path = "crates/fayalite-proc-macros" } fayalite-proc-macros = { version = "=0.2.0", path = "crates/fayalite-proc-macros" }
fayalite-proc-macros-impl = { version = "=0.1.0", path = "crates/fayalite-proc-macros-impl" } fayalite-proc-macros-impl = { version = "=0.2.0", path = "crates/fayalite-proc-macros-impl" }
fayalite-visit-gen = { version = "=0.1.0", path = "crates/fayalite-visit-gen" } fayalite-visit-gen = { version = "=0.2.0", path = "crates/fayalite-visit-gen" }
base16ct = "0.2.0" base16ct = "0.2.0"
bitvec = { version = "1.0.1", features = ["serde"] } bitvec = { version = "1.0.1", features = ["serde"] }
hashbrown = "0.14.3" hashbrown = "0.14.3"

View file

@ -248,5 +248,6 @@ no_op_fold!(syn::Token![enum]);
no_op_fold!(syn::Token![extern]); no_op_fold!(syn::Token![extern]);
no_op_fold!(syn::Token![let]); no_op_fold!(syn::Token![let]);
no_op_fold!(syn::Token![mut]); no_op_fold!(syn::Token![mut]);
no_op_fold!(syn::Token![static]);
no_op_fold!(syn::Token![struct]); no_op_fold!(syn::Token![struct]);
no_op_fold!(syn::Token![where]); no_op_fold!(syn::Token![where]);

View file

@ -20,7 +20,7 @@ mod value_derive_struct;
mod kw { mod kw {
pub(crate) use syn::token::{ pub(crate) use syn::token::{
Enum as enum_, Extern as extern_, Struct as struct_, Where as where_, Enum as enum_, Extern as extern_, Static as static_, Struct as struct_, Where as where_,
}; };
macro_rules! custom_keyword { macro_rules! custom_keyword {
@ -43,7 +43,6 @@ mod kw {
custom_keyword!(clock_domain); custom_keyword!(clock_domain);
custom_keyword!(connect_inexact); custom_keyword!(connect_inexact);
custom_keyword!(fixed_type);
custom_keyword!(flip); custom_keyword!(flip);
custom_keyword!(hdl); custom_keyword!(hdl);
custom_keyword!(input); custom_keyword!(input);

View file

@ -312,9 +312,9 @@ impl ModuleFn {
#body_fn #body_fn
::fayalite::module::ModuleBuilder::run(#fn_name_str, |m| __body #body_turbofish_type_generics(m, #(#param_names,)*)) ::fayalite::module::ModuleBuilder::run(#fn_name_str, |m| __body #body_turbofish_type_generics(m, #(#param_names,)*))
}}; }};
let fixed_type = io.iter().all(|io| io.kind.ty_expr.is_none()); let static_type = io.iter().all(|io| io.kind.ty_expr.is_none());
let struct_options = if fixed_type { let struct_options = if static_type {
quote! { #[hdl(fixed_type)] } quote! { #[hdl(static)] }
} else { } else {
quote! {} quote! {}
}; };

View file

@ -1003,10 +1003,10 @@ fn wrap_ty_with_expr(ty: impl ToTokens) -> Type {
} }
} }
fn unwrap_or_fixed_type(expr: Option<impl ToTokens>, span: Span) -> TokenStream { fn unwrap_or_static_type(expr: Option<impl ToTokens>, span: Span) -> TokenStream {
expr.map(ToTokens::into_token_stream).unwrap_or_else(|| { expr.map(ToTokens::into_token_stream).unwrap_or_else(|| {
quote_spanned! {span=> quote_spanned! {span=>
::fayalite::ty::FixedType::fixed_type() ::fayalite::ty::StaticType::static_type()
} }
}) })
} }
@ -1109,7 +1109,7 @@ impl Visitor {
let m = hdl_let.kind.m; let m = hdl_let.kind.m;
let dot = hdl_let.kind.dot_token; let dot = hdl_let.kind.dot_token;
let kind = hdl_let.kind.kind; let kind = hdl_let.kind.kind;
let ty_expr = unwrap_or_fixed_type(hdl_let.kind.ty_expr.as_ref(), kind.span()); let ty_expr = unwrap_or_static_type(hdl_let.kind.ty_expr.as_ref(), kind.span());
let mut expr = quote! {#m #dot #kind}; let mut expr = quote! {#m #dot #kind};
hdl_let.kind.paren.surround(&mut expr, |expr| { hdl_let.kind.paren.surround(&mut expr, |expr| {
let name_str = ImplicitName { let name_str = ImplicitName {
@ -1214,7 +1214,7 @@ impl Visitor {
paren, paren,
ty_expr, ty_expr,
} => { } => {
let ty_expr = unwrap_or_fixed_type(ty_expr.as_ref(), reg_builder.span()); let ty_expr = unwrap_or_static_type(ty_expr.as_ref(), reg_builder.span());
dot_token.to_tokens(&mut expr); dot_token.to_tokens(&mut expr);
no_reset.to_tokens(&mut expr); no_reset.to_tokens(&mut expr);
paren.surround(&mut expr, |expr| ty_expr.to_tokens(expr)); paren.surround(&mut expr, |expr| ty_expr.to_tokens(expr));
@ -1248,7 +1248,7 @@ impl Visitor {
let dot = hdl_let.kind.dot_token; let dot = hdl_let.kind.dot_token;
let wire = hdl_let.kind.wire; let wire = hdl_let.kind.wire;
self.require_normal_module(wire); self.require_normal_module(wire);
let ty_expr = unwrap_or_fixed_type(hdl_let.kind.ty_expr.as_ref(), wire.span()); let ty_expr = unwrap_or_static_type(hdl_let.kind.ty_expr.as_ref(), wire.span());
let mut expr = quote! {#m #dot #wire}; let mut expr = quote! {#m #dot #wire};
hdl_let.kind.paren.surround(&mut expr, |expr| { hdl_let.kind.paren.surround(&mut expr, |expr| {
let name_str = ImplicitName { let name_str = ImplicitName {
@ -1290,14 +1290,14 @@ impl Visitor {
memory, memory,
paren, paren,
ty_expr, ty_expr,
} => (paren, unwrap_or_fixed_type(ty_expr.as_ref(), memory.span())), } => (paren, unwrap_or_static_type(ty_expr.as_ref(), memory.span())),
MemoryFn::MemoryArray { MemoryFn::MemoryArray {
memory_array, memory_array,
paren, paren,
ty_expr, ty_expr,
} => ( } => (
paren, paren,
unwrap_or_fixed_type(ty_expr.as_ref(), memory_array.span()), unwrap_or_static_type(ty_expr.as_ref(), memory_array.span()),
), ),
MemoryFn::MemoryWithInit { MemoryFn::MemoryWithInit {
memory_with_init: _, memory_with_init: _,

View file

@ -167,46 +167,33 @@ pub(crate) fn get_target(target: &Option<(kw::target, Paren, Path)>, item_ident:
pub(crate) struct ValueDeriveGenerics { pub(crate) struct ValueDeriveGenerics {
pub(crate) generics: Generics, pub(crate) generics: Generics,
pub(crate) fixed_type_generics: Generics, pub(crate) static_type_generics: Generics,
} }
impl ValueDeriveGenerics { impl ValueDeriveGenerics {
pub(crate) fn get(mut generics: Generics, where_: &Option<(Where, Paren, Bounds)>) -> Self { pub(crate) fn get(mut generics: Generics, where_: &Option<(Where, Paren, Bounds)>) -> Self {
let mut fixed_type_generics = generics.clone(); let mut static_type_generics = generics.clone();
if let Some((_, _, bounds)) = where_ { if let Some((_, _, bounds)) = where_ {
generics generics
.make_where_clause() .make_where_clause()
.predicates .predicates
.extend(bounds.0.iter().cloned()); .extend(bounds.0.iter().cloned());
fixed_type_generics static_type_generics
.where_clause .where_clause
.clone_from(&generics.where_clause); .clone_from(&generics.where_clause);
} else { } else {
let type_params = Vec::from_iter(generics.type_params().map(|v| v.ident.clone())); let type_params = Vec::from_iter(generics.type_params().map(|v| v.ident.clone()));
let predicates = &mut generics.make_where_clause().predicates; let predicates = &mut generics.make_where_clause().predicates;
let fixed_type_predicates = &mut fixed_type_generics.make_where_clause().predicates; let static_type_predicates = &mut static_type_generics.make_where_clause().predicates;
for type_param in type_params { for type_param in type_params {
predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value}); predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value<Type: ::fayalite::ty::Type<Value = #type_param>>});
predicates.push(parse_quote! { static_type_predicates
<#type_param as ::fayalite::expr::ToExpr>::Type: .push(parse_quote! {#type_param: ::fayalite::ty::StaticValue});
::fayalite::ty::Type<Value = #type_param>
});
fixed_type_predicates.push(parse_quote! {#type_param: ::fayalite::ty::Value});
fixed_type_predicates.push(parse_quote! {
<#type_param as ::fayalite::expr::ToExpr>::Type:
::fayalite::ty::FixedType<Value = #type_param>
});
fixed_type_predicates.push(parse_quote! {
<
<#type_param as ::fayalite::expr::ToExpr>::Type
as ::fayalite::ty::Type
>::MaskType: ::fayalite::ty::FixedType
});
} }
} }
Self { Self {
generics, generics,
fixed_type_generics, static_type_generics,
} }
} }
} }

View file

@ -152,7 +152,7 @@ impl ParsedVariant {
parsed_struct: ParsedStruct { parsed_struct: ParsedStruct {
options: StructOptions { options: StructOptions {
outline_generated: None, outline_generated: None,
fixed_type: Some(Default::default()), static_: Some(Default::default()),
where_: Some(( where_: Some((
Default::default(), Default::default(),
Default::default(), Default::default(),
@ -160,7 +160,7 @@ impl ParsedVariant {
enum_generics.clone(), enum_generics.clone(),
&enum_options.where_, &enum_options.where_,
) )
.fixed_type_generics .static_type_generics
.where_clause .where_clause
.into(), .into(),
)), )),
@ -275,10 +275,10 @@ impl ToTokens for ParsedEnum {
let target = get_target(target, enum_ident); let target = get_target(target, enum_ident);
let ValueDeriveGenerics { let ValueDeriveGenerics {
generics: _, generics: _,
fixed_type_generics, static_type_generics,
} = ValueDeriveGenerics::get(enum_generics.clone(), where_); } = ValueDeriveGenerics::get(enum_generics.clone(), where_);
let (fixed_type_impl_generics, fixed_type_type_generics, fixed_type_where_clause) = let (static_type_impl_generics, static_type_type_generics, static_type_where_clause) =
fixed_type_generics.split_for_impl(); static_type_generics.split_for_impl();
let type_struct_ident = format_ident!("__{}__Type", enum_ident); let type_struct_ident = format_ident!("__{}__Type", enum_ident);
let mut field_checks = vec![]; let mut field_checks = vec![];
let mut make_type_struct_variant_type = |variant: &ParsedVariant| { let mut make_type_struct_variant_type = |variant: &ParsedVariant| {
@ -303,7 +303,7 @@ impl ToTokens for ParsedEnum {
let mut field_names = Vec::from_iter(get_field_names(&value_struct.fields)); let mut field_names = Vec::from_iter(get_field_names(&value_struct.fields));
derive_clone_hash_eq_partialeq_for_struct( derive_clone_hash_eq_partialeq_for_struct(
&value_struct.ident, &value_struct.ident,
&fixed_type_generics, &static_type_generics,
&field_names, &field_names,
) )
.to_tokens(tokens); .to_tokens(tokens);
@ -334,9 +334,9 @@ impl ToTokens for ParsedEnum {
let value_struct_ident = &value_struct.ident; let value_struct_ident = &value_struct.ident;
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug impl #static_type_impl_generics ::fayalite::__std::fmt::Debug
for #value_struct_ident #fixed_type_type_generics for #value_struct_ident #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
fn fmt( fn fmt(
&self, &self,
@ -349,7 +349,7 @@ impl ToTokens for ParsedEnum {
.to_tokens(tokens); .to_tokens(tokens);
Some(parse_quote! { Some(parse_quote! {
< <
#value_struct_ident #fixed_type_type_generics #value_struct_ident #static_type_type_generics
as ::fayalite::expr::ToExpr as ::fayalite::expr::ToExpr
>::Type >::Type
}) })
@ -373,7 +373,7 @@ impl ToTokens for ParsedEnum {
vis: vis.clone(), vis: vis.clone(),
struct_token: Token![struct](enum_token.span), struct_token: Token![struct](enum_token.span),
ident: type_struct_ident, ident: type_struct_ident,
generics: fixed_type_generics.clone(), generics: static_type_generics.clone(),
fields: Fields::Named(FieldsNamed { fields: Fields::Named(FieldsNamed {
brace_token: *brace_token, brace_token: *brace_token,
named: type_struct_variants, named: type_struct_variants,
@ -398,7 +398,7 @@ impl ToTokens for ParsedEnum {
}; };
derive_clone_hash_eq_partialeq_for_struct( derive_clone_hash_eq_partialeq_for_struct(
type_struct_ident, type_struct_ident,
&fixed_type_generics, &static_type_generics,
&non_empty_variant_names, &non_empty_variant_names,
) )
.to_tokens(tokens); .to_tokens(tokens);
@ -432,7 +432,7 @@ impl ToTokens for ParsedEnum {
.last() .last()
.expect("missing phantom field") .expect("missing phantom field")
.name; .name;
let type_generics = fixed_type_type_generics.as_turbofish(); let type_generics = static_type_type_generics.as_turbofish();
quote! { quote! {
::fayalite::__std::option::Option::Some( ::fayalite::__std::option::Option::Some(
::fayalite::ty::DynValueTrait::to_canonical_dyn( ::fayalite::ty::DynValueTrait::to_canonical_dyn(
@ -628,7 +628,7 @@ impl ToTokens for ParsedEnum {
#variant_index => { #variant_index => {
let __variant_access = ::fayalite::expr::ToExpr::to_expr( let __variant_access = ::fayalite::expr::ToExpr::to_expr(
&__variant_access.downcast_unchecked::<< &__variant_access.downcast_unchecked::<<
#ident #fixed_type_type_generics #ident #static_type_type_generics
as ::fayalite::expr::ToExpr as ::fayalite::expr::ToExpr
>::Type>(), >::Type>(),
); );
@ -660,11 +660,11 @@ impl ToTokens for ParsedEnum {
{ {
::fayalite::expr::ToExpr::to_expr( ::fayalite::expr::ToExpr::to_expr(
&::fayalite::expr::ops::EnumLiteral::< &::fayalite::expr::ops::EnumLiteral::<
#type_struct_ident #fixed_type_type_generics #type_struct_ident #static_type_type_generics
>::new_unchecked( >::new_unchecked(
::fayalite::__std::option::Option::None, ::fayalite::__std::option::Option::None,
#variant_index, #variant_index,
::fayalite::ty::FixedType::fixed_type(), ::fayalite::ty::StaticType::static_type(),
), ),
) )
} }
@ -673,13 +673,13 @@ impl ToTokens for ParsedEnum {
{ {
::fayalite::expr::ToExpr::to_expr( ::fayalite::expr::ToExpr::to_expr(
&::fayalite::expr::ops::EnumLiteral::< &::fayalite::expr::ops::EnumLiteral::<
#type_struct_ident #fixed_type_type_generics #type_struct_ident #static_type_type_generics
>::new_unchecked( >::new_unchecked(
::fayalite::__std::option::Option::Some( ::fayalite::__std::option::Option::Some(
#(#builder_field_vars)*.to_canonical_dyn(), #(#builder_field_vars)*.to_canonical_dyn(),
), ),
#variant_index, #variant_index,
::fayalite::ty::FixedType::fixed_type(), ::fayalite::ty::StaticType::static_type(),
), ),
) )
} }
@ -698,19 +698,19 @@ impl ToTokens for ParsedEnum {
} => parse_quote! { } => parse_quote! {
{ {
let __builder = < let __builder = <
#field_type_struct_ident #fixed_type_type_generics #field_type_struct_ident #static_type_type_generics
as ::fayalite::bundle::BundleType as ::fayalite::bundle::BundleType
>::builder(); >::builder();
#(let __builder = __builder.#builder_field_vars(#builder_field_vars);)* #(let __builder = __builder.#builder_field_vars(#builder_field_vars);)*
::fayalite::expr::ToExpr::to_expr( ::fayalite::expr::ToExpr::to_expr(
&::fayalite::expr::ops::EnumLiteral::< &::fayalite::expr::ops::EnumLiteral::<
#type_struct_ident #fixed_type_type_generics #type_struct_ident #static_type_type_generics
>::new_unchecked( >::new_unchecked(
::fayalite::__std::option::Option::Some( ::fayalite::__std::option::Option::Some(
__builder.build().to_canonical_dyn(), __builder.build().to_canonical_dyn(),
), ),
#variant_index, #variant_index,
::fayalite::ty::FixedType::fixed_type(), ::fayalite::ty::StaticType::static_type(),
), ),
) )
} }
@ -730,9 +730,9 @@ impl ToTokens for ParsedEnum {
(name.clone(), parse_quote! { ::fayalite::expr::Expr<#ty> }) (name.clone(), parse_quote! { ::fayalite::expr::Expr<#ty> })
}, },
), ),
&fixed_type_generics, &static_type_generics,
&parse_quote! {#type_struct_ident #fixed_type_type_generics}, &parse_quote! {#type_struct_ident #static_type_type_generics},
&parse_quote! { ::fayalite::expr::Expr<#target #fixed_type_type_generics> }, &parse_quote! { ::fayalite::expr::Expr<#target #static_type_type_generics> },
build_body, build_body,
) )
.to_tokens(tokens); .to_tokens(tokens);
@ -742,7 +742,7 @@ impl ToTokens for ParsedEnum {
vis: vis.clone(), vis: vis.clone(),
enum_token: *enum_token, enum_token: *enum_token,
ident: match_enum_ident, ident: match_enum_ident,
generics: fixed_type_generics.clone(), generics: static_type_generics.clone(),
brace_token: *brace_token, brace_token: *brace_token,
variants: match_enum_variants, variants: match_enum_variants,
}; };
@ -750,7 +750,7 @@ impl ToTokens for ParsedEnum {
match_enum.to_tokens(tokens); match_enum.to_tokens(tokens);
make_connect_impl( make_connect_impl(
*connect_inexact, *connect_inexact,
&fixed_type_generics, &static_type_generics,
type_struct_ident, type_struct_ident,
variants.iter().flat_map(|variant| { variants.iter().flat_map(|variant| {
variant.fields.iter().map(|field| { variant.fields.iter().map(|field| {
@ -766,9 +766,9 @@ impl ToTokens for ParsedEnum {
let empty_builder_ty = builder.ty([], Some(&parse_quote! { Self }), false); let empty_builder_ty = builder.ty([], Some(&parse_quote! { Self }), false);
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug impl #static_type_impl_generics ::fayalite::__std::fmt::Debug
for #match_enum_ident #fixed_type_type_generics for #match_enum_ident #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
fn fmt( fn fmt(
&self, &self,
@ -781,13 +781,13 @@ impl ToTokens for ParsedEnum {
} }
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::ty::FixedType impl #static_type_impl_generics ::fayalite::ty::StaticType
for #type_struct_ident #fixed_type_type_generics for #type_struct_ident #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
fn fixed_type() -> Self { fn static_type() -> Self {
Self { Self {
#(#non_empty_variant_names: ::fayalite::ty::FixedType::fixed_type(),)* #(#non_empty_variant_names: ::fayalite::ty::StaticType::static_type(),)*
} }
} }
} }
@ -796,16 +796,16 @@ impl ToTokens for ParsedEnum {
where where
<T as ::fayalite::expr::ToExpr>::Type: ::fayalite::ty::Type<Value = T>, <T as ::fayalite::expr::ToExpr>::Type: ::fayalite::ty::Type<Value = T>,
{} {}
fn __check_fields #fixed_type_impl_generics(_: #target #fixed_type_type_generics) fn __check_fields #static_type_impl_generics(_: #target #static_type_type_generics)
#fixed_type_where_clause #static_type_where_clause
{ {
#(#field_checks)* #(#field_checks)*
} }
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::__std::fmt::Debug impl #static_type_impl_generics ::fayalite::__std::fmt::Debug
for #type_struct_ident #fixed_type_type_generics for #type_struct_ident #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
fn fmt( fn fmt(
&self, &self,
@ -816,16 +816,16 @@ impl ToTokens for ParsedEnum {
} }
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::ty::Type impl #static_type_impl_generics ::fayalite::ty::Type
for #type_struct_ident #fixed_type_type_generics for #type_struct_ident #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
type CanonicalType = ::fayalite::enum_::DynEnumType; type CanonicalType = ::fayalite::enum_::DynEnumType;
type Value = #target #fixed_type_type_generics; type Value = #target #static_type_type_generics;
type CanonicalValue = ::fayalite::enum_::DynEnum; type CanonicalValue = ::fayalite::enum_::DynEnum;
type MaskType = ::fayalite::int::UIntType<1>; type MaskType = ::fayalite::int::UIntType<1>;
type MaskValue = ::fayalite::int::UInt<1>; type MaskValue = ::fayalite::int::UInt<1>;
type MatchVariant = #match_enum_ident #fixed_type_type_generics; type MatchVariant = #match_enum_ident #static_type_type_generics;
type MatchActiveScope = ::fayalite::module::Scope; type MatchActiveScope = ::fayalite::module::Scope;
type MatchVariantAndInactiveScope = type MatchVariantAndInactiveScope =
::fayalite::enum_::EnumMatchVariantAndInactiveScope<Self>; ::fayalite::enum_::EnumMatchVariantAndInactiveScope<Self>;
@ -871,9 +871,9 @@ impl ToTokens for ParsedEnum {
#[automatically_derived] #[automatically_derived]
#[allow(clippy::init_numbered_fields)] #[allow(clippy::init_numbered_fields)]
impl #fixed_type_impl_generics ::fayalite::enum_::EnumType impl #static_type_impl_generics ::fayalite::enum_::EnumType
for #type_struct_ident #fixed_type_type_generics for #type_struct_ident #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
type Builder = #empty_builder_ty; type Builder = #empty_builder_ty;
fn match_activate_scope( fn match_activate_scope(
@ -907,13 +907,13 @@ impl ToTokens for ParsedEnum {
} }
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::expr::ToExpr impl #static_type_impl_generics ::fayalite::expr::ToExpr
for #target #fixed_type_type_generics for #target #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
type Type = #type_struct_ident #fixed_type_type_generics; type Type = #type_struct_ident #static_type_type_generics;
fn ty(&self) -> <Self as ::fayalite::expr::ToExpr>::Type { fn ty(&self) -> <Self as ::fayalite::expr::ToExpr>::Type {
::fayalite::ty::FixedType::fixed_type() ::fayalite::ty::StaticType::static_type()
} }
fn to_expr(&self) -> ::fayalite::expr::Expr<Self> { fn to_expr(&self) -> ::fayalite::expr::Expr<Self> {
::fayalite::expr::Expr::from_value(self) ::fayalite::expr::Expr::from_value(self)
@ -921,9 +921,9 @@ impl ToTokens for ParsedEnum {
} }
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::ty::Value impl #static_type_impl_generics ::fayalite::ty::Value
for #target #fixed_type_type_generics for #target #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
fn to_canonical(&self) -> < fn to_canonical(&self) -> <
<Self as ::fayalite::expr::ToExpr>::Type <Self as ::fayalite::expr::ToExpr>::Type
@ -944,9 +944,9 @@ impl ToTokens for ParsedEnum {
} }
#[automatically_derived] #[automatically_derived]
impl #fixed_type_impl_generics ::fayalite::enum_::EnumValue impl #static_type_impl_generics ::fayalite::enum_::EnumValue
for #target #fixed_type_type_generics for #target #static_type_type_generics
#fixed_type_where_clause #static_type_where_clause
{ {
} }
} }

View file

@ -18,7 +18,7 @@ crate::options! {
#[options = StructOptions] #[options = StructOptions]
pub(crate) enum StructOption { pub(crate) enum StructOption {
OutlineGenerated(outline_generated), OutlineGenerated(outline_generated),
FixedType(fixed_type), Static(static_),
ConnectInexact(connect_inexact), ConnectInexact(connect_inexact),
Bounds(where_, Bounds), Bounds(where_, Bounds),
Target(target, Path), Target(target, Path),
@ -136,12 +136,12 @@ impl ParsedStruct {
outline_generated: _, outline_generated: _,
where_, where_,
target: _, target: _,
fixed_type, static_,
connect_inexact, connect_inexact,
} = &options.body; } = &options.body;
let ValueDeriveGenerics { let ValueDeriveGenerics {
generics, generics,
fixed_type_generics, static_type_generics,
} = ValueDeriveGenerics::get(generics.clone(), where_); } = ValueDeriveGenerics::get(generics.clone(), where_);
let (impl_generics, type_generics, where_clause) = generics.split_for_impl(); let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
let unskipped_fields = fields let unskipped_fields = fields
@ -373,16 +373,17 @@ impl ParsedStruct {
__check_field(#check_v.#name); __check_field(#check_v.#name);
} }
})); }));
if fixed_type.is_some() { if static_.is_some() {
let (impl_generics, type_generics, where_clause) = fixed_type_generics.split_for_impl(); let (impl_generics, type_generics, where_clause) =
static_type_generics.split_for_impl();
quote! { quote! {
#[automatically_derived] #[automatically_derived]
impl #impl_generics ::fayalite::ty::FixedType for #type_struct_ident #type_generics impl #impl_generics ::fayalite::ty::StaticType for #type_struct_ident #type_generics
#where_clause #where_clause
{ {
fn fixed_type() -> Self { fn static_type() -> Self {
Self { Self {
#(#unskipped_field_names: ::fayalite::ty::FixedType::fixed_type(),)* #(#unskipped_field_names: ::fayalite::ty::StaticType::static_type(),)*
#(#phantom_data_field_name_slice: #(#phantom_data_field_name_slice:
::fayalite::__std::marker::PhantomData,)* ::fayalite::__std::marker::PhantomData,)*
} }

View file

@ -11,7 +11,7 @@
//! ``` //! ```
//! # use fayalite::{hdl_module, int::UInt, array::Array, ty::Value}; //! # use fayalite::{hdl_module, int::UInt, array::Array, ty::Value};
//! #[derive(Value, Clone, PartialEq, Eq, Hash, Debug)] //! #[derive(Value, Clone, PartialEq, Eq, Hash, Debug)]
//! #[hdl(fixed_type)] //! #[hdl(static)]
//! pub struct MyStruct { //! pub struct MyStruct {
//! pub a: UInt<8>, //! pub a: UInt<8>,
//! pub b: UInt<16>, //! pub b: UInt<16>,

View file

@ -14,8 +14,8 @@ use crate::{
source_location::SourceLocation, source_location::SourceLocation,
ty::{ ty::{
CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType,
DynCanonicalValue, DynType, DynValueTrait, FixedType, MatchVariantWithoutScope, Type, DynCanonicalValue, DynType, DynValueTrait, MatchVariantWithoutScope, StaticType,
TypeEnum, Value, ValueEnum, StaticValue, Type, TypeEnum, Value, ValueEnum,
}, },
util::{ConstBool, GenericConstBool, MakeMutSlice}, util::{ConstBool, GenericConstBool, MakeMutSlice},
}; };
@ -66,7 +66,7 @@ pub trait ValueArrayOrSlice:
LenType = Self::LenType, LenType = Self::LenType,
MaskVA = Self::MaskVA, MaskVA = Self::MaskVA,
> + ?Sized; > + ?Sized;
type IsFixedLen: GenericConstBool; type IsStaticLen: GenericConstBool;
const FIXED_LEN_TYPE: Option<Self::LenType>; const FIXED_LEN_TYPE: Option<Self::LenType>;
fn make_match(array: Expr<Array<Self>>) -> Self::Match; fn make_match(array: Expr<Array<Self>>) -> Self::Match;
fn len_from_len_type(v: Self::LenType) -> usize; fn len_from_len_type(v: Self::LenType) -> usize;
@ -94,7 +94,7 @@ where
type LenType = usize; type LenType = usize;
type Match = Box<[Expr<V>]>; type Match = Box<[Expr<V>]>;
type MaskVA = [<Self::ElementType as Type>::MaskValue]; type MaskVA = [<Self::ElementType as Type>::MaskValue];
type IsFixedLen = ConstBool<false>; type IsStaticLen = ConstBool<false>;
const FIXED_LEN_TYPE: Option<Self::LenType> = None; const FIXED_LEN_TYPE: Option<Self::LenType> = None;
fn make_match(array: Expr<Array<Self>>) -> Self::Match { fn make_match(array: Expr<Array<Self>>) -> Self::Match {
@ -147,7 +147,7 @@ where
type LenType = (); type LenType = ();
type Match = [Expr<V>; N]; type Match = [Expr<V>; N];
type MaskVA = [<Self::ElementType as Type>::MaskValue; N]; type MaskVA = [<Self::ElementType as Type>::MaskValue; N];
type IsFixedLen = ConstBool<true>; type IsStaticLen = ConstBool<true>;
const FIXED_LEN_TYPE: Option<Self::LenType> = Some(()); const FIXED_LEN_TYPE: Option<Self::LenType> = Some(());
fn make_match(array: Expr<Array<Self>>) -> Self::Match { fn make_match(array: Expr<Array<Self>>) -> Self::Match {
@ -302,28 +302,19 @@ where
} }
} }
impl<V: Value, const N: usize> ArrayType<[V; N]> impl<V: Value<Type: Type<Value = V>>, const N: usize> ArrayType<[V; N]> {
where
V::Type: Type<Value = V>,
{
pub fn new_array(element: V::Type) -> Self { pub fn new_array(element: V::Type) -> Self {
ArrayType::new_with_len_type(element, ()) ArrayType::new_with_len_type(element, ())
} }
} }
impl<V: Value, const N: usize> FixedType for ArrayType<[V; N]> impl<V: StaticValue, const N: usize> StaticType for ArrayType<[V; N]> {
where fn static_type() -> Self {
V::Type: FixedType<Value = V>, Self::new_array(StaticType::static_type())
{
fn fixed_type() -> Self {
Self::new_array(FixedType::fixed_type())
} }
} }
impl<V: Value> ArrayType<[V]> impl<V: Value<Type: Type<Value = V>>> ArrayType<[V]> {
where
V::Type: Type<Value = V>,
{
pub fn new_slice(element: V::Type, len: usize) -> Self { pub fn new_slice(element: V::Type, len: usize) -> Self {
ArrayType::new_with_len_type(element, len) ArrayType::new_with_len_type(element, len)
} }
@ -514,18 +505,18 @@ impl<VA: ValueArrayOrSlice + ?Sized> Array<VA> {
impl<VA: ValueArrayOrSlice + ?Sized, T: Into<Arc<VA>>> From<T> for Array<VA> impl<VA: ValueArrayOrSlice + ?Sized, T: Into<Arc<VA>>> From<T> for Array<VA>
where where
VA::ElementType: FixedType, VA::Element: StaticValue,
{ {
fn from(value: T) -> Self { fn from(value: T) -> Self {
Self::new(FixedType::fixed_type(), value.into()) Self::new(StaticType::static_type(), value.into())
} }
} }
impl<E: ToExpr<Type = T>, T: FixedType> ToExpr for [E] { impl<E: ToExpr<Type = T>, T: StaticType<MaskType: StaticType>> ToExpr for [E] {
type Type = ArrayType<[T::Value]>; type Type = ArrayType<[T::Value]>;
fn ty(&self) -> Self::Type { fn ty(&self) -> Self::Type {
ArrayType::new_with_len_type(FixedType::fixed_type(), self.len()) ArrayType::new_with_len_type(StaticType::static_type(), self.len())
} }
fn to_expr(&self) -> Expr<<Self::Type as Type>::Value> { fn to_expr(&self) -> Expr<<Self::Type as Type>::Value> {
@ -536,7 +527,7 @@ impl<E: ToExpr<Type = T>, T: FixedType> ToExpr for [E] {
} }
} }
impl<E: ToExpr<Type = T>, T: FixedType> ToExpr for Vec<E> { impl<E: ToExpr<Type = T>, T: StaticType<MaskType: StaticType>> ToExpr for Vec<E> {
type Type = ArrayType<[T::Value]>; type Type = ArrayType<[T::Value]>;
fn ty(&self) -> Self::Type { fn ty(&self) -> Self::Type {
@ -548,11 +539,11 @@ impl<E: ToExpr<Type = T>, T: FixedType> ToExpr for Vec<E> {
} }
} }
impl<E: ToExpr<Type = T>, T: FixedType, const N: usize> ToExpr for [E; N] { impl<E: ToExpr<Type = T>, T: StaticType<MaskType: StaticType>, const N: usize> ToExpr for [E; N] {
type Type = ArrayType<[T::Value; N]>; type Type = ArrayType<[T::Value; N]>;
fn ty(&self) -> Self::Type { fn ty(&self) -> Self::Type {
ArrayType::new_with_len_type(FixedType::fixed_type(), ()) ArrayType::new_with_len_type(StaticType::static_type(), ())
} }
fn to_expr(&self) -> Expr<<Self::Type as Type>::Value> { fn to_expr(&self) -> Expr<<Self::Type as Type>::Value> {

View file

@ -9,7 +9,7 @@ use crate::{
source_location::SourceLocation, source_location::SourceLocation,
ty::{ ty::{
CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, DynCanonicalType,
DynCanonicalValue, DynType, FixedType, MatchVariantWithoutScope, Type, TypeEnum, DynCanonicalValue, DynType, MatchVariantWithoutScope, StaticType, Type, TypeEnum,
TypeWithDeref, Value, ValueEnum, TypeWithDeref, Value, ValueEnum,
}, },
}; };
@ -755,13 +755,13 @@ macro_rules! impl_tuple {
} }
} }
impl<$($T: FixedType,)*> FixedType for ($($T,)*) impl<$($T: StaticType<MaskType: StaticType>,)*> StaticType for ($($T,)*)
where where
$($T::Value: Value<Type = $T>,)* $($T::Value: Value<Type = $T>,)*
{ {
#[allow(clippy::unused_unit)] #[allow(clippy::unused_unit)]
fn fixed_type() -> Self { fn static_type() -> Self {
($($T::fixed_type(),)*) ($($T::static_type(),)*)
} }
} }

View file

@ -8,7 +8,7 @@ use crate::{
source_location::SourceLocation, source_location::SourceLocation,
ty::{ ty::{
impl_match_values_as_self, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, impl_match_values_as_self, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect,
DynCanonicalType, FixedType, Type, TypeEnum, Value, ValueEnum, DynCanonicalType, StaticType, Type, TypeEnum, Value, ValueEnum,
}, },
util::interned_bit, util::interned_bit,
}; };
@ -63,8 +63,8 @@ impl CanonicalType for ClockType {
const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::Clock; const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::Clock;
} }
impl FixedType for ClockType { impl StaticType for ClockType {
fn fixed_type() -> Self { fn static_type() -> Self {
Self Self
} }
} }
@ -103,7 +103,7 @@ impl CanonicalValue for Clock {
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Value)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Value)]
#[hdl(fixed_type, outline_generated)] #[hdl(static, outline_generated)]
pub struct ClockDomain { pub struct ClockDomain {
pub clk: Clock, pub clk: Clock,
pub rst: Reset, pub rst: Reset,

View file

@ -4,7 +4,7 @@ use crate::{
array::ArrayType, array::ArrayType,
bundle::{BundleType, BundleValue, DynBundle, DynBundleType, FieldType}, bundle::{BundleType, BundleValue, DynBundle, DynBundleType, FieldType},
enum_::{DynEnumType, EnumType, EnumValue}, enum_::{DynEnumType, EnumType, EnumValue},
int::{DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, IntValue, UInt, UIntType}, int::{DynSIntType, DynUInt, DynUIntType, IntValue, StaticOrDynIntType, UInt, UIntType},
intern::{Intern, Interned, InternedCompare, PtrEqWithTypeId, SupportsPtrEqWithTypeId}, intern::{Intern, Interned, InternedCompare, PtrEqWithTypeId, SupportsPtrEqWithTypeId},
memory::{DynPortType, MemPort, PortType}, memory::{DynPortType, MemPort, PortType},
module::{ module::{
@ -288,7 +288,7 @@ impl<T> Hash for Expr<T> {
impl<T> Expr<IntValue<T>> impl<T> Expr<IntValue<T>>
where where
T: FixedOrDynIntType< T: StaticOrDynIntType<
1, 1,
Signed = ConstBool<false>, Signed = ConstBool<false>,
CanonicalType = DynUIntType, CanonicalType = DynUIntType,

View file

@ -10,7 +10,7 @@ use crate::{
TargetPathDynArrayElement, TargetPathElement, ToExpr, TargetPathDynArrayElement, TargetPathElement, ToExpr,
}, },
int::{ int::{
DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int, DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, StaticOrDynIntType, Int,
IntCmp, IntType, IntTypeTrait, IntValue, UInt, UIntType, IntCmp, IntType, IntTypeTrait, IntValue, UInt, UIntType,
}, },
intern::{Intern, Interned}, intern::{Intern, Interned},
@ -726,7 +726,7 @@ macro_rules! cmp_op {
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>, >,
Output: FixedOrDynIntType< Output: StaticOrDynIntType<
1, 1,
Signed = ConstBool<false>, Signed = ConstBool<false>,
CanonicalType = DynUIntType, CanonicalType = DynUIntType,
@ -737,7 +737,7 @@ macro_rules! cmp_op {
pub lhs: Expr<LhsType::CanonicalValue>, pub lhs: Expr<LhsType::CanonicalValue>,
pub rhs: Expr<RhsType::CanonicalValue>, pub rhs: Expr<RhsType::CanonicalValue>,
#[type] #[type]
ty: Output = FixedOrDynIntType::new(), ty: Output = StaticOrDynIntType::new(),
#[cache] #[cache]
literal_bits: Result<Interned<BitSlice>, ()> = { literal_bits: Result<Interned<BitSlice>, ()> = {
lhs.to_literal_bits() lhs.to_literal_bits()
@ -1098,7 +1098,7 @@ macro_rules! reduce_bit_op {
fixed_ary_op! { fixed_ary_op! {
pub struct $name<Output,> pub struct $name<Output,>
where ( where (
Output: FixedOrDynIntType< Output: StaticOrDynIntType<
1, 1,
Signed = ConstBool<false>, Signed = ConstBool<false>,
CanonicalType = DynUIntType, CanonicalType = DynUIntType,
@ -1108,7 +1108,7 @@ macro_rules! reduce_bit_op {
{ {
pub arg: Expr<DynUInt>, pub arg: Expr<DynUInt>,
#[type] #[type]
ty: Output = FixedOrDynIntType::new(), ty: Output = StaticOrDynIntType::new(),
#[cache] #[cache]
literal_bits: Result<Interned<BitSlice>, ()> = { literal_bits: Result<Interned<BitSlice>, ()> = {
arg.to_literal_bits().map(|$bits| interned_bit($literal_bits_bool)) arg.to_literal_bits().map(|$bits| interned_bit($literal_bits_bool))
@ -1503,7 +1503,7 @@ where
} }
} }
cast_bit_to_typed_bit!(pub struct CastClockToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; ClockType => ToType); cast_bit_to_typed_bit!(pub struct CastClockToBit<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; ClockType => ToType);
impl ToBit for Clock { impl ToBit for Clock {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> { fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1511,7 +1511,7 @@ impl ToBit for Clock {
} }
} }
cast_bit_to_typed_bit!(pub struct CastSyncResetToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; SyncResetType => ToType); cast_bit_to_typed_bit!(pub struct CastSyncResetToBit<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; SyncResetType => ToType);
impl ToBit for SyncReset { impl ToBit for SyncReset {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> { fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1519,7 +1519,7 @@ impl ToBit for SyncReset {
} }
} }
cast_bit_to_typed_bit!(pub struct CastAsyncResetToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; AsyncResetType => ToType); cast_bit_to_typed_bit!(pub struct CastAsyncResetToBit<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; AsyncResetType => ToType);
impl ToBit for AsyncReset { impl ToBit for AsyncReset {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> { fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1527,7 +1527,7 @@ impl ToBit for AsyncReset {
} }
} }
cast_bit_to_typed_bit!(pub struct CastResetToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; ResetType => ToType); cast_bit_to_typed_bit!(pub struct CastResetToBit<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; ResetType => ToType);
impl ToBit for Reset { impl ToBit for Reset {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> { fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {

View file

@ -6,7 +6,7 @@ use crate::{
source_location::SourceLocation, source_location::SourceLocation,
ty::{ ty::{
impl_match_values_as_self, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, impl_match_values_as_self, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect,
DynCanonicalType, FixedType, Type, TypeEnum, Value, ValueEnum, DynCanonicalType, StaticType, Type, TypeEnum, Value, ValueEnum,
}, },
util::{ConstBool, GenericConstBool}, util::{ConstBool, GenericConstBool},
valueless::Valueless, valueless::Valueless,
@ -825,7 +825,7 @@ impl_int!(i64, true);
impl_int!(i128, true); impl_int!(i128, true);
impl< impl<
T: FixedOrDynIntType< T: StaticOrDynIntType<
1, 1,
Signed = ConstBool<false>, Signed = ConstBool<false>,
CanonicalType = DynUIntType, CanonicalType = DynUIntType,
@ -1000,7 +1000,7 @@ pub trait IntTypeTrait:
} }
} }
pub trait FixedOrDynIntType<const WIDTH: usize>: IntTypeTrait { pub trait StaticOrDynIntType<const WIDTH: usize>: IntTypeTrait {
fn new() -> Self; fn new() -> Self;
} }
@ -1203,7 +1203,7 @@ impl<Signed: GenericConstBool> IntTypeTrait for DynIntType<Signed> {
} }
} }
impl<Signed: GenericConstBool, const WIDTH: usize> FixedOrDynIntType<WIDTH> for DynIntType<Signed> { impl<Signed: GenericConstBool, const WIDTH: usize> StaticOrDynIntType<WIDTH> for DynIntType<Signed> {
fn new() -> Self { fn new() -> Self {
DynIntType::new(WIDTH) DynIntType::new(WIDTH)
} }
@ -1264,8 +1264,8 @@ impl<Signed: GenericConstBool, const WIDTH: usize> Type for IntType<Signed, WIDT
} }
} }
impl<Signed: GenericConstBool, const WIDTH: usize> FixedType for IntType<Signed, WIDTH> { impl<Signed: GenericConstBool, const WIDTH: usize> StaticType for IntType<Signed, WIDTH> {
fn fixed_type() -> Self { fn static_type() -> Self {
Self::new() Self::new()
} }
} }
@ -1292,7 +1292,7 @@ impl<Signed: GenericConstBool, const WIDTH: usize> IntTypeTrait for IntType<Sign
} }
} }
impl<Signed: GenericConstBool, const WIDTH: usize> FixedOrDynIntType<WIDTH> impl<Signed: GenericConstBool, const WIDTH: usize> StaticOrDynIntType<WIDTH>
for IntType<Signed, WIDTH> for IntType<Signed, WIDTH>
{ {
fn new() -> Self { fn new() -> Self {

View file

@ -11,13 +11,13 @@ use crate::{
ops::VariantAccess, Expr, Flow, Target, TargetBase, TargetPathArrayElement, ops::VariantAccess, Expr, Flow, Target, TargetBase, TargetPathArrayElement,
TargetPathBundleField, TargetPathElement, ToExpr, TargetPathBundleField, TargetPathElement, ToExpr,
}, },
int::{DynUInt, DynUIntType, FixedOrDynIntType, IntValue, UInt}, int::{DynUInt, DynUIntType, IntValue, StaticOrDynIntType, UInt},
intern::{Intern, Interned}, intern::{Intern, Interned},
memory::{Mem, MemBuilder, MemBuilderTarget, PortName}, memory::{Mem, MemBuilder, MemBuilderTarget, PortName},
reg::Reg, reg::Reg,
source_location::SourceLocation, source_location::SourceLocation,
ty::{ ty::{
CanonicalType, Connect, DynCanonicalType, DynCanonicalValue, DynType, FixedType, Type, CanonicalType, Connect, DynCanonicalType, DynCanonicalValue, DynType, StaticValue, Type,
TypeEnum, Value, TypeEnum, Value,
}, },
util::ConstBool, util::ConstBool,
@ -1827,10 +1827,7 @@ impl<'a, CD> RegBuilder<'a, CD, (), ()> {
stmts, stmts,
} }
} }
pub fn reset_default<V: Value + Default>(self) -> RegBuilder<'a, CD, Option<Expr<V>>, V> pub fn reset_default<V: StaticValue + Default>(self) -> RegBuilder<'a, CD, Option<Expr<V>>, V> {
where
V::Type: FixedType<Value = V>,
{
self.reset(V::default().to_expr()) self.reset(V::default().to_expr())
} }
pub fn opt_reset<T: Type>( pub fn opt_reset<T: Type>(
@ -2264,7 +2261,7 @@ where
#[track_caller] #[track_caller]
pub fn if_<Ty>(&mut self, cond: Expr<IntValue<Ty>>) -> IfScope pub fn if_<Ty>(&mut self, cond: Expr<IntValue<Ty>>) -> IfScope
where where
Ty: FixedOrDynIntType< Ty: StaticOrDynIntType<
1, 1,
Signed = ConstBool<false>, Signed = ConstBool<false>,
CanonicalType = DynUIntType, CanonicalType = DynUIntType,
@ -2279,7 +2276,7 @@ where
source_location: SourceLocation, source_location: SourceLocation,
) -> IfScope ) -> IfScope
where where
Ty: FixedOrDynIntType< Ty: StaticOrDynIntType<
1, 1,
Signed = ConstBool<false>, Signed = ConstBool<false>,
CanonicalType = DynUIntType, CanonicalType = DynUIntType,

View file

@ -12,7 +12,7 @@ use crate::{
TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement, ToExpr, TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement, ToExpr,
}, },
int::{ int::{
DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, IntType, DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, StaticOrDynIntType, IntType,
IntTypeTrait, IntTypeTrait,
}, },
intern::{Intern, Interned}, intern::{Intern, Interned},

View file

@ -7,13 +7,13 @@ use crate::{
source_location::SourceLocation, source_location::SourceLocation,
ty::{ ty::{
impl_match_values_as_self, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect, impl_match_values_as_self, CanonicalType, CanonicalTypeKind, CanonicalValue, Connect,
DynCanonicalType, FixedType, Type, TypeEnum, Value, ValueEnum, DynCanonicalType, StaticType, Type, TypeEnum, Value, ValueEnum,
}, },
util::interned_bit, util::interned_bit,
}; };
use bitvec::slice::BitSlice; use bitvec::slice::BitSlice;
pub trait ResetTypeTrait: CanonicalType + FixedType {} pub trait ResetTypeTrait: CanonicalType + StaticType<MaskType = UIntType<1>> {}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub struct AsyncResetType; pub struct AsyncResetType;
@ -64,8 +64,8 @@ impl CanonicalType for AsyncResetType {
const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::AsyncReset; const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::AsyncReset;
} }
impl FixedType for AsyncResetType { impl StaticType for AsyncResetType {
fn fixed_type() -> Self { fn static_type() -> Self {
Self Self
} }
} }
@ -154,8 +154,8 @@ impl CanonicalType for SyncResetType {
const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::SyncReset; const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::SyncReset;
} }
impl FixedType for SyncResetType { impl StaticType for SyncResetType {
fn fixed_type() -> Self { fn static_type() -> Self {
Self Self
} }
} }
@ -244,8 +244,8 @@ impl CanonicalType for ResetType {
const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::Reset; const CANONICAL_TYPE_KIND: CanonicalTypeKind = CanonicalTypeKind::Reset;
} }
impl FixedType for ResetType { impl StaticType for ResetType {
fn fixed_type() -> Self { fn static_type() -> Self {
Self Self
} }
} }

View file

@ -625,8 +625,12 @@ pub trait CanonicalType:
impl<T: CanonicalType> DynCanonicalType for T {} impl<T: CanonicalType> DynCanonicalType for T {}
pub trait FixedType: Type { pub trait StaticType: Type {
fn fixed_type() -> Self; // can't put bounds on full trait, so put it here instead
fn static_type() -> Self
where
Self::Value: Value<Type = Self>,
Self::MaskType: StaticType;
} }
pub trait DynValueTrait: fmt::Debug + Send + Sync + Any { pub trait DynValueTrait: fmt::Debug + Send + Sync + Any {
@ -808,6 +812,10 @@ pub trait Value: DynValueTrait + Clone + Eq + Hash + ToExpr {
} }
} }
pub trait StaticValue: Value<Type: StaticType<Value = Self, MaskType: StaticType>> {}
impl<T: Value<Type: StaticType<Value = Self, MaskType: StaticType>>> StaticValue for T {}
pub trait DynCanonicalValueTrait: DynValueTrait + sealed::Sealed { pub trait DynCanonicalValueTrait: DynValueTrait + sealed::Sealed {
fn ty_dyn_canonical(&self) -> Interned<dyn DynCanonicalType>; fn ty_dyn_canonical(&self) -> Interned<dyn DynCanonicalType>;
fn value_enum(&self) -> ValueEnum; fn value_enum(&self) -> ValueEnum;

View file

@ -13,7 +13,7 @@ use fayalite::{
module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind}, module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
reset::{SyncReset, ToReset}, reset::{SyncReset, ToReset},
source_location::SourceLocation, source_location::SourceLocation,
ty::{FixedType, Value}, ty::{StaticValue, Value},
}; };
use serde_json::json; use serde_json::json;
@ -195,7 +195,7 @@ circuit check_array_repeat_1:
#[hdl_module(outline_generated)] #[hdl_module(outline_generated)]
pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U) pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U)
where where
T: Value<Type: FixedType<Value = T>>, T: StaticValue,
U: std::fmt::Display, U: std::fmt::Display,
{ {
dbg!(M); dbg!(M);
@ -377,18 +377,18 @@ circuit check_written_inside_both_if_else:
} }
#[derive(Value, Clone, PartialEq, Eq, Hash, Debug)] #[derive(Value, Clone, PartialEq, Eq, Hash, Debug)]
#[hdl(fixed_type, outline_generated)] #[hdl(static, outline_generated)]
pub struct TestStruct<T> { pub struct TestStruct<T> {
pub a: T, pub a: T,
pub b: UInt<8>, pub b: UInt<8>,
} }
#[derive(Value, Clone, PartialEq, Eq, Hash, Debug)] #[derive(Value, Clone, PartialEq, Eq, Hash, Debug)]
#[hdl(fixed_type, outline_generated)] #[hdl(static, outline_generated)]
pub struct TestStruct2(pub UInt<8>); pub struct TestStruct2(pub UInt<8>);
#[derive(Value, Clone, PartialEq, Eq, Hash, Debug)] #[derive(Value, Clone, PartialEq, Eq, Hash, Debug)]
#[hdl(fixed_type, outline_generated)] #[hdl(static, outline_generated)]
pub struct TestStruct3; pub struct TestStruct3;
#[hdl_module(outline_generated)] #[hdl_module(outline_generated)]

View file

@ -1,6 +1,9 @@
// 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::{int::UInt, ty::Value}; use fayalite::{
int::UInt,
ty::{StaticValue, Value},
};
#[derive(Value, Clone, Hash, PartialEq, Eq, Debug)] #[derive(Value, Clone, Hash, PartialEq, Eq, Debug)]
#[hdl(outline_generated)] #[hdl(outline_generated)]
@ -21,3 +24,9 @@ pub enum E<T> {
G(T), G(T),
H(T, UInt<1>), H(T, UInt<1>),
} }
#[derive(Value, Clone, Hash, PartialEq, Eq, Debug)]
#[hdl(outline_generated, static, where(T: StaticValue))]
pub struct S2<T> {
pub v: E<T>,
}

View file

@ -501,7 +501,7 @@
"lhs": "Visible", "lhs": "Visible",
"rhs": "Visible" "rhs": "Visible"
}, },
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::CmpLe": { "ops::CmpLe": {
"data": { "data": {
@ -510,7 +510,7 @@
"lhs": "Visible", "lhs": "Visible",
"rhs": "Visible" "rhs": "Visible"
}, },
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::CmpGt": { "ops::CmpGt": {
"data": { "data": {
@ -519,7 +519,7 @@
"lhs": "Visible", "lhs": "Visible",
"rhs": "Visible" "rhs": "Visible"
}, },
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::CmpGe": { "ops::CmpGe": {
"data": { "data": {
@ -528,7 +528,7 @@
"lhs": "Visible", "lhs": "Visible",
"rhs": "Visible" "rhs": "Visible"
}, },
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::CmpEq": { "ops::CmpEq": {
"data": { "data": {
@ -537,7 +537,7 @@
"lhs": "Visible", "lhs": "Visible",
"rhs": "Visible" "rhs": "Visible"
}, },
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::CmpNe": { "ops::CmpNe": {
"data": { "data": {
@ -546,7 +546,7 @@
"lhs": "Visible", "lhs": "Visible",
"rhs": "Visible" "rhs": "Visible"
}, },
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::CastInt": { "ops::CastInt": {
"data": { "data": {
@ -574,7 +574,7 @@
"$constructor": "ops::ReduceBitAnd::new_unchecked", "$constructor": "ops::ReduceBitAnd::new_unchecked",
"arg": "Visible" "arg": "Visible"
}, },
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::ReduceBitOr": { "ops::ReduceBitOr": {
"data": { "data": {
@ -582,7 +582,7 @@
"$constructor": "ops::ReduceBitOr::new_unchecked", "$constructor": "ops::ReduceBitOr::new_unchecked",
"arg": "Visible" "arg": "Visible"
}, },
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::ReduceBitXor": { "ops::ReduceBitXor": {
"data": { "data": {
@ -590,7 +590,7 @@
"$constructor": "ops::ReduceBitXor::new_unchecked", "$constructor": "ops::ReduceBitXor::new_unchecked",
"arg": "Visible" "arg": "Visible"
}, },
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>" "generics": "<Output: StaticOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
}, },
"ops::FieldAccess": { "ops::FieldAccess": {
"data": { "data": {
@ -696,7 +696,7 @@
"$constructor": "ops::CastClockToBit::new_unchecked", "$constructor": "ops::CastClockToBit::new_unchecked",
"value": "Visible" "value": "Visible"
}, },
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>" "generics": "<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
}, },
"ops::CastSyncResetToBit": { "ops::CastSyncResetToBit": {
"data": { "data": {
@ -704,7 +704,7 @@
"$constructor": "ops::CastSyncResetToBit::new_unchecked", "$constructor": "ops::CastSyncResetToBit::new_unchecked",
"value": "Visible" "value": "Visible"
}, },
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>" "generics": "<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
}, },
"ops::CastAsyncResetToBit": { "ops::CastAsyncResetToBit": {
"data": { "data": {
@ -712,7 +712,7 @@
"$constructor": "ops::CastAsyncResetToBit::new_unchecked", "$constructor": "ops::CastAsyncResetToBit::new_unchecked",
"value": "Visible" "value": "Visible"
}, },
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>" "generics": "<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
}, },
"ops::CastResetToBit": { "ops::CastResetToBit": {
"data": { "data": {
@ -720,7 +720,7 @@
"$constructor": "ops::CastResetToBit::new_unchecked", "$constructor": "ops::CastResetToBit::new_unchecked",
"value": "Visible" "value": "Visible"
}, },
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>" "generics": "<ToType: StaticOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
}, },
"BlockId": { "BlockId": {
"data": { "data": {