{-# OPTIONS --guardedness #-}
module SMT.Theories.Core.Reflection where
open import Data.Empty as Empty using (⊥)
open import Data.Bool.Base as Bool using (Bool; false; true)
open import Data.List.Base as List using (List; _∷_; [])
open import Data.Maybe as Maybe using (Maybe; nothing; just)
open import Data.Product as Prod using (Σ-syntax; _,_; _×_)
open import Data.Sum as Sum using (_⊎_)
open import Data.Unit as Unit using (⊤)
open import Function using (Morphism)
import Reflection as Rfl
open import Relation.Nullary using (¬_)
open import SMT.Theory
open import SMT.Theories.Core.Base as Core
open import SMT.Script.Base Core.theory renaming ( Macro to CoreMacro )
coreSorts : List CoreSort
coreSorts = BOOL ∷ []
checkCoreSort : Rfl.Term → Maybe CoreSort
checkCoreSort (Rfl.agda-sort _) = just BOOL
checkCoreSort _ = nothing
checkCoreLiteral : (φ : CoreSort) → Rfl.Literal → Maybe (CoreLiteral φ)
checkCoreLiteral _ _ = nothing
private
pattern `false = quote ⊥
pattern `true = quote ⊤
pattern `not = quote ¬_
pattern `implies = quote Morphism
pattern `and = quote _×_
pattern `or = quote _⊎_
checkCoreIdentifier′ : (φ : CoreSort) → Rfl.Name → Maybe (Σ[ Φ ∈ Signature φ ] CoreIdentifier Φ)
checkCoreIdentifier′ BOOL `false = just (Op₀ BOOL , false)
checkCoreIdentifier′ BOOL `true = just (Op₀ BOOL , true)
checkCoreIdentifier′ BOOL `not = just (Op₁ BOOL , not)
checkCoreIdentifier′ BOOL `implies = just (Op₂ BOOL , implies)
checkCoreIdentifier′ BOOL `and = just (Op₂ BOOL , and)
checkCoreIdentifier′ BOOL `or = just (Op₂ BOOL , or)
checkCoreIdentifier′ BOOL _ = nothing
checkCoreIdentifier : (φ : CoreSort) → Rfl.Name → Maybe (Σ[ Φ ∈ Signature φ ] CoreMacro Φ)
checkCoreIdentifier φ n = Maybe.map (Prod.map₂ λ {Φ} f args → `app f args) (checkCoreIdentifier′ φ n)
coreProofComputation : ∀ {Γ} → Term Γ BOOL → Rfl.Name
coreProofComputation _ = quote Function.id
instance
coreReflectable : Reflectable theory
Reflectable.sorts coreReflectable = coreSorts
Reflectable.checkSort coreReflectable = checkCoreSort
Reflectable.checkLiteral coreReflectable = checkCoreLiteral
Reflectable.checkIdentifier coreReflectable = checkCoreIdentifier
Reflectable.proofComputation coreReflectable = coreProofComputation