0

I got an issue with promela language when trying to compare an attribute, that is not the first one, of my structure.

Here is an example:

typedef Msg {
    byte header;
    byte content;
}

chan pipe = [5] of { Msg };

active proctype Receive () {
    Msg r;    
    do 
        :: atomic { (pipe?[1,2])    -> printf("Receive"); pipe?r; } 
        // doesnt compile: :: atomic { (pipe?[-,2])    -> printf("Receive2"); pipe?r; }
        // doesn't compile: :: atomic { (pipe?[, 2])    -> printf("Receive3"); pipe?r; }
        // doesn't works: :: atomic { (pipe?[skip, 2])    -> printf("Receive4"); pipe?r; }
    od        

}



active proctype Emit () {
    Msg m;
    m.header=1; m.content=2; 
    // doesn't compile: m = { 1,2 };
    do 
    :: atomic { printf ("emit\n"); pipe!m; }                                                                                                                                        
    od                                                                                                                                                                              
}

The problem is very easy: i would like to compare only the content attribute. Not the previous one (header). I tried some syntax, take a look at the grammar (http://spinroot.com/spin/Man/grammar.html#recv_args ... btw, i'm not an expert). But i'm still stuck with this issue.

I use ispin to simulate and test.

Any helps would be great.

Thanks!

GoZoner
  • 67,920
  • 20
  • 95
  • 145
AilurusFulgens
  • 199
  • 1
  • 12

1 Answers1

1

You can't use a 'generic match character', such as '-', in a receive. So, just declare a variable, as such:

active proctype Receive () {
    Msg r;
    byte ignore
    do 
        :: atomic { (pipe?[1,2])    -> printf("Receive"); pipe?r; } 
        :: atomic { (pipe?[ignore,2])    -> printf("Receive2"); pipe?r; }
    od        

}

It compiles:

$ spin -a foo.ml
$ 
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • Thanks it works. But it sounds weird... can you explain me the fact that ``ignore`` which is uninitialized pass the test ? – AilurusFulgens Feb 11 '16 at 08:46
  • `pipe?[ignore,2]` only requires the `2` to match; `ignore` gets filled in with the value of the first field. – GoZoner Feb 11 '16 at 17:48