1 module PreludeBuiltin (
13 import List ( (++), foldr, takeWhile )
14 import TyArray ( Array(..) )
15 import PreludeErrIO ( errorIO )
16 import PreludeGlaST -- state transformer stuff
17 import PreludeDialogueIO ( appendChan# )
18 #ifndef __PARALLEL_HASKELL__
19 import PreludeGlaMisc ( deRefStablePtr )
21 import PS ( _PackedString, _unpackPS )
22 import Stdio ( _FILE )
26 ---------------------------------------------------------------
28 packCString# :: [Char] -> ByteArray#
30 packCString# str = packString# str -- ToDo: more satisfactorily
33 ---------------------------------------------------------------
34 -- ******** defns of `error' and `trace' using Glasgow IO *****
35 -- No specialised versions are required for these bottoming Ids
38 error s = error__ ( \ x -> _ccall_ ErrorHdrHook x ) s
40 error__ :: (_FILE -> PrimIO ()) -> String -> a
43 #ifdef __PARALLEL_HASKELL__
44 = errorIO (msg_hdr sTDERR{-msg hdr-} `seqPrimIO`
45 _ccall_ fflush sTDERR `seqPrimIO`
46 appendChan# sTDERR s `seqPrimIO`
47 _ccall_ fflush sTDERR `seqPrimIO`
48 _ccall_ stg_exit (1::Int)
51 = errorIO (msg_hdr sTDERR{-msg hdr-} `seqPrimIO`
52 _ccall_ fflush sTDERR `seqPrimIO`
53 appendChan# sTDERR s `seqPrimIO`
54 _ccall_ fflush sTDERR `seqPrimIO`
55 _ccall_ getErrorHandler `thenPrimIO` \ errorHandler ->
56 if errorHandler == (-1::Int)
57 then _ccall_ stg_exit (1::Int)
59 _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
60 `thenPrimIO` \ osptr ->
61 _ccall_ decrementErrorCount `thenPrimIO` \ () ->
62 deRefStablePtr osptr `thenPrimIO` \ oact ->
65 #endif {- !parallel -}
67 sTDERR = (``stderr'' :: _FILE)
69 absent# = error "Oops! The program has entered an `absent' argument!\n"
71 parError# = error "Oops! Entered parError# (a GHC bug -- please report it!)\n"
73 ---------------------------------------------------------------
74 _runST m = case m (S# realWorld#) of
77 ---------------------------------------------------------------
78 -- Used for compiler-generated error message;
79 -- encoding saves bytes of string junk.
81 patError# :: String -> a
84 = error__ (\ x -> _ccall_ PatErrorHdrHook x) (expand (encoded_msg ++ "\n"))
87 expand ('%':next:rest)
92 'D' -> "No default method for \""
93 'E' -> "No explicit method for \""
94 'N' -> ": non-exhaustive guards"
95 'F' -> "incomplete pattern(s) to match in function \""
96 'L' -> "pattern-matching failed in lambda"
97 'C' -> "pattern-matching failed in case"
98 '~' -> ": pattern-match failed on an irrefutable pattern"
100 _ -> error ("BAD call to builtin patError#:" ++ (next:rest))
102 decoded ++ expand rest
104 expand (c:rest) = c : expand rest
106 ---------------------------------------------------------------
107 -- ******** defn of `_trace' using Glasgow IO *******
109 {-# GENERATE_SPECS _trace a #-}
110 _trace :: String -> a -> a
113 = unsafePerformPrimIO (
114 ((_ccall_ PreTraceHook sTDERR{-msg-})::PrimIO ()) `seqPrimIO`
115 appendChan# sTDERR string `seqPrimIO`
116 ((_ccall_ PostTraceHook sTDERR{-msg-})::PrimIO ()) `seqPrimIO`
119 sTDERR = (``stderr'' :: _FILE)