[关闭]
@nrailgun 2015-09-29T15:22:48.000000Z 字数 1141 阅读 2322

Promela / spin 正规化方法

强力软件


Promela / spin 是实现正规化方法进行模型检查的工具。

proctype

  1. active proctype P() {
  2. printf("hello, world\n");
  3. }

data types

Sorry, there is no such thing as float point number for promela.

control statements

selection

  1. if
  2. :: a < b ->
  3. printf("<");
  4. :: a > b ->
  5. printf(">");
  6. :: else ->
  7. printf("==");
  8. fi

If multiple guards are true, spin will choose one randomly ! If none of the guards are true, then the process will be blocked.

repetition

  1. do
  2. :: a > b -> a = a - b
  3. :: b > a -> b = b - a
  4. :: a == b -> break
  5. od

for-loops

Em, this looks more tidy than do pair.

  1. int i;
  2. int sum = 0;
  3. for (i : 1 .. 5 ) {
  4. sum = sum + i;
  5. }

array

You can use for-each syntax like Java.

  1. byte a[5];
  2. int sum = 0;
  3. for (i in a) {
  4. sum = sum + a [i]
  5. }

jumps

Here comes the famous goto.

  1. active proctype P() {
  2. do
  3. :: i > 5 ->
  4. goto exitloop;
  5. :: else ->
  6. sum = sum + i;
  7. i++;
  8. od;
  9. exitloop:
  10. printf ("end")
  11. }

inline code

Promela has no methods or procedure calls. You have to use inline code.

  1. inline foo(bar) {
  2. printf(bar);
  3. }
  4. active proctype P() {
  5. foo("!");
  6. }

atomicity

atomic

Looks like Java synchronized keyword, which protects critical areas from being executed by multiple processes at the same time.

  1. atomic {
  2. if
  3. :: a != 0 ->
  4. c = b / a
  5. :: else ->
  6. c = b
  7. fi
  8. }

d_step

Like atomic but has strong atomicity.

  1. d_step {
  2. tmp = b;
  3. b = tmp + 1;
  4. }

details

anonymous variable

They are doomed to abandoned. Anonymous variable _ ignore assignments.

  1. chan c;
  2. c ? _;
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注