Add a check of the current behaviour importing duplicates
[cabal.git] / cabal-testsuite / PackageTests / CmmSourcesDyn / src / Demo.hs
blobad44a3b650e6cbbb48433d25540592dce2a0f5bf
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE ForeignFunctionInterface #-}
3 {-# LANGUAGE GHCForeignImportPrim #-}
4 {-# LANGUAGE MagicHash #-}
5 {-# LANGUAGE UnliftedFFITypes #-}
6 module Demo (main) where
8 #include "MachDeps.h"
10 import Data.Bits
11 import GHC.Exts
12 import Numeric (showHex)
14 foreign import prim "aToMyWordzh" aToWord# :: Any -> Word#
16 tAG_MASK :: Int
17 tAG_MASK = (1 `shift` TAG_BITS) - 1
19 data Box = Box Any
21 instance Show Box where
22 showsPrec _ (Box a) rs =
23 -- unsafePerformIO (print "↓" >> pClosure a) `seq`
24 pad_out (showHex addr "") ++ (if tag>0 then "/" ++ show tag else "") ++ rs
25 where
26 ptr = W# (aToWord# a)
27 tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1)
28 addr = ptr - tag
29 pad_out ls = '0':'x':ls
31 asBox :: a -> Box
32 asBox x = Box (unsafeCoerce# x)
34 main :: IO ()
35 main = do
36 let box = asBox "foobar"
37 putStrLn $ "In Box we have " ++ show box