diff --git a/crates/fayalite/src/expr/ops.rs b/crates/fayalite/src/expr/ops.rs index 51aa7d2..0c8c4fa 100644 --- a/crates/fayalite/src/expr/ops.rs +++ b/crates/fayalite/src/expr/ops.rs @@ -19,7 +19,10 @@ use crate::{ UIntType, UIntValue, }, intern::{Intern, Interned}, - reset::{AsyncReset, Reset, SyncReset, ToAsyncReset, ToReset, ToSyncReset}, + reset::{ + AsyncReset, Reset, ResetType, ResetTypeDispatch, SyncReset, ToAsyncReset, ToReset, + ToSyncReset, + }, ty::{CanonicalType, StaticType, Type}, util::ConstUsize, }; @@ -1773,11 +1776,11 @@ impl_cast_bit_op!(CastSIntToAsyncReset, SInt<1>, #[dyn] SInt, AsyncReset, #[trai impl_cast_bit_op!(CastSyncResetToBool, SyncReset, Bool); impl_cast_bit_op!(CastSyncResetToUInt, SyncReset, UInt<1>, #[dyn] UInt); impl_cast_bit_op!(CastSyncResetToSInt, SyncReset, SInt<1>, #[dyn] SInt); -impl_cast_bit_op!(CastSyncResetToReset, SyncReset, Reset, #[trait] ToReset::to_reset); +impl_cast_bit_op!(CastSyncResetToReset, SyncReset, Reset); impl_cast_bit_op!(CastAsyncResetToBool, AsyncReset, Bool); impl_cast_bit_op!(CastAsyncResetToUInt, AsyncReset, UInt<1>, #[dyn] UInt); impl_cast_bit_op!(CastAsyncResetToSInt, AsyncReset, SInt<1>, #[dyn] SInt); -impl_cast_bit_op!(CastAsyncResetToReset, AsyncReset, Reset, #[trait] ToReset::to_reset); +impl_cast_bit_op!(CastAsyncResetToReset, AsyncReset, Reset); impl_cast_bit_op!(CastResetToBool, Reset, Bool); impl_cast_bit_op!(CastResetToUInt, Reset, UInt<1>, #[dyn] UInt); impl_cast_bit_op!(CastResetToSInt, Reset, SInt<1>, #[dyn] SInt); @@ -1788,6 +1791,29 @@ impl_cast_bit_op!(CastClockToBool, Clock, Bool); impl_cast_bit_op!(CastClockToUInt, Clock, UInt<1>, #[dyn] UInt); impl_cast_bit_op!(CastClockToSInt, Clock, SInt<1>, #[dyn] SInt); +impl ToReset for Expr { + fn to_reset(&self) -> Expr { + struct Dispatch; + impl ResetTypeDispatch for Dispatch { + type Input = Expr; + type Output = Expr; + + fn reset(self, input: Self::Input) -> Self::Output { + input + } + + fn sync_reset(self, input: Self::Input) -> Self::Output { + input.cast_to_static() + } + + fn async_reset(self, input: Self::Input) -> Self::Output { + input.cast_to_static() + } + } + T::dispatch(*self, Dispatch) + } +} + impl ExprCastTo for AsyncReset { fn cast_to(src: Expr, _to_type: AsyncReset) -> Expr { src diff --git a/crates/fayalite/src/reset.rs b/crates/fayalite/src/reset.rs index 0dd6df8..b90d40e 100644 --- a/crates/fayalite/src/reset.rs +++ b/crates/fayalite/src/reset.rs @@ -25,7 +25,7 @@ pub trait ResetTypeDispatch: Sized { } macro_rules! reset_type { - ($name:ident, $Trait:ident::$trait_fn:ident, $is_castable_from_bits:literal, $dispatch_fn:ident) => { + ($name:ident, $(#[$impl_trait:ident])? $Trait:ident::$trait_fn:ident, $is_castable_from_bits:literal, $dispatch_fn:ident) => { #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)] pub struct $name; @@ -109,16 +109,16 @@ macro_rules! reset_type { } } - impl $Trait for Expr<$name> { + $($impl_trait $Trait for Expr<$name> { fn $trait_fn(&self) -> Expr<$name> { *self } - } + })? }; } -reset_type!(AsyncReset, ToAsyncReset::to_async_reset, true, async_reset); -reset_type!(SyncReset, ToSyncReset::to_sync_reset, true, sync_reset); +reset_type!(AsyncReset, #[impl] ToAsyncReset::to_async_reset, true, async_reset); +reset_type!(SyncReset, #[impl] ToSyncReset::to_sync_reset, true, sync_reset); reset_type!( Reset, ToReset::to_reset,