%
-% (c) The GRASP Project, Glasgow University, 1994-1995
+% (c) The GRASP Project, Glasgow University, 1994-1998
%
\section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
\begin{code}
module TysWiredIn (
+ wiredInTyCons, genericTyCons,
+
addrDataCon,
addrTy,
addrTyCon,
+ ptrDataCon,
+ ptrTy,
+ ptrTyCon,
+ funPtrDataCon,
+ funPtrTy,
+ funPtrTyCon,
boolTy,
boolTyCon,
charDataCon,
consDataCon,
doubleDataCon,
doubleTy,
- isDoubleTy,
doubleTyCon,
- falseDataCon,
+ falseDataCon, falseDataConId,
floatDataCon,
floatTy,
- isFloatTy,
floatTyCon,
- getStatePairingConInfo,
intDataCon,
intTy,
intTyCon,
- isIntTy,
- inIntRange,
-
- int8TyCon,
- int16TyCon,
- int32TyCon,
-
- int64TyCon,
- int64DataCon,
--- int64Ty,
integerTy,
integerTyCon,
- integerDataCon,
- isIntegerTy,
+ smallIntegerDataCon,
+ largeIntegerDataCon,
- liftDataCon,
- liftTyCon,
listTyCon,
- foreignObjTyCon,
- mkLiftTy,
mkListTy,
- mkTupleTy,
- tupleTyCon, tupleCon, unitTyCon, unitDataCon, pairTyCon, pairDataCon,
nilDataCon,
- realWorldStateTy,
- return2GMPsTyCon,
- returnIntAndGMPTyCon,
-
- -- ST and STret types
- mkStateTy,
- mkStateTransformerTy,
- mkSTretTy,
- stTyCon,
- stDataCon,
- stRetDataCon,
- stRetTyCon,
-
- -- CCall result types
- stateAndAddrPrimTyCon,
- stateAndArrayPrimTyCon,
- stateAndByteArrayPrimTyCon,
- stateAndCharPrimTyCon,
- stateAndDoublePrimTyCon,
- stateAndFloatPrimTyCon,
- stateAndIntPrimTyCon,
- stateAndInt64PrimTyCon,
- stateAndForeignObjPrimTyCon,
- stateAndMutableArrayPrimTyCon,
- stateAndMutableByteArrayPrimTyCon,
- stateAndPtrPrimTyCon,
- stateAndPtrPrimDataCon,
- stateAndStablePtrPrimTyCon,
- stateAndSynchVarPrimTyCon,
- stateAndWordPrimTyCon,
- stateAndWord64PrimTyCon,
- stateDataCon,
- stateTyCon,
+
+ -- tuples
+ mkTupleTy,
+ tupleTyCon, tupleCon,
+ unitTyCon, unitDataConId, pairTyCon,
+ unboxedSingletonTyCon, unboxedSingletonDataCon,
+ unboxedPairTyCon, unboxedPairDataCon,
+
+ -- Generics
+ genUnitTyCon, genUnitDataCon,
+ plusTyCon, inrDataCon, inlDataCon,
+ crossTyCon, crossDataCon,
stablePtrTyCon,
stringTy,
- trueDataCon,
+ trueDataCon, trueDataConId,
unitTy,
+ voidTy,
wordDataCon,
wordTy,
wordTyCon,
- word8TyCon,
- word16TyCon,
- word32TyCon,
-
- word64DataCon,
--- word64Ty,
- word64TyCon,
-
- isFFIArgumentTy, -- :: Type -> Bool
- isFFIResultTy, -- :: Type -> Bool
- isFFIExternalTy, -- :: Type -> Bool
- isAddrTy, -- :: Type -> Bool
-
+ isFFIArgumentTy, -- :: DynFlags -> Safety -> Type -> Bool
+ isFFIImportResultTy, -- :: DynFlags -> Type -> Bool
+ isFFIExportResultTy, -- :: Type -> Bool
+ isFFIExternalTy, -- :: Type -> Bool
+ isFFIDynArgumentTy, -- :: Type -> Bool
+ isFFIDynResultTy, -- :: Type -> Bool
+ isFFILabelTy, -- :: Type -> Bool
) where
#include "HsVersions.h"
-import {-# SOURCE #-} MkId ( mkDataCon, mkTupleCon )
-import {-# SOURCE #-} Id ( Id, StrictnessMark(..) )
+import {-# SOURCE #-} MkId( mkDataConId, mkDataConWrapId )
+import {-# SOURCE #-} Generics( mkTyConGenInfo )
-- friends:
-import PrelMods
+import PrelNames
import TysPrim
-- others:
-import Kind ( mkBoxedTypeKind, mkArrowKind )
-import Name ( mkWiredInTyConName, mkWiredInIdName )
-import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon,
- TyCon, Arity
+import ForeignCall ( Safety, playSafe )
+import Constants ( mAX_TUPLE_SIZE )
+import Module ( mkPrelModule )
+import Name ( Name, nameRdrName, nameUnique, nameOccName,
+ nameModule, mkWiredInName )
+import OccName ( mkOccFS, tcName, dataName, mkWorkerOcc, mkGenOcc1, mkGenOcc2 )
+import RdrName ( rdrNameOcc )
+import DataCon ( DataCon, mkDataCon, dataConId )
+import Var ( TyVar, tyVarKind )
+import TyCon ( TyCon, AlgTyConFlavour(..), tyConDataCons,
+ mkTupleTyCon, isUnLiftedTyCon, mkAlgTyCon
)
-import BasicTypes ( Module, NewOrData(..), RecFlag(..) )
-import Type ( Type, mkTyConTy, mkTyConApp, mkSigmaTy, mkTyVarTys,
- mkFunTy, mkFunTys, splitTyConApp_maybe, splitAlgTyConApp_maybe,
- GenType(..), ThetaType, TauType, isUnpointedType )
-import TyVar ( GenTyVar, TyVar, tyVarKind, alphaTyVars, alphaTyVar, betaTyVar )
-import Lex ( mkTupNameStr )
-import Unique
-import CmdLineOpts ( opt_GlasgowExts )
-import Util ( assoc, panic )
+import BasicTypes ( Arity, RecFlag(..), Boxity(..), isBoxed, StrictnessMark(..) )
+
+import Type ( Type, mkTyConTy, mkTyConApp, mkTyVarTys,
+ mkArrowKinds, liftedTypeKind, unliftedTypeKind,
+ splitTyConApp_maybe,
+ TauType, ThetaType )
+import Unique ( incrUnique, mkTupleTyConUnique, mkTupleDataConUnique )
+import PrelNames
+import CmdLineOpts
+import Array
alpha_tyvar = [alphaTyVar]
alpha_ty = [alphaTy]
alpha_beta_tyvars = [alphaTyVar, betaTyVar]
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Wired in type constructors}
+%* *
+%************************************************************************
+
+\begin{code}
+wiredInTyCons :: [TyCon]
+wiredInTyCons = data_tycons ++ tuple_tycons ++ unboxed_tuple_tycons
+
+data_tycons = genericTyCons ++
+ [ addrTyCon
+ , ptrTyCon
+ , funPtrTyCon
+ , boolTyCon
+ , charTyCon
+ , doubleTyCon
+ , floatTyCon
+ , intTyCon
+ , integerTyCon
+ , listTyCon
+ , wordTyCon
+ ]
+
+genericTyCons :: [TyCon]
+genericTyCons = [ plusTyCon, crossTyCon, genUnitTyCon ]
+
+
+tuple_tycons = unitTyCon : [tupleTyCon Boxed i | i <- [2..mAX_TUPLE_SIZE] ]
+unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..mAX_TUPLE_SIZE] ]
+\end{code}
-pcRecDataTyCon, pcNonRecDataTyCon, pcNonRecNewTyCon
- :: Unique{-TyConKey-} -> Module -> FAST_STRING
- -> [TyVar] -> [Id] -> TyCon
-pcRecDataTyCon = pc_tycon DataType Recursive
-pcNonRecDataTyCon = pc_tycon DataType NonRecursive
-pcNonRecNewTyCon = pc_tycon NewType NonRecursive
+%************************************************************************
+%* *
+\subsection{mkWiredInTyCon}
+%* *
+%************************************************************************
-pc_tycon new_or_data is_rec key mod str tyvars cons
+\begin{code}
+pcNonRecDataTyCon = pcTyCon DataTyCon NonRecursive
+pcRecDataTyCon = pcTyCon DataTyCon Recursive
+
+pcTyCon new_or_data is_rec name tyvars argvrcs cons
= tycon
where
- tycon = mkDataTyCon name tycon_kind
- tyvars
- [] -- No context
- cons
- [] -- No derivings
- Nothing -- Not a dictionary
- new_or_data
- is_rec
-
- name = mkWiredInTyConName key mod str tycon
- tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars
-
-pcSynTyCon key mod str kind arity tyvars expansion
- = tycon
+ tycon = mkAlgTyCon name kind
+ tyvars
+ [] -- No context
+ argvrcs
+ cons
+ (length cons)
+ [] -- No record selectors
+ new_or_data
+ is_rec
+ gen_info
+
+ mod = nameModule name
+ kind = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind
+ gen_info = mk_tc_gen_info mod (nameUnique name) name tycon
+
+-- We generate names for the generic to/from Ids by incrementing
+-- the TyCon unique. So each Prelude tycon needs 3 slots, one
+-- for itself and two more for the generic Ids.
+mk_tc_gen_info mod tc_uniq tc_name tycon
+ = mkTyConGenInfo tycon [name1, name2]
where
- tycon = mkSynTyCon name kind arity tyvars expansion
- name = mkWiredInTyConName key mod str tycon
-
-pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING
- -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> Id
-pcDataCon key mod str tyvars context arg_tys tycon
+ tc_occ_name = nameOccName tc_name
+ occ_name1 = mkGenOcc1 tc_occ_name
+ occ_name2 = mkGenOcc2 tc_occ_name
+ fn1_key = incrUnique tc_uniq
+ fn2_key = incrUnique fn1_key
+ name1 = mkWiredInName mod occ_name1 fn1_key
+ name2 = mkWiredInName mod occ_name2 fn2_key
+
+pcDataCon :: Name -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> DataCon
+-- The unique is the first of two free uniques;
+-- the first is used for the datacon itself and the worker;
+-- the second is used for the wrapper.
+
+pcDataCon name tyvars context arg_tys tycon
= data_con
where
- data_con = mkDataCon name
- [ NotMarkedStrict | a <- arg_tys ]
- [ {- no labelled fields -} ]
- tyvars context [] [] arg_tys tycon
- name = mkWiredInIdName key mod str data_con
+ data_con = mkDataCon name
+ [ NotMarkedStrict | a <- arg_tys ]
+ [ {- no labelled fields -} ]
+ tyvars context [] [] arg_tys tycon work_id wrap_id
+
+ wrap_rdr = nameRdrName name
+ wrap_occ = rdrNameOcc wrap_rdr
+
+ mod = nameModule name
+ wrap_id = mkDataConWrapId data_con
+
+ work_occ = mkWorkerOcc wrap_occ
+ work_key = incrUnique (nameUnique name)
+ work_name = mkWiredInName mod work_occ work_key
+ work_id = mkDataConId work_name data_con
\end{code}
+
%************************************************************************
%* *
\subsection[TysWiredIn-tuples]{The tuple types}
%************************************************************************
\begin{code}
-tupleTyCon :: Arity -> TyCon
-tupleTyCon arity
- = tycon
- where
- tycon = mkTupleTyCon uniq name arity
- uniq = mkTupleTyConUnique arity
- name = mkWiredInTyConName uniq mod_name (mkTupNameStr arity) tycon
- mod_name | arity == 0 = pREL_BASE
- | otherwise = pREL_TUP
-
-tupleCon :: Arity -> Id
-tupleCon arity
- = tuple_con
+tupleTyCon :: Boxity -> Arity -> TyCon
+tupleTyCon boxity i | i > mAX_TUPLE_SIZE = fst (mk_tuple boxity i) -- Build one specially
+tupleTyCon Boxed i = fst (boxedTupleArr ! i)
+tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)
+
+tupleCon :: Boxity -> Arity -> DataCon
+tupleCon boxity i | i > mAX_TUPLE_SIZE = snd (mk_tuple boxity i) -- Build one specially
+tupleCon Boxed i = snd (boxedTupleArr ! i)
+tupleCon Unboxed i = snd (unboxedTupleArr ! i)
+
+boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
+boxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Boxed i) | i <- [0..mAX_TUPLE_SIZE]]
+unboxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Unboxed i) | i <- [0..mAX_TUPLE_SIZE]]
+
+mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
+mk_tuple boxity arity = (tycon, tuple_con)
where
- tuple_con = mkTupleCon arity name ty
- uniq = mkTupleDataConUnique arity
- name = mkWiredInIdName uniq mod_name (mkTupNameStr arity) tuple_con
- mod_name | arity == 0 = pREL_BASE
- | otherwise = pREL_TUP
- ty = mkSigmaTy tyvars [] (mkFunTys tyvar_tys (mkTyConApp tycon tyvar_tys))
- tyvars = take arity alphaTyVars
- tyvar_tys = mkTyVarTys tyvars
- tycon = tupleTyCon arity
-
-unitTyCon = tupleTyCon 0
-pairTyCon = tupleTyCon 2
-
-unitDataCon = tupleCon 0
-pairDataCon = tupleCon 2
+ tycon = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info
+ tc_name = mkWiredInName mod (mkOccFS tcName name_str) tc_uniq
+ tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind
+ res_kind | isBoxed boxity = liftedTypeKind
+ | otherwise = unliftedTypeKind
+
+ tyvars | isBoxed boxity = take arity alphaTyVars
+ | otherwise = take arity openAlphaTyVars
+
+ tuple_con = pcDataCon name tyvars [] tyvar_tys tycon
+ tyvar_tys = mkTyVarTys tyvars
+ (mod_name, name_str) = mkTupNameStr boxity arity
+ name = mkWiredInName mod (mkOccFS dataName name_str) dc_uniq
+ tc_uniq = mkTupleTyConUnique boxity arity
+ dc_uniq = mkTupleDataConUnique boxity arity
+ mod = mkPrelModule mod_name
+ gen_info = mk_tc_gen_info mod tc_uniq tc_name tycon
+
+unitTyCon = tupleTyCon Boxed 0
+unitDataConId = dataConId (head (tyConDataCons unitTyCon))
+
+pairTyCon = tupleTyCon Boxed 2
+
+unboxedSingletonTyCon = tupleTyCon Unboxed 1
+unboxedSingletonDataCon = tupleCon Unboxed 1
+
+unboxedPairTyCon = tupleTyCon Unboxed 2
+unboxedPairDataCon = tupleCon Unboxed 2
\end{code}
-
%************************************************************************
%* *
\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)}
%************************************************************************
\begin{code}
+-- The Void type is represented as a data type with no constructors
+-- It's a built in type (i.e. there's no way to define it in Haskell;
+-- the nearest would be
+--
+-- data Void = -- No constructors!
+--
+-- ) It's lifted; there is only one value of this
+-- type, namely "void", whose semantics is just bottom.
+--
+-- Haskell 98 drops the definition of a Void type, so we just 'simulate'
+-- voidTy using ().
+voidTy = unitTy
+\end{code}
+
+
+\begin{code}
charTy = mkTyConTy charTyCon
-charTyCon = pcNonRecDataTyCon charTyConKey pREL_BASE SLIT("Char") [] [charDataCon]
-charDataCon = pcDataCon charDataConKey pREL_BASE SLIT("C#") [] [] [charPrimTy] charTyCon
+charTyCon = pcNonRecDataTyCon charTyConName [] [] [charDataCon]
+charDataCon = pcDataCon charDataConName [] [] [charPrimTy] charTyCon
stringTy = mkListTy charTy -- convenience only
\end{code}
\begin{code}
intTy = mkTyConTy intTyCon
-intTyCon = pcNonRecDataTyCon intTyConKey pREL_BASE SLIT("Int") [] [intDataCon]
-intDataCon = pcDataCon intDataConKey pREL_BASE SLIT("I#") [] [] [intPrimTy] intTyCon
-
-isIntTy :: GenType flexi -> Bool
-isIntTy ty
- = case (splitAlgTyConApp_maybe ty) of
- Just (tycon, [], _) -> uniqueOf tycon == intTyConKey
- _ -> False
-
-inIntRange :: Integer -> Bool -- Tells if an integer lies in the legal range of Ints
-inIntRange i = (min_int <= i) && (i <= max_int)
-
-max_int, min_int :: Integer
-max_int = toInteger maxInt
-min_int = toInteger minInt
-
-int8TyCon = pcNonRecDataTyCon int8TyConKey iNT SLIT("Int8") [] [int8DataCon]
- where
- int8DataCon = pcDataCon int8DataConKey iNT SLIT("I8#") [] [] [intPrimTy] int8TyCon
-
-int16TyCon = pcNonRecDataTyCon int16TyConKey iNT SLIT("Int16") [] [int16DataCon]
- where
- int16DataCon = pcDataCon int16DataConKey iNT SLIT("I16#") [] [] [intPrimTy] int16TyCon
-
-int32TyCon = pcNonRecDataTyCon int32TyConKey iNT SLIT("Int32") [] [int32DataCon]
- where
- int32DataCon = pcDataCon int32DataConKey iNT SLIT("I32#") [] [] [intPrimTy] int32TyCon
-
-int64Ty = mkTyConTy int64TyCon
-
-int64TyCon = pcNonRecDataTyCon int64TyConKey pREL_CCALL SLIT("Int64") [] [int64DataCon]
-int64DataCon = pcDataCon int64DataConKey pREL_CCALL SLIT("I64#") [] [] [int64PrimTy] int64TyCon
+intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon]
+intDataCon = pcDataCon intDataConName [] [] [intPrimTy] intTyCon
\end{code}
\begin{code}
-
wordTy = mkTyConTy wordTyCon
-wordTyCon = pcNonRecDataTyCon wordTyConKey pREL_FOREIGN SLIT("Word") [] [wordDataCon]
-wordDataCon = pcDataCon wordDataConKey pREL_FOREIGN SLIT("W#") [] [] [wordPrimTy] wordTyCon
-
-word8TyCon = pcNonRecDataTyCon word8TyConKey wORD SLIT("Word8") [] [word8DataCon]
- where
- word8DataCon = pcDataCon word8DataConKey wORD SLIT("W8#") [] [] [wordPrimTy] word8TyCon
-
-word16TyCon = pcNonRecDataTyCon word16TyConKey wORD SLIT("Word16") [] [word16DataCon]
- where
- word16DataCon = pcDataCon word16DataConKey wORD SLIT("W16#") [] [] [wordPrimTy] word16TyCon
-
-word32TyCon = pcNonRecDataTyCon word32TyConKey wORD SLIT("Word32") [] [word32DataCon]
- where
- word32DataCon = pcDataCon word32DataConKey wORD SLIT("W32#") [] [] [wordPrimTy] word32TyCon
-
-word64Ty = mkTyConTy word64TyCon
-
-word64TyCon = pcNonRecDataTyCon word64TyConKey pREL_CCALL SLIT("Word64") [] [word64DataCon]
-word64DataCon = pcDataCon word64DataConKey pREL_CCALL SLIT("W64#") [] [] [word64PrimTy] word64TyCon
+wordTyCon = pcNonRecDataTyCon wordTyConName [] [] [wordDataCon]
+wordDataCon = pcDataCon wordDataConName [] [] [wordPrimTy] wordTyCon
\end{code}
\begin{code}
addrTy = mkTyConTy addrTyCon
-addrTyCon = pcNonRecDataTyCon addrTyConKey pREL_ADDR SLIT("Addr") [] [addrDataCon]
-addrDataCon = pcDataCon addrDataConKey pREL_ADDR SLIT("A#") [] [] [addrPrimTy] addrTyCon
-
-isAddrTy :: GenType flexi -> Bool
-isAddrTy ty
- = case (splitAlgTyConApp_maybe ty) of
- Just (tycon, [], _) -> uniqueOf tycon == addrTyConKey
- _ -> False
-
+addrTyCon = pcNonRecDataTyCon addrTyConName [] [] [addrDataCon]
+addrDataCon = pcDataCon addrDataConName [] [] [addrPrimTy] addrTyCon
\end{code}
\begin{code}
-floatTy = mkTyConTy floatTyCon
+ptrTy = mkTyConTy ptrTyCon
-floatTyCon = pcNonRecDataTyCon floatTyConKey pREL_BASE SLIT("Float") [] [floatDataCon]
-floatDataCon = pcDataCon floatDataConKey pREL_BASE SLIT("F#") [] [] [floatPrimTy] floatTyCon
+ptrTyCon = pcNonRecDataTyCon ptrTyConName alpha_tyvar [(True,False)] [ptrDataCon]
+ptrDataCon = pcDataCon ptrDataConName alpha_tyvar [] [addrPrimTy] ptrTyCon
+\end{code}
-isFloatTy :: GenType flexi -> Bool
-isFloatTy ty
- = case (splitAlgTyConApp_maybe ty) of
- Just (tycon, [], _) -> uniqueOf tycon == floatTyConKey
- _ -> False
+\begin{code}
+funPtrTy = mkTyConTy funPtrTyCon
+funPtrTyCon = pcNonRecDataTyCon funPtrTyConName alpha_tyvar [(True,False)] [funPtrDataCon]
+funPtrDataCon = pcDataCon funPtrDataConName alpha_tyvar [] [addrPrimTy] funPtrTyCon
\end{code}
\begin{code}
-doubleTy = mkTyConTy doubleTyCon
-
-isDoubleTy :: GenType flexi -> Bool
-isDoubleTy ty
- = case (splitAlgTyConApp_maybe ty) of
- Just (tycon, [], _) -> uniqueOf tycon == doubleTyConKey
- _ -> False
+floatTy = mkTyConTy floatTyCon
-doubleTyCon = pcNonRecDataTyCon doubleTyConKey pREL_BASE SLIT("Double") [] [doubleDataCon]
-doubleDataCon = pcDataCon doubleDataConKey pREL_BASE SLIT("D#") [] [] [doublePrimTy] doubleTyCon
+floatTyCon = pcNonRecDataTyCon floatTyConName [] [] [floatDataCon]
+floatDataCon = pcDataCon floatDataConName [] [] [floatPrimTy] floatTyCon
\end{code}
\begin{code}
-mkStateTy ty = mkTyConApp stateTyCon [ty]
-realWorldStateTy = mkStateTy realWorldTy -- a common use
+doubleTy = mkTyConTy doubleTyCon
-stateTyCon = pcNonRecDataTyCon stateTyConKey pREL_ST SLIT("State") alpha_tyvar [stateDataCon]
-stateDataCon
- = pcDataCon stateDataConKey pREL_ST SLIT("S#")
- alpha_tyvar [] [mkStatePrimTy alphaTy] stateTyCon
+doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [] [doubleDataCon]
+doubleDataCon = pcDataCon doubleDataConName [] [] [doublePrimTy] doubleTyCon
\end{code}
\begin{code}
stablePtrTyCon
- = pcNonRecDataTyCon stablePtrTyConKey pREL_FOREIGN SLIT("StablePtr")
- alpha_tyvar [stablePtrDataCon]
+ = pcNonRecDataTyCon stablePtrTyConName
+ alpha_tyvar [(True,False)] [stablePtrDataCon]
where
stablePtrDataCon
- = pcDataCon stablePtrDataConKey pREL_FOREIGN SLIT("StablePtr")
+ = pcDataCon stablePtrDataConName
alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon
\end{code}
\begin{code}
foreignObjTyCon
- = pcNonRecDataTyCon foreignObjTyConKey pREL_IO_BASE SLIT("ForeignObj")
- [] [foreignObjDataCon]
+ = pcNonRecDataTyCon foreignObjTyConName
+ [] [] [foreignObjDataCon]
where
foreignObjDataCon
- = pcDataCon foreignObjDataConKey pREL_IO_BASE SLIT("ForeignObj")
+ = pcDataCon foreignObjDataConName
[] [] [foreignObjPrimTy] foreignObjTyCon
\end{code}
-%************************************************************************
-%* *
-\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
-%* *
-%************************************************************************
-
-@Integer@ and its pals are not really primitive. @Integer@ itself, first:
-\begin{code}
-integerTy :: GenType t
-integerTy = mkTyConTy integerTyCon
-
-integerTyCon = pcNonRecDataTyCon integerTyConKey pREL_BASE SLIT("Integer") [] [integerDataCon]
-
-integerDataCon = pcDataCon integerDataConKey pREL_BASE SLIT("J#")
- [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon
-
-isIntegerTy :: GenType flexi -> Bool
-isIntegerTy ty
- = case (splitAlgTyConApp_maybe ty) of
- Just (tycon, [], _) -> uniqueOf tycon == integerTyConKey
- _ -> False
-\end{code}
-
-And the other pairing types:
\begin{code}
-return2GMPsTyCon = pcNonRecDataTyCon return2GMPsTyConKey
- pREL_NUM SLIT("Return2GMPs") [] [return2GMPsDataCon]
-
-return2GMPsDataCon
- = pcDataCon return2GMPsDataConKey pREL_NUM SLIT("Return2GMPs") [] []
- [intPrimTy, intPrimTy, byteArrayPrimTy,
- intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon
-
-returnIntAndGMPTyCon = pcNonRecDataTyCon returnIntAndGMPTyConKey
- pREL_NUM SLIT("ReturnIntAndGMP") [] [returnIntAndGMPDataCon]
-
-returnIntAndGMPDataCon
- = pcDataCon returnIntAndGMPDataConKey pREL_NUM SLIT("ReturnIntAndGMP") [] []
- [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon
+foreignPtrTyCon
+ = pcNonRecDataTyCon foreignPtrTyConName
+ alpha_tyvar [(True,False)] [foreignPtrDataCon]
+ where
+ foreignPtrDataCon
+ = pcDataCon foreignPtrDataConName
+ alpha_tyvar [] [foreignObjPrimTy] foreignPtrTyCon
\end{code}
%************************************************************************
%* *
-\subsection[TysWiredIn-state-pairing]{``State-pairing'' types}
+\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types}
%* *
%************************************************************************
-These boring types pair a \tr{State#} with another primitive type.
-They are not really primitive, so they are given here, not in
-\tr{TysPrim.lhs}.
-
-We fish one of these \tr{StateAnd<blah>#} things with
-@getStatePairingConInfo@ (given a little way down).
-
-\begin{code}
-stateAndPtrPrimTyCon
- = pcNonRecDataTyCon stateAndPtrPrimTyConKey pREL_ST SLIT("StateAndPtr#")
- alpha_beta_tyvars [stateAndPtrPrimDataCon]
-stateAndPtrPrimDataCon
- = pcDataCon stateAndPtrPrimDataConKey pREL_ST SLIT("StateAndPtr#")
- alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
- stateAndPtrPrimTyCon
-
-stateAndCharPrimTyCon
- = pcNonRecDataTyCon stateAndCharPrimTyConKey pREL_ST SLIT("StateAndChar#")
- alpha_tyvar [stateAndCharPrimDataCon]
-stateAndCharPrimDataCon
- = pcDataCon stateAndCharPrimDataConKey pREL_ST SLIT("StateAndChar#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, charPrimTy]
- stateAndCharPrimTyCon
-
-stateAndIntPrimTyCon
- = pcNonRecDataTyCon stateAndIntPrimTyConKey pREL_ST SLIT("StateAndInt#")
- alpha_tyvar [stateAndIntPrimDataCon]
-stateAndIntPrimDataCon
- = pcDataCon stateAndIntPrimDataConKey pREL_ST SLIT("StateAndInt#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, intPrimTy]
- stateAndIntPrimTyCon
-
-stateAndInt64PrimTyCon
- = pcNonRecDataTyCon stateAndInt64PrimTyConKey pREL_ST SLIT("StateAndInt64#")
- alpha_tyvar [stateAndInt64PrimDataCon]
-stateAndInt64PrimDataCon
- = pcDataCon stateAndInt64PrimDataConKey pREL_ST SLIT("StateAndInt64#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, int64PrimTy]
- stateAndInt64PrimTyCon
-
-stateAndWordPrimTyCon
- = pcNonRecDataTyCon stateAndWordPrimTyConKey pREL_ST SLIT("StateAndWord#")
- alpha_tyvar [stateAndWordPrimDataCon]
-stateAndWordPrimDataCon
- = pcDataCon stateAndWordPrimDataConKey pREL_ST SLIT("StateAndWord#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, wordPrimTy]
- stateAndWordPrimTyCon
-
-stateAndWord64PrimTyCon
- = pcNonRecDataTyCon stateAndWord64PrimTyConKey pREL_ST SLIT("StateAndWord64#")
- alpha_tyvar [stateAndWord64PrimDataCon]
-stateAndWord64PrimDataCon
- = pcDataCon stateAndWord64PrimDataConKey pREL_ST SLIT("StateAndWord64#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, word64PrimTy]
- stateAndWord64PrimTyCon
-
-stateAndAddrPrimTyCon
- = pcNonRecDataTyCon stateAndAddrPrimTyConKey pREL_ST SLIT("StateAndAddr#")
- alpha_tyvar [stateAndAddrPrimDataCon]
-stateAndAddrPrimDataCon
- = pcDataCon stateAndAddrPrimDataConKey pREL_ST SLIT("StateAndAddr#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, addrPrimTy]
- stateAndAddrPrimTyCon
-
-stateAndStablePtrPrimTyCon
- = pcNonRecDataTyCon stateAndStablePtrPrimTyConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
- alpha_beta_tyvars [stateAndStablePtrPrimDataCon]
-stateAndStablePtrPrimDataCon
- = pcDataCon stateAndStablePtrPrimDataConKey pREL_FOREIGN SLIT("StateAndStablePtr#")
- alpha_beta_tyvars []
- [mkStatePrimTy alphaTy, mkTyConApp stablePtrPrimTyCon [betaTy]]
- stateAndStablePtrPrimTyCon
-
-stateAndForeignObjPrimTyCon
- = pcNonRecDataTyCon stateAndForeignObjPrimTyConKey pREL_IO_BASE SLIT("StateAndForeignObj#")
- alpha_tyvar [stateAndForeignObjPrimDataCon]
-stateAndForeignObjPrimDataCon
- = pcDataCon stateAndForeignObjPrimDataConKey pREL_IO_BASE SLIT("StateAndForeignObj#")
- alpha_tyvar []
- [mkStatePrimTy alphaTy, mkTyConTy foreignObjPrimTyCon]
- stateAndForeignObjPrimTyCon
-
-stateAndFloatPrimTyCon
- = pcNonRecDataTyCon stateAndFloatPrimTyConKey pREL_ST SLIT("StateAndFloat#")
- alpha_tyvar [stateAndFloatPrimDataCon]
-stateAndFloatPrimDataCon
- = pcDataCon stateAndFloatPrimDataConKey pREL_ST SLIT("StateAndFloat#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, floatPrimTy]
- stateAndFloatPrimTyCon
-
-stateAndDoublePrimTyCon
- = pcNonRecDataTyCon stateAndDoublePrimTyConKey pREL_ST SLIT("StateAndDouble#")
- alpha_tyvar [stateAndDoublePrimDataCon]
-stateAndDoublePrimDataCon
- = pcDataCon stateAndDoublePrimDataConKey pREL_ST SLIT("StateAndDouble#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, doublePrimTy]
- stateAndDoublePrimTyCon
-\end{code}
-
+@Integer@ and its pals are not really primitive. @Integer@ itself, first:
\begin{code}
-stateAndArrayPrimTyCon
- = pcNonRecDataTyCon stateAndArrayPrimTyConKey pREL_ARR SLIT("StateAndArray#")
- alpha_beta_tyvars [stateAndArrayPrimDataCon]
-stateAndArrayPrimDataCon
- = pcDataCon stateAndArrayPrimDataConKey pREL_ARR SLIT("StateAndArray#")
- alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy]
- stateAndArrayPrimTyCon
-
-stateAndMutableArrayPrimTyCon
- = pcNonRecDataTyCon stateAndMutableArrayPrimTyConKey pREL_ARR SLIT("StateAndMutableArray#")
- alpha_beta_tyvars [stateAndMutableArrayPrimDataCon]
-stateAndMutableArrayPrimDataCon
- = pcDataCon stateAndMutableArrayPrimDataConKey pREL_ARR SLIT("StateAndMutableArray#")
- alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy]
- stateAndMutableArrayPrimTyCon
-
-stateAndByteArrayPrimTyCon
- = pcNonRecDataTyCon stateAndByteArrayPrimTyConKey pREL_ARR SLIT("StateAndByteArray#")
- alpha_tyvar [stateAndByteArrayPrimDataCon]
-stateAndByteArrayPrimDataCon
- = pcDataCon stateAndByteArrayPrimDataConKey pREL_ARR SLIT("StateAndByteArray#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, byteArrayPrimTy]
- stateAndByteArrayPrimTyCon
-
-stateAndMutableByteArrayPrimTyCon
- = pcNonRecDataTyCon stateAndMutableByteArrayPrimTyConKey pREL_ARR SLIT("StateAndMutableByteArray#")
- alpha_tyvar [stateAndMutableByteArrayPrimDataCon]
-stateAndMutableByteArrayPrimDataCon
- = pcDataCon stateAndMutableByteArrayPrimDataConKey pREL_ARR SLIT("StateAndMutableByteArray#")
- alpha_tyvar [] [mkStatePrimTy alphaTy, mkTyConApp mutableByteArrayPrimTyCon alpha_ty]
- stateAndMutableByteArrayPrimTyCon
-
-stateAndSynchVarPrimTyCon
- = pcNonRecDataTyCon stateAndSynchVarPrimTyConKey pREL_CONC SLIT("StateAndSynchVar#")
- alpha_beta_tyvars [stateAndSynchVarPrimDataCon]
-stateAndSynchVarPrimDataCon
- = pcDataCon stateAndSynchVarPrimDataConKey pREL_CONC SLIT("StateAndSynchVar#")
- alpha_beta_tyvars [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy]
- stateAndSynchVarPrimTyCon
-\end{code}
+integerTy :: Type
+integerTy = mkTyConTy integerTyCon
-The ccall-desugaring mechanism uses this function to figure out how to
-rebox the result. It's really a HACK, especially the part about
-how many types to drop from \tr{tys_applied}.
+integerTyCon = pcNonRecDataTyCon integerTyConName
+ [] [] [smallIntegerDataCon, largeIntegerDataCon]
-\begin{code}
-getStatePairingConInfo
- :: Type -- primitive type
- -> (Id, -- state pair constructor for prim type
- Type) -- type of state pair
-
-getStatePairingConInfo prim_ty
- = case (splitTyConApp_maybe prim_ty) of
- Nothing -> panic "getStatePairingConInfo:1"
- Just (prim_tycon, tys_applied) ->
- let
- (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon
- pair_ty = mkTyConApp pair_tycon (realWorldTy : drop num_tys tys_applied)
- in
- (pair_con, pair_ty)
- where
- tbl = [
- (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)),
- (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)),
- (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)),
- (int64PrimTyCon, (stateAndInt64PrimDataCon, stateAndInt64PrimTyCon, 0)),
- (word64PrimTyCon, (stateAndWord64PrimDataCon, stateAndWord64PrimTyCon, 0)),
- (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)),
- (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)),
- (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)),
- (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)),
- (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)),
- (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)),
- (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)),
- (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)),
- (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)),
- (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1))
- -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)),
- ]
+smallIntegerDataCon = pcDataCon smallIntegerDataConName
+ [] [] [intPrimTy] integerTyCon
+largeIntegerDataCon = pcDataCon largeIntegerDataConName
+ [] [] [intPrimTy, byteArrayPrimTy] integerTyCon
\end{code}
being the )
\begin{code}
-isFFIArgumentTy :: Type -> Bool
-isFFIArgumentTy ty =
- (opt_GlasgowExts && isUnpointedType ty) || --leave out for now: maybeToBool (maybeBoxedPrimType ty))) ||
- case (splitAlgTyConApp_maybe ty) of
- Just (tycon, _, _) -> (uniqueOf tycon) `elem` primArgTyConKeys
- _ -> False
-
--- types that can be passed as arguments to "foreign" functions
-primArgTyConKeys
- = [ intTyConKey, int8TyConKey, int16TyConKey, int32TyConKey, int64TyConKey
- , wordTyConKey, word8TyConKey, word16TyConKey, word32TyConKey, word64TyConKey
- , floatTyConKey, doubleTyConKey
- , addrTyConKey, charTyConKey, foreignObjTyConKey
- , stablePtrTyConKey, byteArrayTyConKey, mutableByteArrayTyConKey
- ]
-
--- types that can be passed from the outside world into Haskell.
--- excludes (mutable) byteArrays.
+isFFIArgumentTy :: DynFlags -> Safety -> Type -> Bool
+-- Checks for valid argument type for a 'foreign import'
+isFFIArgumentTy dflags safety ty
+ = checkRepTyCon (legalOutgoingTyCon dflags safety) ty
+
isFFIExternalTy :: Type -> Bool
-isFFIExternalTy ty =
- (opt_GlasgowExts && isUnpointedType ty) || --leave out for now: maybeToBool (maybeBoxedPrimType ty))) ||
- case (splitAlgTyConApp_maybe ty) of
- Just (tycon, _, _) ->
- let
- u_tycon = uniqueOf tycon
- in
- (u_tycon `elem` primArgTyConKeys) &&
- not (u_tycon `elem` notLegalExternalTyCons)
- _ -> False
-
-
-isFFIResultTy :: Type -> Bool
-isFFIResultTy ty =
- not (isUnpointedType ty) &&
- case (splitAlgTyConApp_maybe ty) of
- Just (tycon, _, _) ->
- let
- u_tycon = uniqueOf tycon
- in
- (u_tycon == uniqueOf unitTyCon) ||
- ((u_tycon `elem` primArgTyConKeys) &&
- not (u_tycon `elem` notLegalExternalTyCons))
- _ -> False
-
--- it's illegal to return foreign objects and (mutable)
--- bytearrays from a _ccall_ / foreign declaration
--- (or be passed them as arguments in foreign exported functions).
-notLegalExternalTyCons =
- [ foreignObjTyConKey, byteArrayTyConKey, mutableByteArrayTyConKey ]
-
+-- Types that are allowed as arguments of a 'foreign export'
+isFFIExternalTy ty = checkRepTyCon legalFEArgTyCon ty
+
+isFFIImportResultTy :: DynFlags -> Type -> Bool
+isFFIImportResultTy dflags ty
+ = checkRepTyCon (legalFIResultTyCon dflags) ty
+
+isFFIExportResultTy :: Type -> Bool
+isFFIExportResultTy ty = checkRepTyCon legalFEResultTyCon ty
+
+isFFIDynArgumentTy :: Type -> Bool
+-- The argument type of a foreign import dynamic must be Ptr, FunPtr, Addr,
+-- or a newtype of either.
+isFFIDynArgumentTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == funPtrTyCon || tc == addrTyCon)
+
+isFFIDynResultTy :: Type -> Bool
+-- The result type of a foreign export dynamic must be Ptr, FunPtr, Addr,
+-- or a newtype of either.
+isFFIDynResultTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == funPtrTyCon || tc == addrTyCon)
+
+isFFILabelTy :: Type -> Bool
+-- The type of a foreign label must be Ptr, FunPtr, Addr,
+-- or a newtype of either.
+isFFILabelTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == funPtrTyCon || tc == addrTyCon)
+
+checkRepTyCon :: (TyCon -> Bool) -> Type -> Bool
+ -- Look through newtypes
+checkRepTyCon check_tc ty = case splitTyConApp_maybe ty of
+ Just (tycon, _) -> check_tc tycon
+ Nothing -> False
\end{code}
-
-%************************************************************************
-%* *
-\subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type}
-%* *
-%************************************************************************
-
-The only reason this is wired in is because we have to represent the
-type of runST.
+----------------------------------------------
+These chaps do the work; they are not exported
+----------------------------------------------
\begin{code}
-mkStateTransformerTy s a = mkTyConApp stTyCon [s, a]
-
-stTyCon = pcNonRecNewTyCon stTyConKey pREL_ST SLIT("ST") alpha_beta_tyvars [stDataCon]
-
-stDataCon = pcDataCon stDataConKey pREL_ST SLIT("ST")
- alpha_beta_tyvars [] [ty] stTyCon
- where
- ty = mkFunTy (mkStatePrimTy alphaTy) (mkSTretTy alphaTy betaTy)
-
-mkSTretTy alpha beta = mkTyConApp stRetTyCon [alpha,beta]
-
-stRetTyCon
- = pcNonRecDataTyCon stRetTyConKey pREL_ST SLIT("STret")
- alpha_beta_tyvars [stRetDataCon]
-stRetDataCon
- = pcDataCon stRetDataConKey pREL_ST SLIT("STret")
- alpha_beta_tyvars [] [mkStatePrimTy alphaTy, betaTy]
- stRetTyCon
+legalFEArgTyCon :: TyCon -> Bool
+-- It's illegal to return foreign objects and (mutable)
+-- bytearrays from a _ccall_ / foreign declaration
+-- (or be passed them as arguments in foreign exported functions).
+legalFEArgTyCon tc
+ | getUnique tc `elem` [ foreignObjTyConKey, foreignPtrTyConKey,
+ byteArrayTyConKey, mutableByteArrayTyConKey ]
+ = False
+ -- It's also illegal to make foreign exports that take unboxed
+ -- arguments. The RTS API currently can't invoke such things. --SDM 7/2000
+ | otherwise
+ = boxedMarshalableTyCon tc
+
+legalFIResultTyCon :: DynFlags -> TyCon -> Bool
+legalFIResultTyCon dflags tc
+ | getUnique tc `elem`
+ [ foreignObjTyConKey, foreignPtrTyConKey,
+ byteArrayTyConKey, mutableByteArrayTyConKey ] = False
+ | tc == unitTyCon = True
+ | otherwise = marshalableTyCon dflags tc
+
+legalFEResultTyCon :: TyCon -> Bool
+legalFEResultTyCon tc
+ | getUnique tc `elem`
+ [ foreignObjTyConKey, foreignPtrTyConKey,
+ byteArrayTyConKey, mutableByteArrayTyConKey ] = False
+ | tc == unitTyCon = True
+ | otherwise = boxedMarshalableTyCon tc
+
+legalOutgoingTyCon :: DynFlags -> Safety -> TyCon -> Bool
+-- Checks validity of types going from Haskell -> external world
+legalOutgoingTyCon dflags safety tc
+ | playSafe safety && getUnique tc `elem` [byteArrayTyConKey, mutableByteArrayTyConKey]
+ = False
+ | otherwise
+ = marshalableTyCon dflags tc
+
+marshalableTyCon dflags tc
+ = (dopt Opt_GlasgowExts dflags && isUnLiftedTyCon tc)
+ || boxedMarshalableTyCon tc
+
+boxedMarshalableTyCon tc
+ = getUnique tc `elem` [ intTyConKey, int8TyConKey, int16TyConKey
+ , int32TyConKey, int64TyConKey
+ , wordTyConKey, word8TyConKey, word16TyConKey
+ , word32TyConKey, word64TyConKey
+ , floatTyConKey, doubleTyConKey
+ , addrTyConKey, ptrTyConKey, funPtrTyConKey
+ , charTyConKey, foreignObjTyConKey
+ , foreignPtrTyConKey
+ , stablePtrTyConKey
+ , byteArrayTyConKey, mutableByteArrayTyConKey
+ , boolTyConKey
+ ]
\end{code}
+
%************************************************************************
%* *
\subsection[TysWiredIn-Bool]{The @Bool@ type}
\begin{code}
boolTy = mkTyConTy boolTyCon
-boolTyCon = pcNonRecDataTyCon boolTyConKey pREL_BASE SLIT("Bool") [] [falseDataCon, trueDataCon]
+boolTyCon = pcTyCon EnumTyCon NonRecursive boolTyConName
+ [] [] [falseDataCon, trueDataCon]
+
+falseDataCon = pcDataCon falseDataConName [] [] [] boolTyCon
+trueDataCon = pcDataCon trueDataConName [] [] [] boolTyCon
-falseDataCon = pcDataCon falseDataConKey pREL_BASE SLIT("False") [] [] [] boolTyCon
-trueDataCon = pcDataCon trueDataConKey pREL_BASE SLIT("True") [] [] [] boolTyCon
+falseDataConId = dataConId falseDataCon
+trueDataConId = dataConId trueDataCon
\end{code}
%************************************************************************
\end{verbatim}
\begin{code}
-mkListTy :: GenType t -> GenType t
+mkListTy :: Type -> Type
mkListTy ty = mkTyConApp listTyCon [ty]
-alphaListTy = mkSigmaTy alpha_tyvar [] (mkTyConApp listTyCon alpha_ty)
+listTyCon = pcRecDataTyCon listTyConName
+ alpha_tyvar [(True,False)] [nilDataCon, consDataCon]
-listTyCon = pcRecDataTyCon listTyConKey pREL_BASE SLIT("[]")
- alpha_tyvar [nilDataCon, consDataCon]
-
-nilDataCon = pcDataCon nilDataConKey pREL_BASE SLIT("[]") alpha_tyvar [] [] listTyCon
-consDataCon = pcDataCon consDataConKey pREL_BASE SLIT(":")
- alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
+nilDataCon = pcDataCon nilDataConName alpha_tyvar [] [] listTyCon
+consDataCon = pcDataCon consDataConName
+ alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
-- Interesting: polymorphic recursion would help here.
-- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
-- gets the over-specific type (Type -> Type)
\end{itemize}
\begin{code}
-mkTupleTy :: Int -> [GenType t] -> GenType t
-
-mkTupleTy arity tys = mkTyConApp (tupleTyCon arity) tys
+mkTupleTy :: Boxity -> Int -> [Type] -> Type
+mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys
-unitTy = mkTupleTy 0 []
+unitTy = mkTupleTy Boxed 0 []
\end{code}
%************************************************************************
-%* *
-\subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing}
-%* *
+%* *
+\subsection{Wired In Type Constructors for Representation Types}
+%* *
%************************************************************************
-Again, deeply turgid: \tr{data _Lift a = _Lift a}.
+The following code defines the wired in datatypes cross, plus, unit
+and c_of needed for the generic methods.
-\begin{code}
-mkLiftTy ty = mkTyConApp liftTyCon [ty]
+Ok, so the basic story is that for each type constructor I need to
+create 2 things - a TyCon and a DataCon and then we are basically
+ok. There are going to be no arguments passed to these functions
+because -well- there is nothing to pass to these functions.
-{-
-mkLiftTy ty
- = mkSigmaTy tvs theta (mkTyConApp liftTyCon [tau])
- where
- (tvs, theta, tau) = splitSigmaTy ty
+\begin{code}
+crossTyCon :: TyCon
+crossTyCon = pcNonRecDataTyCon crossTyConName alpha_beta_tyvars [] [crossDataCon]
-isLiftTy ty
- = case (splitAlgTyConApp_maybeExpandingDicts tau) of
- Just (tycon, tys, _) -> tycon == liftTyCon
- Nothing -> False
- where
- (tvs, theta, tau) = splitSigmaTy ty
--}
+crossDataCon :: DataCon
+crossDataCon = pcDataCon crossDataConName alpha_beta_tyvars [] [alphaTy, betaTy] crossTyCon
+plusTyCon :: TyCon
+plusTyCon = pcNonRecDataTyCon plusTyConName alpha_beta_tyvars [] [inlDataCon, inrDataCon]
-alphaLiftTy = mkSigmaTy alpha_tyvar [] (mkTyConApp liftTyCon alpha_ty)
+inlDataCon, inrDataCon :: DataCon
+inlDataCon = pcDataCon inlDataConName alpha_beta_tyvars [] [alphaTy] plusTyCon
+inrDataCon = pcDataCon inrDataConName alpha_beta_tyvars [] [betaTy] plusTyCon
-liftTyCon
- = pcNonRecDataTyCon liftTyConKey pREL_BASE SLIT("Lift") alpha_tyvar [liftDataCon]
+genUnitTyCon :: TyCon -- The "1" type constructor for generics
+genUnitTyCon = pcNonRecDataTyCon genUnitTyConName [] [] [genUnitDataCon]
-liftDataCon
- = pcDataCon liftDataConKey pREL_BASE SLIT("Lift")
- alpha_tyvar [] alpha_ty liftTyCon
- where
- bottom = panic "liftDataCon:State# _RealWorld"
+genUnitDataCon :: DataCon
+genUnitDataCon = pcDataCon genUnitDataConName [] [] [] genUnitTyCon
\end{code}