bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

generic inputs

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
dabox367



Joined: 24 Jan 2011
Posts: 3

PostPosted: Fri Mar 04, 2011 3:28 pm    Post subject: generic inputs Reply with quote

Is there a way to feed an Int or UInt to a type that expects a numeric type input? Let's take Vector for instance:

Vector#(numeric type vsize, type element_type)

I want to be able to feed vsize a number I calculated and then stored in an Int or UInt type but get a unbounded type variable error.

Example (overly-simplistic):

Integer temp1 = 6 + 3;
Int#(32) temp2 = fromInteger(temp1);
...
Vector#(temp2, Reg#(Bit#(32))) reg_vect <- replicateM(mkReg(0));

Is there some way to do this in BSV?
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 499

PostPosted: Sat Mar 05, 2011 4:59 pm    Post subject: Reply with quote

No, you can't go from values back to types. But you can start from types and go to values:
Code:
typedef 6 N;
typedef 3 M;

typedef TAdd#(N,M) Temp1;

module mkMod(...);
   Integer temp1 = valueOf(Temp1);
   Int#(32) temp2 = fromInteger(temp1);
   ...
   Vector#(Temp1, Reg#(Bit#(32))) reg_vect <- replicateM(mkReg(0));
Back to top
View user's profile Send private message
dabox367



Joined: 24 Jan 2011
Posts: 3

PostPosted: Tue Mar 08, 2011 12:55 am    Post subject: Reply with quote

Thanks for the reply. Is there going to be suport for this in the future? I would think it possible since Int and UInt are both bounded. The types are used for representing integer values, yes? The compiler would just have to be aware that it is representing a numeric value. It'd be useful.

Thanks again!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP