1 #pragma once 2 3 -- For GHC_STAGE 4 #include "ghcplatform.h" 5 6 #if 0 7 8 IMPORTANT! If you put extra tabs/spaces in these macro definitions, 9 you will screw up the layout where they are used in case expressions! 10 11 (This is cpp-dependent, of course) 12 13 #endif 14 15 #define GLOBAL_VAR(name,value,ty) \ 16 {-# NOINLINE name #-}; \ 17 name :: IORef (ty); \ 18 name = Util.global (value); 19 20 #define GLOBAL_VAR_M(name,value,ty) \ 21 {-# NOINLINE name #-}; \ 22 name :: IORef (ty); \ 23 name = Util.globalM (value); 24 25 26 #define SHARED_GLOBAL_VAR(name,accessor,saccessor,value,ty) \ 27 {-# NOINLINE name #-}; \ 28 name :: IORef (ty); \ 29 name = Util.sharedGlobal (value) (accessor); \ 30 foreign import ccall unsafe saccessor \ 31 accessor :: Ptr (IORef a) -> IO (Ptr (IORef a)); 32 33 #define SHARED_GLOBAL_VAR_M(name,accessor,saccessor,value,ty) \ 34 {-# NOINLINE name #-}; \ 35 name :: IORef (ty); \ 36 name = Util.sharedGlobalM (value) (accessor); \ 37 foreign import ccall unsafe saccessor \ 38 accessor :: Ptr (IORef a) -> IO (Ptr (IORef a)); 39 40 41 #define ASSERT(e) if debugIsOn && not (e) then (assertPanic __FILE__ __LINE__) else 42 #define ASSERT2(e,msg) if debugIsOn && not (e) then (assertPprPanic __FILE__ __LINE__ (msg)) else 43 #define WARN( e, msg ) (warnPprTrace (e) __FILE__ __LINE__ (msg)) $ 44 45 -- Examples: Assuming flagSet :: String -> m Bool 46 -- 47 -- do { c <- getChar; MASSERT( isUpper c ); ... } 48 -- do { c <- getChar; MASSERT2( isUpper c, text "Bad" ); ... } 49 -- do { str <- getStr; ASSERTM( flagSet str ); .. } 50 -- do { str <- getStr; ASSERTM2( flagSet str, text "Bad" ); .. } 51 -- do { str <- getStr; WARNM2( flagSet str, text "Flag is set" ); .. } 52 #define MASSERT(e) ASSERT(e) return () 53 #define MASSERT2(e,msg) ASSERT2(e,msg) return () 54 #define ASSERTM(e) do { bool <- e; MASSERT(bool) } 55 #define ASSERTM2(e,msg) do { bool <- e; MASSERT2(bool,msg) } 56 #define WARNM2(e,msg) do { bool <- e; WARN(bool, msg) return () } 57