module CC.Reduction where
open import Data.Nat
open import Data.Unit using (β€; tt)
open import Data.Bool using (true; false) renaming (Bool to πΉ)
open import Data.List hiding ([_])
open import Data.Product renaming (_,_ to β¨_,_β©)
open import Data.Maybe
open import Relation.Nullary using (Β¬_; Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_β‘_; refl)
open import Common.Utils
open import Common.Types
open import CC.CCStatics
open import Memory.Heap Term Value
open import CC.ApplyCast public
open import CC.ProxyElimination public
open import CC.Frame public
infix 2 _β£_β£_ββ_β£_
data _β£_β£_ββ_β£_ : Term β Heap β StaticLabel β Term β Heap β Set where
ΞΎ : β {M Mβ² F ΞΌ ΞΌβ² pc}
β M β£ ΞΌ β£ pc ββ Mβ² β£ ΞΌβ²
β plug M F β£ ΞΌ β£ pc ββ plug Mβ² F β£ ΞΌβ²
ΞΎ-err : β {F ΞΌ pc e}
β plug (error e) F β£ ΞΌ β£ pc ββ error e β£ ΞΌ
prot-val : β {V ΞΌ pc β}
β (v : Value V)
β prot β V β£ ΞΌ β£ pc ββ stamp-val V v β β£ ΞΌ
prot-ctx : β {M Mβ² ΞΌ ΞΌβ² pc β}
β M β£ ΞΌ β£ pc β β ββ Mβ² β£ ΞΌβ²
β prot β M β£ ΞΌ β£ pc ββ prot β Mβ² β£ ΞΌβ²
prot-err : β {ΞΌ pc β e}
β prot β (error e) β£ ΞΌ β£ pc ββ error e β£ ΞΌ
Ξ² : β {V N ΞΌ pc pcβ² A β}
β Value V
β (Ζβ¦ pcβ² β§ A Λ N of β) Β· V β£ ΞΌ β£ pc ββ prot β (N [ V ]) β£ ΞΌ
Ξ²-if-true : β {M N ΞΌ pc A β}
β if ($ true of β) A M N β£ ΞΌ β£ pc ββ prot β M β£ ΞΌ
Ξ²-if-false : β {M N ΞΌ pc A β}
β if ($ false of β) A M N β£ ΞΌ β£ pc ββ prot β N β£ ΞΌ
Ξ²-let : β {V N ΞΌ pc}
β Value V
β `let V N β£ ΞΌ β£ pc ββ N [ V ] β£ ΞΌ
ref-static : β {M ΞΌ pc β}
β refβ¦ β β§ M β£ ΞΌ β£ pc ββ refββ¦ β β§ M β£ ΞΌ
ref?-ok : β {M ΞΌ pc β}
β pc βΌ β
β ref?β¦ β β§ M β£ ΞΌ β£ pc ββ refββ¦ β β§ M β£ ΞΌ
ref?-fail : β {M ΞΌ pc β}
β Β¬ pc βΌ β
β ref?β¦ β β§ M β£ ΞΌ β£ pc ββ error nsu-error β£ ΞΌ
ref : β {V ΞΌ pc n β}
β (v : Value V)
β aβ¦ β β§ n FreshIn ΞΌ
β refββ¦ β β§ V β£ ΞΌ β£ pc ββ addr (aβ¦ β β§ n) of low β£ cons-ΞΌ (aβ¦ β β§ n) V v ΞΌ
deref : β {V ΞΌ pc v n β βΜ}
β lookup-ΞΌ ΞΌ (aβ¦ βΜ β§ n) β‘ just (V & v)
β ! (addr (aβ¦ βΜ β§ n) of β) β£ ΞΌ β£ pc ββ prot (βΜ β β) V β£ ΞΌ
assign-static : β {L M ΞΌ pc}
β L := M β£ ΞΌ β£ pc ββ L :=β M β£ ΞΌ
assign?-ok : β {M ΞΌ pc n β βΜ}
β pc βΌ βΜ
β (addr (aβ¦ βΜ β§ n) of β) :=? M β£ ΞΌ β£ pc ββ (addr (aβ¦ βΜ β§ n) of β) :=β M β£ ΞΌ
assign?-fail : β {M ΞΌ pc n β βΜ}
β Β¬ pc βΌ βΜ
β (addr (aβ¦ βΜ β§ n) of β) :=? M β£ ΞΌ β£ pc ββ error nsu-error β£ ΞΌ
assign : β {V ΞΌ pc n β βΜ}
β (v : Value V)
β (addr (aβ¦ βΜ β§ n) of β) :=β V β£ ΞΌ β£ pc ββ $ tt of low β£ cons-ΞΌ (aβ¦ βΜ β§ n) V v ΞΌ
cast : β {A B V M ΞΌ pc} {c : Cast A β B}
β Value V β Active c
β ApplyCast V , c β M
β V β¨ c β© β£ ΞΌ β£ pc ββ M β£ ΞΌ
if-cast-true : β {M N ΞΌ pc A g β} {c : Cast (` Bool of g) β (` Bool of β)}
β Inert c
β if ($ true of β β¨ c β©) A M N β£ ΞΌ β£ pc ββ prot β (cast-pc β M) β¨ branch/c A c β© β£ ΞΌ
if-cast-false : β {M N ΞΌ pc A g β} {c : Cast (` Bool of g) β (` Bool of β)}
β Inert c
β if ($ false of β β¨ c β©) A M N β£ ΞΌ β£ pc ββ prot β (cast-pc β N) β¨ branch/c A c β© β£ ΞΌ
fun-cast : β {V W ΞΌ pc A B C D gcβ gcβ gβ gβ} {c : Cast (β¦ gcβ β§ A β B of gβ) β (β¦ gcβ β§ C β D of gβ)}
β Value V β Value W
β (i : Inert c)
β (V β¨ c β©) Β· W β£ ΞΌ β£ pc ββ elim-fun-proxy V W i pc β£ ΞΌ
deref-cast : β {V ΞΌ pc A B gβ gβ} {c : Cast (Ref A of gβ) β (Ref B of gβ)}
β Value V
β Inert c
β ! (V β¨ c β©) β£ ΞΌ β£ pc ββ ! V β¨ out/c c β© β£ ΞΌ
assign?-cast : β {V M ΞΌ pc A B gβ gβ} {c : Cast (Ref A of gβ) β (Ref B of gβ)}
β Value V
β (i : Inert c)
β (V β¨ c β©) :=? M β£ ΞΌ β£ pc ββ elim-ref-proxy V M i _:=?_ β£ ΞΌ
assign-cast : β {V W ΞΌ pc A B gβ gβ} {c : Cast (Ref A of gβ) β (Ref B of gβ)}
β Value V β Value W
β (i : Inert c)
β (V β¨ c β©) :=β W β£ ΞΌ β£ pc ββ elim-ref-proxy V W i _:=β_ β£ ΞΌ
Ξ²-cast-pc : β {V ΞΌ pc g}
β Value V
β cast-pc g V β£ ΞΌ β£ pc ββ V β£ ΞΌ