2 {-# LANGUAGE ForeignFunctionInterface #-}
3 {-# LANGUAGE GHCForeignImportPrim #-}
4 {-# LANGUAGE MagicHash #-}
5 {-# LANGUAGE UnliftedFFITypes #-}
6 module Demo
(main
) where
12 import Numeric
(showHex
)
14 foreign import prim
"aToMyWordzh" aToWord
# :: Any
-> Word
#
17 tAG_MASK
= (1 `shift` TAG_BITS
) - 1
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
27 tag
= ptr
.&. fromIntegral tAG_MASK
-- ((1 `shiftL` TAG_BITS) -1)
29 pad_out ls
= '0':'x
':ls
32 asBox x
= Box
(unsafeCoerce
# x
)
36 let box
= asBox
"foobar"
37 putStrLn $ "In Box we have " ++ show box