Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Local Open Scope Z.
Local Open Scope logic.
Definition object_invariant := list Z -> val -> mpred.
Definition tobject := tptr (Tstruct _object noattr).
Definition reset_spec (instance: object_invariant) :=
WITH self: val, history: list Z
PRE [ _self OF tobject]
PROP ()
LOCAL (temp _self self)
SEP (instance history self)
POST [ tvoid ]
PROP() LOCAL () SEP(instance nil self).
Definition twiddle_spec (instance: object_invariant) :=
WITH self: val, i: Z, history: list Z
PRE [ _self OF tobject, _i OF tint]
PROP (0 < i <= Int.max_signed / 4;
0 <= fold_right Z.add 0 history <= Int.max_signed / 4)
LOCAL (temp _self self; temp _i (Vint (Int.repr i)))
SEP (instance history self)
POST [ tint ]
EX v: Z,
PROP(2* fold_right Z.add 0 history < v <= 2* fold_right Z.add 0 (i::history))
LOCAL (temp ret_temp (Vint (Int.repr v)))
SEP(instance (i::history) self).
Definition object_methods (instance: object_invariant) (mtable: val) : mpred :=
EX sh: share, EX reset: val, EX twiddle: val,
!! readable_share sh &&
func_ptr' (reset_spec instance) reset *
func_ptr' (twiddle_spec instance) twiddle *
data_at sh (Tstruct _methods noattr) (reset,twiddle) mtable.

(* Specifications: *)
Lemma object_methods_local_facts: forall instance p,
object_methods instance p |-- !! isptr p.