1 module PreludeBuiltin (
12 import List ( (++), foldr, takeWhile )
13 import TyArray ( Array(..) )
14 import PreludeErrIO ( errorIO )
15 import PreludeGlaST -- state transformer stuff
16 import PreludeDialogueIO ( appendChan# )
17 #ifndef __PARALLEL_HASKELL__
18 import PreludeGlaMisc ( deRefStablePtr )
20 import PS ( _PackedString, _unpackPS )
21 import Stdio ( _FILE )
24 ---------------------------------------------------------------
26 packCString# :: [Char] -> ByteArray#
28 packCString# str = packString# str -- ToDo: more satisfactorily
31 ---------------------------------------------------------------
32 -- ******** defns of `error' and `trace' using Glasgow IO *****
33 -- No specialised versions are required for these bottoming Ids
36 error s = error__ ( \ x -> _ccall_ ErrorHdrHook x ) s
38 error__ :: (_FILE -> PrimIO ()) -> String -> a
41 #ifdef __PARALLEL_HASKELL__
42 = errorIO (msg_hdr sTDERR{-msg hdr-} `seqPrimIO`
43 _ccall_ fflush sTDERR `seqPrimIO`
44 appendChan# sTDERR s `seqPrimIO`
45 _ccall_ fflush sTDERR `seqPrimIO`
46 _ccall_ stg_exit (1::Int)
49 = errorIO (msg_hdr sTDERR{-msg hdr-} `seqPrimIO`
50 _ccall_ fflush sTDERR `seqPrimIO`
51 appendChan# sTDERR s `seqPrimIO`
52 _ccall_ fflush sTDERR `seqPrimIO`
53 _ccall_ getErrorHandler `thenPrimIO` \ errorHandler ->
54 if errorHandler == (-1::Int)
55 then _ccall_ stg_exit (1::Int)
57 _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
58 `thenPrimIO` \ osptr ->
59 _ccall_ decrementErrorCount `thenPrimIO` \ () ->
60 deRefStablePtr osptr `thenPrimIO` \ oact ->
63 #endif {- !parallel -}
65 sTDERR = (``stderr'' :: _FILE)
67 absent# = error "Oops! The program has entered an `absent' argument!\n"
69 ---------------------------------------------------------------
70 _runST m = case m (S# realWorld#) of
73 ---------------------------------------------------------------
74 -- Used for compiler-generated error message;
75 -- encoding saves bytes of string junk.
77 patError# :: String -> a
80 = error__ (\ x -> _ccall_ PatErrorHdrHook x) (expand (encoded_msg ++ "\n"))
83 expand ('%':next:rest)
88 'D' -> "No default method for \""
89 'N' -> ": non-exhaustive guards"
90 'F' -> "incomplete pattern(s) to match in function \""
91 'L' -> "pattern-matching failed in lambda"
92 'C' -> "pattern-matching failed in case"
93 '~' -> ": pattern-match failed on an irrefutable pattern"
95 _ -> error ("BAD call to builtin patError#:" ++ (next:rest))
97 decoded ++ expand rest
99 expand (c:rest) = c : expand rest
101 ---------------------------------------------------------------
102 -- ******** defn of `_trace' using Glasgow IO *******
104 --{-# GENERATE_SPECS _trace a #-}
105 _trace :: String -> a -> a
108 = unsafePerformPrimIO (
109 ((_ccall_ PreTraceHook sTDERR{-msg-})::PrimIO ()) `seqPrimIO`
110 appendChan# sTDERR string `seqPrimIO`
111 ((_ccall_ PostTraceHook sTDERR{-msg-})::PrimIO ()) `seqPrimIO`
114 sTDERR = (``stderr'' :: _FILE)