/-
Port of `Analysis/Forward/Evaluation.agda`.

All four records were consumed through Agda instance arguments (`{{evaluator :
StmtEvaluator}}`, `{{validEvaluator : ValidStmtEvaluator …}}`), so they are
typeclasses here as well.

Correspondence:
  StmtEvaluator (eval, eval-Monoʳ)  ↦ StmtEvaluator (eval, eval_mono)
  ExprEvaluator (eval, eval-Monoʳ)  ↦ ExprEvaluator (eval, eval_mono)
  ValidExprEvaluator                ↦ ValidExprEvaluator (valid)
  ValidStmtEvaluator                ↦ ValidStmtEvaluator (valid)
-/
import Spa.Analysis.Forward.Lattices

namespace Spa

variable (L : Type) [Lattice L] (prog : Program)

/-- Agda: `StmtEvaluator`. -/
class StmtEvaluator where
  eval : prog.State → BasicStmt → VariableValues L prog → VariableValues L prog
  eval_mono : ∀ s bs, Monotone (eval s bs)

/-- Agda: `ExprEvaluator`. -/
class ExprEvaluator where
  eval : Expr → VariableValues L prog → L
  eval_mono : ∀ e, Monotone (eval e)

/-- Agda: `ValidExprEvaluator`. -/
class ValidExprEvaluator [ExprEvaluator L prog] [I : LatticeInterpretation L] :
    Prop where
  valid : ∀ {vs : VariableValues L prog} {ρ : Env} {e : Expr} {v : Value},
    EvalExpr ρ e v → interpV vs ρ → I.interp (ExprEvaluator.eval e vs) v

/-- Agda: `ValidStmtEvaluator`. -/
class ValidStmtEvaluator [E : StmtEvaluator L prog] [LatticeInterpretation L] :
    Prop where
  valid : ∀ {s : prog.State} {vs : VariableValues L prog} {ρ₁ ρ₂ : Env}
    {bs : BasicStmt},
    EvalBasicStmt ρ₁ bs ρ₂ → interpV vs ρ₁ → interpV (E.eval s bs vs) ρ₂

end Spa
