Library topsy_hmInit_old

Load seplog_header.

Open Local Scope sep_scope.
Open Local Scope Z_scope.

Require Import topsy_hm_old.
Require Import frag.

Definition hmInit (adr: loc) (size:nat) :=
  hmStart <- nat_e adr;
  hmStart -.> next *<- nat_e adr +e nat_e size -e int_e 2;
  hmStart -.> status *<- Free;
  hmEnd <-* hmStart -.> next;
  hmEnd -.> next *<- int_e 0;
  hmEnd -.> status *<- Allocated.

Close Local Scope Z_scope.

Open Local Scope heap_scope.

Definition hmInit_specif := forall startp sizep,
   startp > 0 ->
   sizep > 4 ->
   {{ Array startp sizep}}
   
   hmInit startp sizep
   
   {{Heap_List ((startp, sizep - 4, Free)::nil) startp 0}}.

Definition hmInit_precond (adr: loc) (size:nat):=
  (true_b,
      star
      (star (cell (nat_e adr)) (cell (nat_e adr +e int_e 1%Z)))
      (star (cell (nat_e adr +e nat_e size -e int_e 2%Z)) (cell (nat_e adr +e nat_e size -e int_e 1%Z)))
  ).

Definition hmInit_postcond (adr: loc) (size:nat):=
  (true_b,
      star
      (star (singl (nat_e adr) Free) (singl (nat_e adr +e int_e 1%Z) (nat_e adr +e nat_e size -e int_e 2%Z)))
      (star (singl (nat_e adr +e nat_e size -e int_e 2%Z) Allocated) (singl (nat_e adr +e nat_e size -e int_e 1%Z) (nat_e 0)))
  ).

Lemma hmInit_verif : hmInit_specif.