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

Correspondence:
  StmtEvaluator (eval, eval-Monoʳ)  ↦ StmtEvaluator (eval, eval_mono)
  ExprEvaluator (eval, eval-Monoʳ)  ↦ ExprEvaluator (eval, eval_mono)
  IsValidExprEvaluator              ↦ IsValidExprEvaluator
  IsValidStmtEvaluator              ↦ IsValidStmtEvaluator
  ValidExprEvaluator,
  ValidStmtEvaluator (records)      ↦ (the `IsValid…` Props are passed
                                      directly; the wrapper records existed
                                      for Agda instance resolution)
-/
import Spa.Analysis.Forward.Lattices

namespace Spa

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

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

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

variable {L prog}

/-- Agda: `IsValidExprEvaluator`. -/
def IsValidExprEvaluator (E : ExprEvaluator L prog)
    (I : LatticeInterpretation L) : Prop :=
  ∀ {vs : VariableValues L prog} {ρ : Env} {e : Expr} {v : Value},
    EvalExpr ρ e v → interpV I vs ρ → I.interp (E.eval e vs) v

/-- Agda: `IsValidStmtEvaluator`. -/
def IsValidStmtEvaluator (E : StmtEvaluator L prog)
    (I : LatticeInterpretation L) : Prop :=
  ∀ {s : prog.State} {vs : VariableValues L prog} {ρ₁ ρ₂ : Env} {bs : BasicStmt},
    EvalBasicStmt ρ₁ bs ρ₂ → interpV I vs ρ₁ → interpV I (E.eval s bs vs) ρ₂

end Spa
