diff --git a/crates/fayalite-proc-macros-impl/src/lib.rs b/crates/fayalite-proc-macros-impl/src/lib.rs index 903983f..194dbf3 100644 --- a/crates/fayalite-proc-macros-impl/src/lib.rs +++ b/crates/fayalite-proc-macros-impl/src/lib.rs @@ -78,7 +78,6 @@ mod kw { custom_keyword!(output); custom_keyword!(reg_builder); custom_keyword!(reset); - custom_keyword!(reset_default); custom_keyword!(skip); custom_keyword!(target); custom_keyword!(wire); diff --git a/crates/fayalite-proc-macros-impl/src/module/transform_body.rs b/crates/fayalite-proc-macros-impl/src/module/transform_body.rs index 1f9565a..6e99e87 100644 --- a/crates/fayalite-proc-macros-impl/src/module/transform_body.rs +++ b/crates/fayalite-proc-macros-impl/src/module/transform_body.rs @@ -265,11 +265,6 @@ pub(crate) enum RegBuilderReset { paren: Paren, init_expr: Box, }, - ResetDefault { - dot_token: Token![.], - reset_default: kw::reset_default, - paren: Paren, - }, } impl_fold! { @@ -286,11 +281,6 @@ impl_fold! { paren: Paren, init_expr: Box, }, - ResetDefault { - dot_token: Token![.], - reset_default: kw::reset_default, - paren: Paren, - }, } } @@ -312,11 +302,6 @@ impl Parse for RegBuilderReset { paren: parenthesized!(paren_contents in input), init_expr: paren_contents.call(parse_single_fn_arg)?, }), - RegBuilderMethod::ResetDefault(reset_default) => Ok(Self::ResetDefault { - dot_token, - reset_default, - paren: parenthesized!(paren_contents in input), - }), } } } @@ -344,15 +329,6 @@ impl ToTokens for RegBuilderReset { reset.to_tokens(tokens); paren.surround(tokens, |tokens| init_expr.to_tokens(tokens)); } - RegBuilderReset::ResetDefault { - dot_token, - reset_default, - paren, - } => { - dot_token.to_tokens(tokens); - reset_default.to_tokens(tokens); - paren.surround(tokens, |_| {}); - } } } } @@ -401,8 +377,6 @@ make_builder_method_enum! { NoReset(no_reset), #[cond = need_reset] Reset(reset), - #[cond = need_reset] - ResetDefault(reset_default), } } @@ -445,17 +419,13 @@ impl HdlLetKindRegBuilder { let mut clock_domain = None; match RegBuilderMethod::parse_dot_prefixed(&input.fork(), true, true)?.1 { RegBuilderMethod::ClockDomain(_) => clock_domain = Some(input.parse()?), - RegBuilderMethod::NoReset(_) - | RegBuilderMethod::Reset(_) - | RegBuilderMethod::ResetDefault(_) => {} + RegBuilderMethod::NoReset(_) | RegBuilderMethod::Reset(_) => {} } let reset = input.parse()?; if clock_domain.is_none() { match RegBuilderMethod::parse_dot_prefixed(&input.fork(), true, false)?.1 { RegBuilderMethod::ClockDomain(_) => clock_domain = Some(input.parse()?), - RegBuilderMethod::NoReset(_) - | RegBuilderMethod::Reset(_) - | RegBuilderMethod::ResetDefault(_) => unreachable!(), + RegBuilderMethod::NoReset(_) | RegBuilderMethod::Reset(_) => unreachable!(), } } Ok(Self { @@ -1370,7 +1340,7 @@ impl Visitor<'_> { no_reset.to_tokens(&mut expr); paren.surround(&mut expr, |expr| ty_expr.to_tokens(expr)); } - RegBuilderReset::Reset { .. } | RegBuilderReset::ResetDefault { .. } => { + RegBuilderReset::Reset { .. } => { hdl_let.kind.reset.to_tokens(&mut expr); } } diff --git a/crates/fayalite/src/expr/ops.rs b/crates/fayalite/src/expr/ops.rs index 4814d2d..e5d3d9b 100644 --- a/crates/fayalite/src/expr/ops.rs +++ b/crates/fayalite/src/expr/ops.rs @@ -1236,10 +1236,11 @@ macro_rules! impl_dyn_shl { } } - impl_binary_op_trait! { - #[generics(LhsWidth: Size, RhsWidth: Size)] - fn Shl::shl(lhs: $ty, rhs: UIntType) -> $ty { - $name::new(Expr::as_dyn_int(lhs), Expr::as_dyn_int(rhs)).to_expr() + impl Shl>> for Expr<$ty> { + type Output = Expr<$ty>; + + fn shl(self, rhs: Expr>) -> Self::Output { + $name::new(Expr::as_dyn_int(self), Expr::as_dyn_int(rhs)).to_expr() } } }; @@ -1308,10 +1309,11 @@ macro_rules! impl_dyn_shr { } } - impl_binary_op_trait! { - #[generics(LhsWidth: Size, RhsWidth: Size)] - fn Shr::shr(lhs: $ty, rhs: UIntType) -> $ty { - $name::new(lhs, Expr::as_dyn_int(rhs)).to_expr() + impl Shr>> for Expr<$ty> { + type Output = Expr<$ty>; + + fn shr(self, rhs: Expr>) -> Self::Output { + $name::new(self, Expr::as_dyn_int(rhs)).to_expr() } } }; diff --git a/crates/fayalite/src/int.rs b/crates/fayalite/src/int.rs index 2950086..b48f617 100644 --- a/crates/fayalite/src/int.rs +++ b/crates/fayalite/src/int.rs @@ -18,6 +18,7 @@ use std::{ borrow::{BorrowMut, Cow}, fmt, marker::PhantomData, + num::NonZero, ops::{Bound, Index, Not, Range, RangeBounds, RangeInclusive}, sync::Arc, }; @@ -468,7 +469,11 @@ impl SInt { } macro_rules! impl_prim_int { - ($prim_int:ident, $ty:ty) => { + ( + $(#[$meta:meta])* + $prim_int:ident, $ty:ty + ) => { + $(#[$meta])* impl ToExpr for $prim_int { type Type = $ty; @@ -479,6 +484,17 @@ macro_rules! impl_prim_int { ) } } + $(#[$meta])* + impl ToExpr for NonZero<$prim_int> { + type Type = $ty; + + fn to_expr(&self) -> Expr { + <$ty>::le_bytes_to_expr_wrapping( + &self.get().to_le_bytes(), + <$ty as BoolOrIntType>::Width::VALUE, + ) + } + } }; } @@ -493,6 +509,16 @@ impl_prim_int!(i32, SInt<32>); impl_prim_int!(i64, SInt<64>); impl_prim_int!(i128, SInt<128>); +impl_prim_int!( + /// for portability reasons, [`usize`] always translates to [`UInt<64>`] + usize, UInt<64> +); + +impl_prim_int!( + /// for portability reasons, [`isize`] always translates to [`SInt<64>`] + isize, SInt<64> +); + pub trait BoolOrIntType: Type + sealed::BoolOrIntTypeSealed { type Width: Size; type Signed: GenericConstBool;