22-- | Definition of λ□ terms.
33module LambdaBox.Term where
44
5+ import Data.Int (Int64 )
56import Data.Bifunctor (first )
67import Agda.Syntax.Common.Pretty
78import LambdaBox.Names
89
910
10- -- | Definition component in a mutual fixpoint.
11+ -- | Definition component in a mutual fixpoint
1112data Def t = Def
1213 { dName :: Name
1314 , dBody :: t
1415 , dArgs :: Int
1516 }
1617
17- -- | Mutual components of a fixpoint.
18+ -- | Mutual components of a fixpoint
1819type MFixpoint = [Def Term ]
1920
21+ -- |
22+ data PrimValue
23+ = PInt Int64
24+ -- NOTE(flupe): ^ Should ensure they are restricted to Int63
25+ | PFloat Int64
26+ | PString String
27+
2028-- | λ□ terms
2129data Term
22- = LBox -- ^ Proofs and erased terms
23- | LRel Int -- ^ Bound variable, with de Bruijn index
24- | LLambda Name Term -- ^ Lambda abstraction
25- | LLetIn Name Term Term
26- -- ^ Let bindings.
27- -- Unused in the backend, since Agda itself no longer has let bindings
28- -- in the concrete syntac.
30+ = LBox -- ^ Proofs and erased terms
31+ | LRel Int -- ^ Bound variable, with de Bruijn index
32+ | LLambda Name Term -- ^ Lambda abstraction
33+ | LLetIn Name Term Term -- ^ Let bindings
2934 | LApp Term Term -- ^ Term application
30- | LConst KerName -- ^ Named constant.
31- | LConstruct Inductive Int [Term ] -- ^ Inductive constructor.
32- | LCase -- ^ Pattern-matching case construct.
33- Inductive -- ^ Inductive type we cae on.
35+ | LConst KerName -- ^ Named constant
36+ | LConstruct Inductive Int [Term ] -- ^ Inductive constructor
37+ | LCase -- ^ Pattern-matching case construct
38+ Inductive -- ^ Inductive type we case on
3439 Int -- ^ Number of parameters
3540 Term -- ^ Discriminee
3641 [([Name ], Term )] -- ^ Branches
37- | LFix -- ^ Fixpoint combinator.
42+ | LFix -- ^ Fixpoint combinator
3843 MFixpoint
39- Int -- ^ Index of the fixpoint we keep.
44+ Int -- ^ Index of the fixpoint we keep
45+ | LPrim PrimValue
46+ -- ^ Primitive literal value
4047
4148
4249instance Pretty t => Pretty (Def t ) where
4350 -- prettyPrec _ (Def s _ _) = pretty s
4451 prettyPrec _ (Def _ t _) = pretty t
4552
53+
54+ instance Pretty PrimValue where
55+ pretty (PInt i) = text $ show i
56+ pretty (PFloat f) = text $ show f
57+ pretty (PString f) = text $ show f
58+
59+
4660instance Pretty Term where
4761 prettyPrec p v =
4862 case v of
@@ -59,7 +73,6 @@ instance Pretty Term where
5973 in
6074 mparens (p > 0 ) $
6175 hang (" λ" <+> sep (map pretty (n: ns)) <+> " →" ) 2 $ pretty t'
62-
6376
6477 LLetIn n e t ->
6578 mparens (p > 0 ) $ sep
@@ -85,3 +98,6 @@ instance Pretty Term where
8598 LFix ds i -> -- FIXME: for mutual recursion
8699 mparens (p > 0 ) $
87100 hang " μ rec ->" 2 $ pretty $ ds !! i
101+
102+ LPrim p -> pretty p
103+
0 commit comments