module Simulator.CheckPrecision where
open import Data.Nat
open import Data.Bool renaming (Bool to πΉ; _β_ to _βα΅_)
open import Data.Unit using (β€; tt)
open import Data.Maybe
open import Data.Product using (_Γ_; β; β-syntax) renaming (_,_ to β¨_,_β©)
open import Data.List hiding ([_])
open import Function using (case_of_)
open import Relation.Nullary using (Β¬_; Dec; yes; no)
open import Relation.Nullary.Decidable using (isYes)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary.PropositionalEquality
using (_β‘_; _β’_; refl; trans; sym; subst; cong; congβ)
open import Common.Utils
open import Common.Types
open import Memory.Addr
open import CC.Errors
open import Simulator.AST
check-β? : (t tβ² : AST) β πΉ
check-β? (castpc _ t _) tβ² = check-β? t tβ²
check-β? t (castpc _ tβ² _) = check-β? t tβ²
check-β? (var x _) (var y _) = isYes (x β y)
check-β? (const {ΞΉ} k β _) (const {ΞΉβ²} kβ² ββ² _) =
case ` ΞΉ β‘α΅£? ` ΞΉβ² of Ξ» where
(yes refl) β (isYes (const-eq? k kβ²)) β§ (isYes (β =? ββ²))
(no _) β false
check-β? (addr a β _) (addr aβ² ββ² _) =
(isYes (addr-eq? a aβ²)) β§ (isYes (β =? ββ²))
check-β? (lam βαΆ A t β _) (lam βαΆβ² Aβ² tβ² ββ² _) =
(isYes (βαΆ =? βαΆβ²)) β§ (isYes (β =? ββ²)) β§
(isYes (A β? Aβ²)) β§ (check-β? t tβ²)
check-β? (app tβ tβ _) (app tββ² tββ² _) = (check-β? tβ tββ²) β§ (check-β? tβ tββ²)
check-β? (cond tβ tβ tβ _) (cond tββ² tββ² tββ² _) =
(check-β? tβ tββ²) β§ (check-β? tβ tββ²) β§ (check-β? tβ tββ²)
check-β? (let-bind tβ tβ _) (let-bind tββ² tββ² _) =
(check-β? tβ tββ²) β§ (check-β? tβ tββ²)
check-β? (ref β t _) (ref ββ² tβ² _) = isYes (β =? ββ²) β§ (check-β? t tβ²)
check-β? (ref? β t _) (ref? ββ² tβ² _) = isYes (β =? ββ²) β§ (check-β? t tβ²)
check-β? (ref? β t _) (ref ββ² tβ² _) = isYes (β =? ββ²) β§ (check-β? t tβ²)
check-β? (refβ β t _) (refβ ββ² tβ² _) = isYes (β =? ββ²) β§ (check-β? t tβ²)
check-β? (deref t _) (deref tβ² _) = check-β? t tβ²
check-β? (assign tβ tβ _) (assign tββ² tββ² _) = check-β? tβ tββ² β§ check-β? tβ tββ²
check-β? (assign? tβ tβ _) (assign? tββ² tββ² _) = check-β? tβ tββ² β§ check-β? tβ tββ²
check-β? (assign? tβ tβ _) (assign tββ² tββ² _) = check-β? tβ tββ² β§ check-β? tβ tββ²
check-β? (assign? tβ tβ _) (assignβ tββ² tββ² _) = check-β? tβ tββ² β§ check-β? tβ tββ²
check-β? (assignβ tβ tβ _) (assignβ tββ² tββ² _) = check-β? tβ tββ² β§ check-β? tβ tββ²
check-β? (protect β t _) (protect ββ² tβ² _) =
isYes (β =? ββ²) β§ check-β? t tβ²
check-β? (err nsu-error _) (err nsu-error _) = true
check-β? (cast t A B C) (cast tβ² Aβ² Bβ² Cβ²) =
(isYes (A β? Aβ²) β§ isYes (B β? Bβ²) β§ check-β? t tβ²) β¨
(isYes (A β<:? Cβ²) β§ isYes (B β<:? Cβ²) β§ check-β? t (cast tβ² Aβ² Bβ² Cβ²)) β¨
(isYes (C β? Aβ²) β§ isYes (C β? Bβ²) β§ check-β? (cast t A B C) tβ²)
check-β? (cast t A B C) (err (blame p) Aβ²) =
(isYes (A β? Aβ²) β§ isYes (B β? Aβ²) β§ check-β? t (err (blame p) Aβ²)) β¨
(isYes (C β? Aβ²))
check-β? (cast t A B C) tβ² =
let Cβ² = get-type tβ² in
isYes (A β<:? Cβ²) β§ isYes (B β<:? Cβ²) β§ check-β? t tβ²
check-β? t (cast tβ² Aβ² Bβ² Cβ²) =
let C = get-type t in
isYes (C β? Aβ²) β§ isYes (C β? Bβ²) β§ check-β? t tβ²
check-β? t (err (blame p) Aβ²) =
let A = get-type t in
isYes (A β? Aβ²)
check-β? _ _ = false