module CC.BigStep 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
infix 2 _β£_β’_β_β£_
data _β£_β’_β_β£_ : Heap β StaticLabel β (M V : Term) β Heap β Set
β-value : β {ΞΌ ΞΌβ² pc M V} β ΞΌ β£ pc β’ M β V β£ ΞΌβ² β Value V
data _β£_β’_β_β£_ where
β-val : β {ΞΌ pc V}
β Value V
β ΞΌ β£ pc β’ V β V β£ ΞΌ
β-app : β {ΞΌ ΞΌβ ΞΌβ ΞΌβ pc pcβ² L M N V W A β}
β ΞΌ β£ pc β’ L β Ζβ¦ pcβ² β§ A Λ N of β β£ ΞΌβ
β ΞΌβ β£ pc β’ M β V β£ ΞΌβ
β (βW : ΞΌβ β£ pc β β β’ N [ V ] β W β£ ΞΌβ)
β ΞΌ β£ pc β’ L Β· M β stamp-val W (β-value βW) β β£ ΞΌβ
β-if-true : β {ΞΌ ΞΌβ ΞΌβ pc L M N V A β}
β ΞΌ β£ pc β’ L β $ true of β β£ ΞΌβ
β (βV : ΞΌβ β£ pc β β β’ M β V β£ ΞΌβ)
β ΞΌ β£ pc β’ if L A M N β stamp-val V (β-value βV) β β£ ΞΌβ
β-if-false : β {ΞΌ ΞΌβ ΞΌβ pc L M N V A β}
β ΞΌ β£ pc β’ L β $ false of β β£ ΞΌβ
β (βV : ΞΌβ β£ pc β β β’ N β V β£ ΞΌβ)
β ΞΌ β£ pc β’ if L A M N β stamp-val V (β-value βV) β β£ ΞΌβ
β-let : β {ΞΌ ΞΌβ ΞΌβ pc M N V W}
β ΞΌ β£ pc β’ M β V β£ ΞΌβ
β ΞΌβ β£ pc β’ N [ V ] β W β£ ΞΌβ
β ΞΌ β£ pc β’ `let M N β W β£ ΞΌβ
β-ref? : β {ΞΌ ΞΌβ pc M V n β}
β (βV : ΞΌ β£ pc β’ M β V β£ ΞΌβ)
β aβ¦ β β§ n FreshIn ΞΌβ
β pc βΌ β
β ΞΌ β£ pc β’ ref?β¦ β β§ M β addr aβ¦ β β§ n of low β£ cons-ΞΌ (aβ¦ β β§ n) V (β-value βV) ΞΌβ
β-ref : β {ΞΌ ΞΌβ pc M V n β}
β (βV : ΞΌ β£ pc β’ M β V β£ ΞΌβ)
β aβ¦ β β§ n FreshIn ΞΌβ
β ΞΌ β£ pc β’ refβ¦ β β§ M β addr aβ¦ β β§ n of low β£ cons-ΞΌ (aβ¦ β β§ n) V (β-value βV) ΞΌβ
β-deref : β {ΞΌ ΞΌβ pc M V v n β βΜ}
β ΞΌ β£ pc β’ M β addr aβ¦ βΜ β§ n of β β£ ΞΌβ
β lookup-ΞΌ ΞΌβ (aβ¦ βΜ β§ n) β‘ just (V & v)
β ΞΌ β£ pc β’ ! M β stamp-val V v (βΜ β β) β£ ΞΌβ
β-assign? : β {ΞΌ ΞΌβ ΞΌβ pc L M V n β βΜ}
β ΞΌ β£ pc β’ L β addr aβ¦ βΜ β§ n of β β£ ΞΌβ
β (βV : ΞΌβ β£ pc β’ M β V β£ ΞΌβ)
β pc βΌ βΜ
β ΞΌ β£ pc β’ L :=? M β $ tt of low β£ cons-ΞΌ (aβ¦ βΜ β§ n) V (β-value βV) ΞΌβ
β-assign : β {ΞΌ ΞΌβ ΞΌβ pc L M V n β βΜ}
β ΞΌ β£ pc β’ L β addr aβ¦ βΜ β§ n of β β£ ΞΌβ
β (βV : ΞΌβ β£ pc β’ M β V β£ ΞΌβ)
β ΞΌ β£ pc β’ L := M β $ tt of low β£ cons-ΞΌ (aβ¦ βΜ β§ n) V (β-value βV) ΞΌβ
β-cast : β {ΞΌ ΞΌβ ΞΌβ pc M N V W A B} {c : Cast A β B}
β Active c
β ΞΌ β£ pc β’ M β V β£ ΞΌβ
β ApplyCast V , c β N
β ΞΌβ β£ pc β’ N β W β£ ΞΌβ
β ΞΌ β£ pc β’ M β¨ c β© β W β£ ΞΌβ
β-if-cast-true : β {ΞΌ ΞΌβ ΞΌβ ΞΌβ pc L M N V W A g β}
{c : Cast (` Bool of g) β (` Bool of β)}
β Inert c
β ΞΌ β£ pc β’ L β $ true of β β¨ c β© β£ ΞΌβ
β (βV : ΞΌβ β£ pc β β β’ M β V β£ ΞΌβ)
β ΞΌβ β£ pc β’ stamp-val V (β-value βV) β β¨ branch/c A c β© β W β£ ΞΌβ
β ΞΌ β£ pc β’ if L A M N β W β£ ΞΌβ
β-if-cast-false : β {ΞΌ ΞΌβ ΞΌβ ΞΌβ pc L M N V W A g β}
{c : Cast (` Bool of g) β (` Bool of β)}
β Inert c
β ΞΌ β£ pc β’ L β $ false of β β¨ c β© β£ ΞΌβ
β (βV : ΞΌβ β£ pc β β β’ N β V β£ ΞΌβ)
β ΞΌβ β£ pc β’ stamp-val V (β-value βV) β β¨ branch/c A c β© β W β£ ΞΌβ
β ΞΌ β£ pc β’ if L A M N β W β£ ΞΌβ
β-fun-cast : β {ΞΌ ΞΌβ ΞΌβ ΞΌβ pc L M V Vβ² W A B C D gcβ gcβ gβ gβ}
{c : Cast (β¦ gcβ β§ A β B of gβ) β (β¦ gcβ β§ C β D of gβ)}
β (i : Inert c)
β ΞΌ β£ pc β’ L β V β¨ c β© β£ ΞΌβ
β ΞΌβ β£ pc β’ M β W β£ ΞΌβ
β ΞΌβ β£ pc β’ elim-fun-proxy V W i pc β Vβ² β£ ΞΌβ
β ΞΌ β£ pc β’ L Β· M β Vβ² β£ ΞΌβ
β-deref-cast : β {ΞΌ ΞΌβ ΞΌβ pc M V W A B gβ gβ}
{c : Cast (Ref A of gβ) β (Ref B of gβ)}
β Inert c
β ΞΌ β£ pc β’ M β V β¨ c β© β£ ΞΌβ
β ΞΌβ β£ pc β’ ! V β¨ out/c c β© β W β£ ΞΌβ
β ΞΌ β£ pc β’ ! M β W β£ ΞΌβ
β-assign?-cast : β {ΞΌ ΞΌβ ΞΌβ pc L M V W A B gβ gβ}
{c : Cast (Ref A of gβ) β (Ref B of gβ)}
β (i : Inert c)
β ΞΌ β£ pc β’ L β V β¨ c β© β£ ΞΌβ
β ΞΌβ β£ pc β’ elim-ref-proxy V M i _:=?_ β W β£ ΞΌβ
β ΞΌ β£ pc β’ L :=? M β W β£ ΞΌβ
β-assign-cast : β {ΞΌ ΞΌβ ΞΌβ pc L M V W A B gβ gβ}
{c : Cast (Ref A of gβ) β (Ref B of gβ)}
β (i : Inert c)
β ΞΌ β£ pc β’ L β V β¨ c β© β£ ΞΌβ
β ΞΌβ β£ pc β’ elim-ref-proxy V M i _:=_ β W β£ ΞΌβ
β ΞΌ β£ pc β’ L := M β W β£ ΞΌβ
β-value (β-val v) = v
β-value (β-app _ _ βW) = stamp-val-value (β-value βW)
β-value (β-if-true _ βV) = stamp-val-value (β-value βV)
β-value (β-if-false _ βV) = stamp-val-value (β-value βV)
β-value (β-let _ βV) = β-value βV
β-value (β-ref? _ _ _) = V-addr
β-value (β-ref _ _) = V-addr
β-value (β-deref {v = v} _ _) = stamp-val-value v
β-value (β-assign? _ _ _) = V-const
β-value (β-assign _ _) = V-const
β-value (β-cast _ _ _ βV) = β-value βV
β-value (β-if-cast-true _ _ _ βV) = β-value βV
β-value (β-if-cast-false _ _ _ βV) = β-value βV
β-value (β-fun-cast _ _ _ βV) = β-value βV
β-value (β-deref-cast _ _ βV) = β-value βV
β-value (β-assign?-cast _ _ βV) = β-value βV
β-value (β-assign-cast _ _ βV) = β-value βV
error-not-β : β {ΞΌ ΞΌβ² pc M V} β ΞΌ β£ pc β’ M β V β£ ΞΌβ² β Β¬ Err M
error-not-β (β-val ()) E-error