Added MASSERT macro for assertions in do notation
[ghc.git] / compiler / HsVersions.h
1 #ifndef HSVERSIONS_H
2 #define HSVERSIONS_H
3
4 #if 0
5
6 IMPORTANT! If you put extra tabs/spaces in these macro definitions,
7 you will screw up the layout where they are used in case expressions!
8
9 (This is cpp-dependent, of course)
10
11 #endif
12
13 /* Useful in the headers that we share with the RTS */
14 #define COMPILING_GHC 1
15
16 /* Pull in all the platform defines for this build (foo_TARGET_ARCH etc.) */
17 #include "ghc_boot_platform.h"
18
19 /* Pull in the autoconf defines (HAVE_FOO), but don't include
20 * ghcconfig.h, because that will include ghcplatform.h which has the
21 * wrong platform settings for the compiler (it has the platform
22 * settings for the target plat instead). */
23 #include "../includes/ghcautoconf.h"
24
25 #if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ >= 602
26 #define SYSTEM_IO_ERROR System.IO.Error
27 #else
28 #define SYSTEM_IO_ERROR System.IO
29 #endif
30
31 /* Global variables may not work in other Haskell implementations,
32 * but we need them currently! so the conditional on GLASGOW won't do. */
33 #if defined(__GLASGOW_HASKELL__) || !defined(__GLASGOW_HASKELL__)
34 #define GLOBAL_VAR(name,value,ty) \
35 name = Util.global (value) :: IORef (ty); \
36 {-# NOINLINE name #-}
37 #endif
38
39 #define COMMA ,
40
41 #ifdef DEBUG
42 #define debugIsOn True
43 #define ASSERT(e) if (not (e)) then (assertPanic __FILE__ __LINE__) else
44 #define ASSERT2(e,msg) if (not (e)) then (assertPprPanic __FILE__ __LINE__ (msg)) else
45 #define MASSERT(e) ASSERT(e) return ()
46 #define MASSERT2(e,msg) ASSERT2(e,msg) return ()
47 #define WARN( e, msg ) (warnPprTrace (e) __FILE__ __LINE__ (msg))
48 #define ASSERTM(mbool) do { bool <- mbool; ASSERT(bool) return () }
49 #define ASSERTM2(mbool,msg) do { bool <- mbool; ASSERT2(bool,msg) return () }
50 #else
51 #define debugIsOn False
52 -- We have to actually use all the variables we are given or we may get
53 -- unused variable warnings when DEBUG is off.
54 #define ASSERT(e) if False && (not (e)) then panic "ASSERT" else
55 #define ASSERT2(e,msg) if False && (not (e)) then pprPanic "ASSERT2" (msg) else
56 #define MASSERT(e) ASSERT(e) return ()
57 #define MASSERT2(e,msg) ASSERT2(e,msg) return ()
58 #define ASSERTM(e) do { let { _mbool = (e) } }
59 -- Here we deliberately don't use when as Control.Monad might not be imported
60 #define ASSERTM2(e,msg) do { let { _mbool = (e) }; if False then panic "ASSERTM2" else return () }
61 #define WARN(e,msg) if False && (e) then pprPanic "WARN" (msg) else
62 #endif
63
64 -- This conditional lets us switch off the "import FastString"
65 -- when compiling FastString itself, or when compiling modules that
66 -- don't use it (and would otherwise get warnings, which we treat
67 -- as errors). Can we do this more nicely?
68 #if !defined(COMPILING_FAST_STRING) && !defined(FAST_STRING_NOT_NEEDED)
69 --
70 import qualified FastString as FS
71 #endif
72
73 #if defined(__GLASGOW_HASKELL__)
74 #define SLIT(x) (FS.mkLitString# (x#))
75 #define FSLIT(x) (FS.mkFastString# (x#))
76 #else
77 #define SLIT(x) (FS.mkLitString (x))
78 #define FSLIT(x) (FS.mkFastString (x))
79 #endif
80
81 -- Useful for declaring arguments to be strict
82 #define STRICT1(f) f a | a `seq` False = undefined
83 #define STRICT2(f) f a b | a `seq` b `seq` False = undefined
84 #define STRICT3(f) f a b c | a `seq` b `seq` c `seq` False = undefined
85 #define STRICT4(f) f a b c d | a `seq` b `seq` c `seq` d `seq` False = undefined
86 #define STRICT5(f) f a b c d e | a `seq` b `seq` c `seq` d `seq` e `seq` False = undefined
87 #define STRICT6(f) f a b c d e f | a `seq` b `seq` c `seq` d `seq` e `seq` f `seq` False = undefined
88
89 #endif /* HsVersions.h */
90