2024-11-30 20:34:09 -08:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
|
|
|
|
|
|
module IR where
|
|
|
|
|
|
|
|
|
|
import Control.Lens
|
|
|
|
|
|
|
|
|
|
type Param = (Text, IRExpr)
|
|
|
|
|
|
|
|
|
|
data IRExpr
|
|
|
|
|
= Var {_varName :: Text}
|
|
|
|
|
| Level {_level :: Integer}
|
|
|
|
|
| App
|
|
|
|
|
{ _appFunc :: IRExpr
|
|
|
|
|
, _appArg :: IRExpr
|
|
|
|
|
}
|
|
|
|
|
| Abs
|
|
|
|
|
{ _absParamName :: Text
|
|
|
|
|
, _absParamType :: IRExpr
|
|
|
|
|
, _absBody :: IRExpr
|
|
|
|
|
}
|
|
|
|
|
| Pi
|
|
|
|
|
{ _piParamName :: Text
|
|
|
|
|
, _piParamType :: IRExpr
|
|
|
|
|
, _piBody :: IRExpr
|
|
|
|
|
}
|
|
|
|
|
| Let
|
|
|
|
|
{ _letVarName :: Text
|
|
|
|
|
, _letAscription :: Maybe IRExpr
|
|
|
|
|
, _letValue :: IRExpr
|
|
|
|
|
, _letBody :: IRExpr
|
|
|
|
|
}
|
|
|
|
|
deriving (Show, Eq, Ord)
|
|
|
|
|
|
|
|
|
|
makeLenses ''IRExpr
|
|
|
|
|
|
2024-11-30 21:05:07 -08:00
|
|
|
data IRDef
|
|
|
|
|
= Def
|
|
|
|
|
{ _defName :: Text
|
|
|
|
|
, _defParams :: [Param]
|
|
|
|
|
, _defAscription :: Maybe IRExpr
|
|
|
|
|
, _defBody :: IRExpr
|
|
|
|
|
}
|
|
|
|
|
| Axiom
|
|
|
|
|
{ _axiomName :: Text
|
|
|
|
|
, _axiomParams :: [Param]
|
|
|
|
|
, _axiomAscription :: IRExpr
|
|
|
|
|
}
|
2024-11-30 20:34:09 -08:00
|
|
|
|
|
|
|
|
type IRProgram = [IRDef]
|