module DDC.Core.Flow.Env
( primDataDefs
, primSortEnv
, primKindEnv
, primTypeEnv)
where
import DDC.Core.Flow.Prim
import DDC.Core.Flow.Compounds
import DDC.Type.DataDef
import DDC.Type.Exp
import DDC.Type.Env (Env)
import qualified DDC.Type.Env as Env
primDataDefs :: DataDefs Name
primDataDefs
= fromListDataDefs
$
[ makeDataDefAlg (NamePrimTyCon PrimTyConBool)
[]
(Just [ (NameLitBool True, [])
, (NameLitBool False, []) ])
, makeDataDefAlg (NamePrimTyCon PrimTyConNat) [] Nothing
, makeDataDefAlg (NamePrimTyCon PrimTyConInt) [] Nothing
, makeDataDefAlg (NamePrimTyCon (PrimTyConFloat 32)) [] Nothing
, makeDataDefAlg (NamePrimTyCon (PrimTyConFloat 64)) [] Nothing
, makeDataDefAlg (NamePrimTyCon (PrimTyConWord 64)) [] Nothing
, makeDataDefAlg (NamePrimTyCon (PrimTyConWord 32)) [] Nothing
, makeDataDefAlg (NamePrimTyCon (PrimTyConWord 16)) [] Nothing
, makeDataDefAlg (NamePrimTyCon (PrimTyConWord 8)) [] Nothing
, makeDataDefAbs
(NameTyConFlow TyConFlowVector)
[BAnon kRate, BAnon kData]
, makeDataDefAbs
(NameTyConFlow TyConFlowSeries)
[BAnon kRate, BAnon kData]
]
++ [ makeTupleDataDef arity
| arity <- [2..32] ]
makeTupleDataDef :: Int -> DataDef Name
makeTupleDataDef n
= makeDataDefAlg
(NameTyConFlow (TyConFlowTuple n))
(replicate n (BAnon kData))
(Just [ ( NameDaConFlow (DaConFlowTuple n)
, (reverse [tIx kData i | i <- [0..n 1]]))])
primSortEnv :: Env Name
primSortEnv = Env.setPrimFun sortOfPrimName Env.empty
sortOfPrimName :: Name -> Maybe (Sort Name)
sortOfPrimName _ = Nothing
primKindEnv :: Env Name
primKindEnv = Env.setPrimFun kindOfPrimName Env.empty
kindOfPrimName :: Name -> Maybe (Kind Name)
kindOfPrimName nn
= case nn of
NameKiConFlow KiConFlowRate -> Just sProp
NameTyConFlow tc -> Just $ kindTyConFlow tc
NamePrimTyCon tc -> Just $ kindPrimTyCon tc
_ -> Nothing
primTypeEnv :: Env Name
primTypeEnv = Env.setPrimFun typeOfPrimName Env.empty
typeOfPrimName :: Name -> Maybe (Type Name)
typeOfPrimName dc
= case dc of
NameOpConcrete p -> Just $ typeOpConcrete p
NameOpSeries p -> Just $ typeOpSeries p
NameOpStore p -> Just $ typeOpStore p
NameOpControl p -> Just $ typeOpControl p
NameOpVector p -> Just $ typeOpVector p
NameDaConFlow p -> Just $ typeDaConFlow p
NamePrimCast p -> Just $ typePrimCast p
NamePrimArith p -> Just $ typePrimArith p
NamePrimVec p -> Just $ typePrimVec p
NameLitBool _ -> Just $ tBool
NameLitNat _ -> Just $ tNat
NameLitInt _ -> Just $ tInt
NameLitWord _ bits -> Just $ tWord bits
NameLitFloat _ bits -> Just $ tFloat bits
_ -> Nothing