POCS.Lab0.ThreeVariablesAPI
Specification of variables.
Inductive var :=
| VarX
| VarY
| VarZ.
Instance var_eq : EqualDec var.
Proof.
hnf.
destruct x, y; simpl;
(left; congruence) || (right; congruence).
Defined.
| VarX
| VarY
| VarZ.
Instance var_eq : EqualDec var.
Proof.
hnf.
destruct x, y; simpl;
(left; congruence) || (right; congruence).
Defined.
The values of these variables comprise the state:
Definition StateVar (v:var) (state:State) : nat :=
match v with
| VarX => StateX state
| VarY => StateY state
| VarZ => StateZ state
end.
match v with
| VarX => StateX state
| VarY => StateY state
| VarZ => StateZ state
end.
Operations on variables.
The postcondition has two parts to it. First, it says
that the resulting state after reading a variable, state',
is the same as the state before reading the variable, state.
In other words, reading a variable doesn't change the state.
The second part of the postcondition says that the return
value r is the value of the variable v in the state.
Since our framework supports reasoning about crashes, we must
supply a recovered condition, but here we will ignore crashes
by saying that recovery can never occur, by stating False.
The specification for writing a variable, write_spec is
parametrized by two things: the variable being modified, v,
and the value being written to that variable, val.
The precondition and recovery condition are the same as for
reading (True and False respectively).
The postcondition says that the return value is always equal
to tt (a way of representing a procedure that has no return
value), and
the new state, state', is updated based on which variable
we were trying to modify.
match v with
| VarX => state' = mkState val (StateY state) (StateZ state)
| VarY => state' = mkState (StateX state) val (StateZ state)
| VarZ => state' = mkState (StateX state) (StateY state) val
end;
recovered := fun _ _ => False
|}.
| VarX => state' = mkState val (StateY state) (StateZ state)
| VarY => state' = mkState (StateX state) val (StateZ state)
| VarZ => state' = mkState (StateX state) (StateY state) val
end;
recovered := fun _ _ => False
|}.
Variables module
Module Type VarsAPI.
Axiom init : proc InitResult.
Axiom read : var -> proc nat.
Axiom write : var -> nat -> proc unit.
Axiom recover : proc unit.
Axiom abstr : Abstraction State.
Axiom init_ok : init_abstraction init recover abstr inited_any.
Axiom read_ok : forall v, proc_spec (read_spec v) (read v) recover abstr.
Axiom write_ok : forall v val, proc_spec (write_spec v val) (write v val) recover abstr.
Axiom recover_wipe : rec_wipe recover abstr no_crash.
Hint Resolve init_ok : core.
Hint Resolve read_ok : core.
Hint Resolve write_ok : core.
Hint Resolve recover_wipe : core.
End VarsAPI.