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 

Error: negated pattern matching in rule's guard

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



Joined: 24 Feb 2011
Posts: 9

PostPosted: Fri Jun 20, 2014 11:35 am    Post subject: Error: negated pattern matching in rule's guard Reply with quote

Hi,

When I use pattern matching in a rule's guard, it works fine:

Code:
rule r1 ( fifo.first matches tagged TAG_A .v );


I also want rule r2 to not trigger in that particular case:

Code:
rule r2 ( ! ( fifo.first matches tagged TAG_A .v ) );


However, the compiler gives the following error:

Quote:
Error: "path/to/file.bsv", line XXXX, column YY: (P0005)
Unexpected `)'; expected `&&&' or `?'


Which is the position for the inner closing ')'. Am I doing anything wrong or the compiler does not allow to negate a pattern matching? If so, how could I do it? I used the following workaround:

Code:
Wire#(Bool) matchesW <- mkDWire(False);

rule aux ( fifo.first matches tagged TAG_A .v );
  matchesW <= True;
endrule

rule r2 ( !matchesW );
  ...
endrule
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 499

PostPosted: Fri Jun 20, 2014 12:03 pm    Post subject: Re: Error: negated pattern matching in rule's guard Reply with quote

The "matches" statement is not a Boolean expression, so you can't apply the negation operator to it.

(In fact, this shows up as a parser error and not a type-checking error, because the "matches" statement isn't a basic expression -- you can't use it just anywhere that an expression can go. It's a special kind of statement, that can only be used in certain places. And the predicate clause for a rule doesn't just take basic expressions, it takes pattern statements, separated by the "&&&" operator. It happens that a basic expression counts as a pattern statement, and so most rules have basic expressions as their predicate clause.)

What you probably want to do is write a function, that does the pattern matching and computes a Boolean result based on the match:
Code:
function Bool hasTagA(MyType val);
   if (val matches tagged TAG_A .v)
      return True;
   else
      return False;
endfunction

rule r2 ( ! hasTagA(fifo.first) );

Which you could also write inline, using the conditional operator:
Code:
rule r2 ( fifo.first matches tagged TAG_A .v ? False : True );


Although, if what you want is for rule r2 to execute when rule r1 does not execute, then you can also achieve that using the "preempts" scheduling attribute:
Code:
(* preempts = "r1, r2" *)
rule r2;
Back to top
View user's profile Send private message
oarcas



Joined: 24 Feb 2011
Posts: 9

PostPosted: Mon Jun 30, 2014 11:27 am    Post subject: Re: Error: negated pattern matching in rule's guard Reply with quote

Thank you for your answer, I will try these methods.

Oriol
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