2020-05-18 18:57:43 +03:00
|
|
|
module Language.Reflection.TT
|
|
|
|
|
2020-06-01 16:26:37 +03:00
|
|
|
import public Data.List
|
|
|
|
|
2021-05-13 14:58:56 +03:00
|
|
|
%default total
|
|
|
|
|
2021-06-05 14:53:22 +03:00
|
|
|
public export
|
|
|
|
data Namespace = MkNS (List String) -- namespace, stored in reverse order
|
|
|
|
|
|
|
|
public export
|
|
|
|
data ModuleIdent = MkMI (List String) -- module identifier, stored in reverse order
|
|
|
|
|
|
|
|
export
|
|
|
|
showSep : String -> List String -> String
|
|
|
|
showSep sep [] = ""
|
|
|
|
showSep sep [x] = x
|
|
|
|
showSep sep (x :: xs) = x ++ sep ++ showSep sep xs
|
|
|
|
|
|
|
|
export
|
|
|
|
Show Namespace where
|
|
|
|
show (MkNS ns) = showSep "." (reverse ns)
|
|
|
|
|
2021-02-21 12:07:12 +03:00
|
|
|
-- 'FilePos' represents the position of
|
|
|
|
-- the source information in the file (or REPL).
|
|
|
|
-- in the form of '(line-no, column-no)'.
|
2020-05-18 18:57:43 +03:00
|
|
|
public export
|
|
|
|
FilePos : Type
|
|
|
|
FilePos = (Int, Int)
|
|
|
|
|
|
|
|
public export
|
2021-06-05 14:53:22 +03:00
|
|
|
data VirtualIdent : Type where
|
|
|
|
Interactive : VirtualIdent
|
|
|
|
|
|
|
|
public export
|
|
|
|
data OriginDesc : Type where
|
|
|
|
||| Anything that originates in physical Idris source files is assigned a
|
|
|
|
||| `PhysicalIdrSrc modIdent`,
|
|
|
|
||| where `modIdent` is the top-level module identifier of that file.
|
|
|
|
PhysicalIdrSrc : (ident : ModuleIdent) -> OriginDesc
|
|
|
|
||| Anything parsed from a package file is decorated with `PhysicalPkgSrc fname`,
|
|
|
|
||| where `fname` is path to the package file.
|
|
|
|
PhysicalPkgSrc : (fname : String) -> OriginDesc
|
|
|
|
Virtual : (ident : VirtualIdent) -> OriginDesc
|
|
|
|
|
|
|
|
||| A file context is a filename together with starting and ending positions.
|
|
|
|
||| It's often carried by AST nodes that might have been created from a source
|
|
|
|
||| file or by the compiler. That makes it useful to have the notion of
|
|
|
|
||| `EmptyFC` as part of the type.
|
|
|
|
public export
|
|
|
|
data FC = MkFC OriginDesc FilePos FilePos
|
|
|
|
| ||| Virtual FCs are FC attached to desugared/generated code. They can help with marking
|
|
|
|
||| errors, but we shouldn't attach semantic highlighting metadata to them.
|
|
|
|
MkVirtualFC OriginDesc FilePos FilePos
|
|
|
|
| EmptyFC
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
emptyFC : FC
|
|
|
|
emptyFC = EmptyFC
|
|
|
|
|
|
|
|
public export
|
|
|
|
data NameType : Type where
|
|
|
|
Bound : NameType
|
|
|
|
Func : NameType
|
|
|
|
DataCon : (tag : Int) -> (arity : Nat) -> NameType
|
|
|
|
TyCon : (tag : Int) -> (arity : Nat) -> NameType
|
|
|
|
|
|
|
|
public export
|
|
|
|
data Constant
|
|
|
|
= I Int
|
|
|
|
| BI Integer
|
2021-06-29 22:58:41 +03:00
|
|
|
| I8 Int8
|
|
|
|
| I16 Int16
|
|
|
|
| I32 Int32
|
|
|
|
| I64 Int64
|
|
|
|
| B8 Bits8
|
|
|
|
| B16 Bits16
|
|
|
|
| B32 Bits32
|
|
|
|
| B64 Bits64
|
2020-05-18 18:57:43 +03:00
|
|
|
| Str String
|
|
|
|
| Ch Char
|
|
|
|
| Db Double
|
|
|
|
| WorldVal
|
|
|
|
|
|
|
|
| IntType
|
|
|
|
| IntegerType
|
2021-06-29 22:58:41 +03:00
|
|
|
| Int8Type
|
|
|
|
| Int16Type
|
|
|
|
| Int32Type
|
|
|
|
| Int64Type
|
2020-06-01 15:39:18 +03:00
|
|
|
| Bits8Type
|
|
|
|
| Bits16Type
|
|
|
|
| Bits32Type
|
|
|
|
| Bits64Type
|
2020-05-18 18:57:43 +03:00
|
|
|
| StringType
|
|
|
|
| CharType
|
|
|
|
| DoubleType
|
|
|
|
| WorldType
|
|
|
|
|
|
|
|
public export
|
2021-09-15 15:20:58 +03:00
|
|
|
data UserName
|
|
|
|
= Basic String -- default name constructor e.g. map
|
|
|
|
| Field String -- field accessor e.g. .fst
|
|
|
|
| Underscore -- no name e.g. _
|
|
|
|
|
|
|
|
public export
|
|
|
|
data Name = NS Namespace Name -- name in a namespace
|
|
|
|
| UN UserName -- user defined name
|
2020-06-07 13:49:19 +03:00
|
|
|
| MN String Int -- machine generated name
|
|
|
|
| DN String Name -- a name and how to display it
|
2020-06-20 08:28:48 +03:00
|
|
|
| Nested (Int, Int) Name -- nested function name
|
2021-07-16 20:48:57 +03:00
|
|
|
| CaseBlock String Int -- case block nested in (resolved) name
|
|
|
|
| WithBlock String Int -- with block nested in (resolved) name
|
2020-05-18 18:57:43 +03:00
|
|
|
|
2021-09-15 15:20:58 +03:00
|
|
|
export
|
|
|
|
Show UserName where
|
|
|
|
show (Basic n) = n
|
|
|
|
show (Field n) = "." ++ n
|
|
|
|
show Underscore = "_"
|
|
|
|
|
2020-06-01 16:26:37 +03:00
|
|
|
export
|
|
|
|
Show Name where
|
2020-09-05 11:41:31 +03:00
|
|
|
show (NS ns n) = show ns ++ "." ++ show n
|
2021-09-15 15:20:58 +03:00
|
|
|
show (UN x) = show x
|
2020-06-01 16:26:37 +03:00
|
|
|
show (MN x y) = "{" ++ x ++ ":" ++ show y ++ "}"
|
2020-06-07 13:49:19 +03:00
|
|
|
show (DN str y) = str
|
2020-06-20 08:28:48 +03:00
|
|
|
show (Nested (outer, idx) inner)
|
|
|
|
= show outer ++ ":" ++ show idx ++ ":" ++ show inner
|
|
|
|
show (CaseBlock outer i) = "case block in " ++ show outer
|
|
|
|
show (WithBlock outer i) = "with block in " ++ show outer
|
2020-06-01 16:26:37 +03:00
|
|
|
|
2021-11-07 18:06:53 +03:00
|
|
|
public export
|
|
|
|
record NameInfo where
|
|
|
|
constructor MkNameInfo
|
|
|
|
nametype : NameType
|
|
|
|
|
2020-05-18 18:57:43 +03:00
|
|
|
public export
|
|
|
|
data Count = M0 | M1 | MW
|
|
|
|
|
|
|
|
public export
|
2020-05-30 00:40:29 +03:00
|
|
|
data PiInfo t = ImplicitArg | ExplicitArg | AutoImplicit | DefImplicit t
|
2020-05-18 18:57:43 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data IsVar : Name -> Nat -> List Name -> Type where
|
|
|
|
First : IsVar n Z (n :: ns)
|
|
|
|
Later : IsVar n i ns -> IsVar n (S i) (m :: ns)
|
|
|
|
|
|
|
|
public export
|
|
|
|
data LazyReason = LInf | LLazy | LUnknown
|
|
|
|
|
2020-05-31 03:36:54 +03:00
|
|
|
export
|
|
|
|
data TT : Type where [external]
|
|
|
|
|
|
|
|
{-
|
2020-05-18 18:57:43 +03:00
|
|
|
-- Type checked terms in the core TT
|
|
|
|
public export
|
|
|
|
data TT : List Name -> Type where
|
2020-05-30 00:40:29 +03:00
|
|
|
Local : FC -> (idx : Nat) -> (0 prf : IsVar name idx vars) -> TT vars
|
2020-05-18 18:57:43 +03:00
|
|
|
Ref : FC -> NameType -> Name -> TT vars
|
2020-05-30 00:40:29 +03:00
|
|
|
Pi : FC -> Count -> PiInfo (TT vars) ->
|
2020-05-18 18:57:43 +03:00
|
|
|
(x : Name) -> (argTy : TT vars) -> (retTy : TT (x :: vars)) ->
|
|
|
|
TT vars
|
2020-05-30 00:40:29 +03:00
|
|
|
Lam : FC -> Count -> PiInfo (TT vars) ->
|
2020-05-18 18:57:43 +03:00
|
|
|
(x : Name) -> (argTy : TT vars) -> (scope : TT (x :: vars)) ->
|
|
|
|
TT vars
|
|
|
|
App : FC -> TT vars -> TT vars -> TT vars
|
|
|
|
TDelayed : FC -> LazyReason -> TT vars -> TT vars
|
|
|
|
TDelay : FC -> LazyReason -> (ty : TT vars) -> (arg : TT vars) -> TT vars
|
2020-05-30 00:40:29 +03:00
|
|
|
TForce : FC -> LazyReason -> TT vars -> TT vars
|
2020-05-18 18:57:43 +03:00
|
|
|
PrimVal : FC -> Constant -> TT vars
|
|
|
|
Erased : FC -> TT vars
|
|
|
|
TType : FC -> TT vars
|
2020-05-31 03:36:54 +03:00
|
|
|
-}
|
2020-05-18 18:57:43 +03:00
|
|
|
|
2020-05-30 00:40:29 +03:00
|
|
|
public export
|
|
|
|
data TotalReq = Total | CoveringOnly | PartialOK
|
|
|
|
|
2020-05-18 18:57:43 +03:00
|
|
|
public export
|
|
|
|
data Visibility = Private | Export | Public
|
2021-07-15 20:28:07 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
data BuiltinType = BuiltinNatural | NaturalToInteger | IntegerToNatural
|