add repeat()
This commit is contained in:
		
							parent
							
								
									78edfc97b2
								
							
						
					
					
						commit
						a701f99fd6
					
				
					 2 changed files with 17 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -9,7 +9,7 @@ use crate::{
 | 
			
		|||
        ops::ExprCastTo,
 | 
			
		||||
        target::{GetTarget, Target},
 | 
			
		||||
    },
 | 
			
		||||
    int::{Bool, DynSize, IntType, SIntType, SIntValue, Size, UInt, UIntType, UIntValue},
 | 
			
		||||
    int::{Bool, DynSize, IntType, SIntType, SIntValue, Size, SizeType, UInt, UIntType, UIntValue},
 | 
			
		||||
    intern::{Intern, Interned},
 | 
			
		||||
    memory::{DynPortType, MemPort, PortType},
 | 
			
		||||
    module::{
 | 
			
		||||
| 
						 | 
				
			
			@ -720,3 +720,18 @@ impl<T: Type> MakeUninitExpr for T {
 | 
			
		|||
        ops::Uninit::new(self).to_expr()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn repeat<T: Type, L: SizeType>(
 | 
			
		||||
    element: impl ToExpr<Type = T>,
 | 
			
		||||
    len: L,
 | 
			
		||||
) -> Expr<ArrayType<T, L::Size>> {
 | 
			
		||||
    let element = element.to_expr();
 | 
			
		||||
    let canonical_element = Expr::canonical(element);
 | 
			
		||||
    ops::ArrayLiteral::new(
 | 
			
		||||
        Expr::ty(element),
 | 
			
		||||
        std::iter::repeat(canonical_element)
 | 
			
		||||
            .take(L::Size::as_usize(len))
 | 
			
		||||
            .collect(),
 | 
			
		||||
    )
 | 
			
		||||
    .to_expr()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ pub use crate::{
 | 
			
		|||
    clock::{Clock, ClockDomain, ToClock},
 | 
			
		||||
    enum_::{HdlNone, HdlOption, HdlSome},
 | 
			
		||||
    expr::{
 | 
			
		||||
        CastBitsTo, CastTo, CastToBits, Expr, HdlPartialEq, HdlPartialOrd, MakeUninitExpr,
 | 
			
		||||
        repeat, CastBitsTo, CastTo, CastToBits, Expr, HdlPartialEq, HdlPartialOrd, MakeUninitExpr,
 | 
			
		||||
        ReduceBits, ToExpr,
 | 
			
		||||
    },
 | 
			
		||||
    hdl, hdl_module,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue