Transitions
A transition is an atomic state change: a guard that enables it and an effect that runs when it fires.
transition name(param1 : Type1, param2 : Type2) {
guard: <expression> ;
modifies: x, y ; // optional
effect: <statement> ;
<statement> ; // as many as needed
}- Parameters — each parameter takes its own type annotation; one without an annotation is an
Int. Intransition t(a, b : BV<64>),ais anIntandbaBV<64>. A transition without parameters may omit the parentheses. guard:— a Boolean expression; the transition is enabled only when it holds.modifies:— optional frame clause between the guard and the effect: a comma-separated list of attribute names.effect:— a list of statements, each ending in;, executed in order.
Effect statements#
Assignment#
x := x + 1 ; // simple variable
arr[i] := val ; // indexed
node.state := ACTIVE ; // field
Node(id).state := IDLE ; // field of a parameterised agent instance
Memory(addr) := b ; // call form: same as Memory[addr]Compound assignment#
counter += 1 ; // counter := counter + 1
balance -= amount ; // balance := balance - amountSkip#
skip ;Let binding#
let names a value for the following statements of the effect; it does not change the state.
let result = dst - src ;
dst := result ;Conditional#
if (x > 0) then {
y := 1 ;
z := 2 ;
} else {
y := 0 ;
} ;The condition needs parentheses; each branch is a braced list of statements. The else branch is optional. There is no else if: nest a second if inside the else block.
Bounded loops#
for (j : Int) in [0..n) {
Cache(j).state := INVALID ;
} ;
for 4 times {
counter += 1 ;
} ;for (j : T) in [lo..hi) { … } runs the body for j from lo up to but excluding hi. for e times { … } runs it e times.
Atomic block#
atomic {
lock := 1 ;
owner := id ;
} ;Braced statement lists#
The bodies of if, for, for … times and atomic are braced lists: one or more statements separated by ;, with an optional ; after the last one. An empty block { } and a doubled ;; are errors.
Nondeterministic assignment: havoc#
havoc(x) ; // x gets any value
havoc(x) with { x >= 0 && x < 10 } ; // any value satisfying the constraint
havoc(arr[i]) ; // any assignable target
havoc(X1, X2, Memory) ; // several targets
havoc(X1..X3) ; // a range: X1, X2, X3
havoc(NZCV) ; // the flags N, Z, C and V
havoc(caller_saved) ; // a regset- A
with { … }constraint is allowed only with a single target. - A range
P<lo>..P<hi>needs the same alphabetic prefix on both ends and decimal suffixes withlo≤hi. NZCVstands for the four attributesN,Z,C,V, which must be declared, unless an attribute is itself namedNZCV.- In a list of several targets, every plain name must be a declared attribute, a parameter or a
letlocal, or a regset.
Effects are statement lists
An effect may hold any number of statements. Each statement ends in ;, including the last one and the closing ; after an if, for or atomic block.
Examples#
type NodeState = { IDLE, VALIDATING } ;
type LineState = { INVALID, SHARED } ;
transition selectValidator(slot : Int) {
guard: exists (i : Int) in [0..numNodes) . nodeState[i] == IDLE ;
effect: nodeState[slot] := VALIDATING ;
}
transition cpuReadMiss(core : Int) {
guard: lineState[core] == INVALID ;
modifies: lineState ;
effect: lineState[core] := SHARED ;
}
transition transfer(from : Int, to : Int, amount : Int) {
guard: balances[from] >= amount && amount > 0 ;
modifies: balances ;
effect: balances[from] -= amount ;
balances[to] += amount ;
}
transition sub_op(dst : BV<64>, src : BV<64>) {
guard: true ;
effect: let result = dst - src ;
dst := result ;
if (result == 0x0:BV<64>) then { ZF := 0x1:BV<1> ; } else { ZF := 0x0:BV<1> ; } ;
}