2026-04-19 04:17:45 +00:00
|
|
|
|
import BidirTT.Value
|
|
|
|
|
|
|
|
|
|
|
|
namespace BidirTT
|
|
|
|
|
|
|
|
|
|
|
|
structure Cxt where
|
|
|
|
|
|
env : Env
|
|
|
|
|
|
types : List (Name × Val)
|
|
|
|
|
|
lvl : Lvl
|
|
|
|
|
|
deriving Inhabited
|
|
|
|
|
|
|
|
|
|
|
|
def Cxt.empty : Cxt := ⟨[], [], 0⟩
|
|
|
|
|
|
|
|
|
|
|
|
def Cxt.bind (cxt : Cxt) (x : Name) (a : Val) : Cxt :=
|
2026-04-19 15:03:40 +00:00
|
|
|
|
{ env := .neu (.var cxt.lvl) :: cxt.env
|
2026-04-19 04:17:45 +00:00
|
|
|
|
, types := (x, a) :: cxt.types
|
|
|
|
|
|
, lvl := cxt.lvl + 1 }
|
|
|
|
|
|
|
|
|
|
|
|
def Cxt.define (cxt : Cxt) (x : Name) (v a : Val) : Cxt :=
|
|
|
|
|
|
{ env := v :: cxt.env
|
|
|
|
|
|
, types := (x, a) :: cxt.types
|
|
|
|
|
|
, lvl := cxt.lvl + 1 }
|
|
|
|
|
|
|
|
|
|
|
|
private def lookupGo : Name → List (Name × Val) → Nat → Option (Nat × Val)
|
|
|
|
|
|
| _, [], _ => none
|
|
|
|
|
|
| x, (y, a) :: rest, i => if x == y then some (i, a) else lookupGo x rest (i+1)
|
|
|
|
|
|
|
|
|
|
|
|
def Cxt.lookup (cxt : Cxt) (x : Name) : Option (Nat × Val) :=
|
|
|
|
|
|
lookupGo x cxt.types 0
|
|
|
|
|
|
|
|
|
|
|
|
end BidirTT
|