Compare commits

..

No commits in common. "5cf638c74a11099ba60f71867bafdd5c503cf46a" and "af95bb2f58f792a36cd774b5610ac9b220d74493" have entirely different histories.

8 changed files with 17 additions and 26 deletions

View file

@ -15,5 +15,4 @@ jobs:
with: with:
save-if: ${{ github.ref == 'refs/heads/master' }} save-if: ${{ github.ref == 'refs/heads/master' }}
- run: cargo test - run: cargo test
- run: cargo test --features=unstable-doc
- run: cargo doc --features=unstable-doc - run: cargo doc --features=unstable-doc

View file

@ -1,7 +1,7 @@
//! # Module Function Bodies //! # Module Function Bodies
//! //!
//! The `#[hdl_module]` attribute lets you have statements/expressions with `#[hdl]` annotations //! The `#[hdl_module]` attribute lets you have statements/expressions with `#[hdl]` annotations
//! and `_hdl`-suffixed literals in the module function's body. //! and `_hdl`-suffixed literals in the module function's body
pub mod hdl_array_expressions; pub mod hdl_array_expressions;
pub mod hdl_if_statements; pub mod hdl_if_statements;

View file

@ -13,12 +13,12 @@
//! m.connect( //! m.connect(
//! w, //! w,
//! #[hdl] //! #[hdl]
//! [4_hdl_u8, v, 3_hdl_u8, (v + 7_hdl_u8).cast()] // you can make an array like this //! [4_hdl_u8, v, 3_hdl_u8, v + 7_hdl_u8] // you can make an array like this
//! ); //! );
//! m.connect( //! m.connect(
//! w, //! w,
//! #[hdl] //! #[hdl]
//! [(v + 1_hdl_u8).cast(); 4] // or you can make an array repeat like this //! [v + 1_hdl_u8; 4] // or you can make an array repeat like this
//! ); //! );
//! # } //! # }
//! ``` //! ```

View file

@ -4,12 +4,11 @@
//! so you should read it. //! so you should read it.
//! //!
//! ``` //! ```
//! # use fayalite::{hdl_module, int::UInt, expr::Expr, array::Array}; //! # use fayalite::{hdl_module, int::UInt, array::Array};
//! # #[hdl_module] //! # #[hdl_module]
//! # fn module() { //! # fn module() {
//! #[hdl] //! #[hdl]
//! let my_input: UInt<10> = m.input(); //! let my_input: UInt<10> = m.input();
//! let _: Expr<UInt<10>> = my_input; // my_input has type Expr<UInt<10>>
//! #[hdl] //! #[hdl]
//! let my_output: Array<[UInt<10>; 3]> = m.output(); //! let my_output: Array<[UInt<10>; 3]> = m.output();
//! # } //! # }

View file

@ -11,7 +11,6 @@
//! ``` //! ```
//! # 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)]
//! pub struct MyStruct { //! pub struct MyStruct {
//! pub a: UInt<8>, //! pub a: UInt<8>,
//! pub b: UInt<16>, //! pub b: UInt<16>,

View file

@ -20,8 +20,8 @@
//! Connection Semantics Example: //! Connection Semantics Example:
//! //!
//! ``` //! ```
//! # use fayalite::{hdl_module, int::UInt}; //! # use fayalite::module_hdl;
//! # #[hdl_module] //! # #[module_hdl]
//! # fn module() { //! # fn module() {
//! #[hdl] //! #[hdl]
//! let a: UInt<8> = m.wire(); //! let a: UInt<8> = m.wire();
@ -43,8 +43,8 @@
//! # Conditional Connection Semantics //! # Conditional Connection Semantics
//! //!
//! ``` //! ```
//! # use fayalite::{hdl_module, int::UInt}; //! # use fayalite::module_hdl;
//! # #[hdl_module] //! # #[module_hdl]
//! # fn module() { //! # fn module() {
//! #[hdl] //! #[hdl]
//! let cond: UInt<1> = m.input(); //! let cond: UInt<1> = m.input();

View file

@ -11,7 +11,7 @@ use crate::{
}, },
int::{ int::{
DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int, DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int,
IntCmp, IntType, IntTypeTrait, IntValue, UInt, UIntType, IntCmp, IntTypeTrait, IntValue, UInt, UIntType,
}, },
intern::{Intern, Interned}, intern::{Intern, Interned},
reset::{ reset::{
@ -888,7 +888,7 @@ fixed_ary_op! {
}, },
fn simulate(&self, sim_state: &mut SimState) -> _ { fn simulate(&self, sim_state: &mut SimState) -> _ {
self.value.simulate(sim_state).cast_as_type(self.ty.canonical()) self.value.simulate(sim_state).cast(self.ty.canonical())
} }
fn expr_enum(&self) -> _ { fn expr_enum(&self) -> _ {
@ -935,7 +935,7 @@ impl<
>, >,
> Expr<IntValue<FromType>> > Expr<IntValue<FromType>>
{ {
pub fn cast_as_type< pub fn cast<
ToType: IntTypeTrait< ToType: IntTypeTrait<
CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>,
@ -946,20 +946,17 @@ impl<
) -> Expr<ToType::Value> { ) -> Expr<ToType::Value> {
CastInt::<FromType, ToType>::new_unchecked(self.canonical(), ty).to_expr() CastInt::<FromType, ToType>::new_unchecked(self.canonical(), ty).to_expr()
} }
pub fn cast<Signed: GenericConstBool, const WIDTH: usize>(self) -> Expr<Int<Signed, WIDTH>> {
self.cast_as_type(IntType::new())
}
pub fn as_same_width_uint(self) -> Expr<IntValue<FromType::SameWidthUInt>> { pub fn as_same_width_uint(self) -> Expr<IntValue<FromType::SameWidthUInt>> {
self.cast_as_type(self.ty().as_same_width_uint()) self.cast(self.ty().as_same_width_uint())
} }
pub fn as_same_width_sint(self) -> Expr<IntValue<FromType::SameWidthSInt>> { pub fn as_same_width_sint(self) -> Expr<IntValue<FromType::SameWidthSInt>> {
self.cast_as_type(self.ty().as_same_width_sint()) self.cast(self.ty().as_same_width_sint())
} }
pub fn as_same_value_uint(self) -> Expr<DynUInt> { pub fn as_same_value_uint(self) -> Expr<DynUInt> {
self.cast_as_type(self.ty().as_same_value_uint()) self.cast(self.ty().as_same_value_uint())
} }
pub fn as_same_value_sint(self) -> Expr<DynSInt> { pub fn as_same_value_sint(self) -> Expr<DynSInt> {
self.cast_as_type(self.ty().as_same_value_sint()) self.cast(self.ty().as_same_value_sint())
} }
} }
@ -1023,7 +1020,7 @@ impl<
return false.to_expr(); return false.to_expr();
} }
let index = index.min(width - 1); let index = index.min(width - 1);
self.slice(index..=index).cast() self.slice(index..=index).cast(UIntType::new())
} }
pub fn is_negative(self) -> Expr<UInt<1>> { pub fn is_negative(self) -> Expr<UInt<1>> {
if T::Signed::VALUE { if T::Signed::VALUE {

View file

@ -211,7 +211,7 @@ impl<
IntValue::with_type(new_type, self.into_uint_value()) IntValue::with_type(new_type, self.into_uint_value())
} }
} }
pub fn cast_as_type< pub fn cast<
NewType: IntTypeTrait< NewType: IntTypeTrait<
CanonicalType = DynIntType<<NewType as IntTypeTrait>::Signed>, CanonicalType = DynIntType<<NewType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<NewType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<NewType as IntTypeTrait>::Signed>,
@ -226,9 +226,6 @@ impl<
IntValue::with_type(new_type, self.uint_value()) IntValue::with_type(new_type, self.uint_value())
} }
} }
pub fn cast<Signed: GenericConstBool, const WIDTH: usize>(self) -> Int<Signed, WIDTH> {
self.cast_as_type(IntType::new())
}
pub fn as_same_width_uint(self) -> IntValue<T::SameWidthUInt> { pub fn as_same_width_uint(self) -> IntValue<T::SameWidthUInt> {
IntValue { IntValue {
ty: self.ty.as_same_width_uint(), ty: self.ty.as_same_width_uint(),