3 {- This module contains a few primitive types that need to be wired in.
4 Most are defined in PrimEnv, which is automatically generated from
7 module Prims(initialEnv, primEnv, newPrimVars) where
18 initialEnv = efromlist [(primMname,primEnv),
22 -- Tediously, we add defs for ByteArray# etc. because these are
23 -- declared as ByteArr# (etc.) in primops.txt, and GHC has
24 -- ByteArray# etc. wired-in.
25 -- At least this is better than when all primops were wired-in here.
26 primEnv = Envs {tcenv_=efromlist $ map (\ (t,k) -> (t,Kind k)) $
27 [(snd tcByteArrayzh,ktByteArrayzh),
28 (snd tcMutableArrayzh, ktMutableArrayzh),
29 (snd tcMutableByteArrayzh, ktMutableByteArrayzh)] ++
30 ([(snd $ tcUtuple n, ktUtuple n) | n <- [1..maxUtuple]]
31 ++ ((snd tcArrow,ktArrow):primTcs)),
32 cenv_=efromlist primDcs,
33 venv_=efromlist (newPrimVars ++ opsState ++ primVals)}
36 errorEnv = Envs {tcenv_=eempty,
38 venv_=efromlist errorVals}
41 newPrimVars :: [(Id, Ty)]
42 newPrimVars = map (\ (v, ty) -> (zEncodeString v, ty))
43 [("hPutChar#", mkFunTy tIntzh (mkFunTy tCharzh tIOUnit)),
44 ("isSpace#", mkFunTy tCharzh tBool)]
47 primDcs :: [(Dcon,Ty)]
48 primDcs = map (\ ((_,c),t) -> (c,t))
49 [(dcUtuple n, dcUtupleTy n) | n <- [1..maxUtuple]]
52 tRWS = tStatezh tRealWorld
54 opsState :: [(Var, Ty)]
56 ("realWorldzh", tRWS)]
60 tcByteArrayzh, tcMutableArrayzh, tcMutableByteArrayzh :: Qual Tcon
61 ktByteArrayzh, ktMutableArrayzh, ktMutableByteArrayzh :: Kind
63 tcByteArrayzh = pvz "ByteArray"
64 ktByteArrayzh = Kunlifted
66 tcMutableArrayzh = pvz "MutableArray"
67 ktMutableArrayzh = Karrow Klifted (Karrow Klifted Kunlifted)
69 tcMutableByteArrayzh = pvz "MutableByteArray"
70 ktMutableByteArrayzh = Karrow Klifted Kunlifted
72 {- Real world and state. -}
74 -- tjc: why isn't this one unboxed?
75 tcRealWorld :: Qual Tcon
76 tcRealWorld = pv "RealWorld"
78 tRealWorld = Tcon tcRealWorld
80 tcStatezh :: Qual Tcon
81 tcStatezh = pvz "State"
83 tStatezh t = Tapp (Tcon tcStatezh) t
85 {- Properly defined in PrelError, but needed in many modules before that. -}
86 errorVals :: [(Var, Ty)]
88 ("error", Tforall ("a",Kopen) (tArrow tString (Tvar "a"))),
89 ("irrefutPatError", str2A),
91 ("divZZeroError", forallAA),
92 ("overflowError", forallAA)]
94 {- Non-primitive, but mentioned in the types of primitives. -}
100 str2A = Tforall ("a",Kopen) (tArrow tAddrzh (Tvar "a"))
101 forallAA = Tforall ("a",Kopen) (Tvar "a")
104 tBool = Tcon (Just boolMname, "Bool")
112 tList t = Tapp (Tcon tcList) t
114 tString = tList tChar
115 tIntzh, tCharzh, tIOUnit :: Ty
116 tIntzh = Tcon (primId "Int#")
117 tCharzh = Tcon (primId "Char#")
118 tIOUnit = Tapp (Tcon (Just (mkBaseMname "IOBase"), "IO"))
121 primId :: String -> Qual Id
122 primId = pv . zEncodeString