Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initialized

  • Loading branch information...
commit 0283356142abf64b1d35e9005f9f22173849155c 0 parents
@ekmett authored
39 Data/TagBits.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE CPP, BangPatterns, MagicHash #-}
+module Data.TagBits
+ (
+ -- * Determining if a closure is evaluated
+ unsafeGetTagBits
+ , unsafeIsEvaluated
+ ) where
+
+#if __GLASGOW_HASKELL__ >= 608
+-- import Data.Bits ((.&.))
+-- import Unsafe.Coerce (unsafeCoerce)
+import Foreign (sizeOf)
+import GHC.Prim
+import GHC.Types
+import GHC.Word
+-- dynamic pointer tagging is present on this platform
+#define TAGGED
+#endif
+
+-- | Inspect the dynamic pointer tagging bits of a closure. This is an impure function that relies on GHC internals and may falsely return 0, but should never give the wrong tag number if it returns a non-0 value.
+unsafeGetTagBits :: a -> Word
+{-# INLINE unsafeGetTagBits #-}
+#ifndef TAGGED
+unsafeGetTagBits _ = 0
+#else
+unsafeGetTagBits a = W# (and# (unsafeCoerce# a) (int2Word# mask#))
+ where
+ !(I# mask#) = sizeOf (undefined :: Int) - 1
+
+-- unsafeGetTagBits a = unsafeCoerce (Box a) .&. (sizeOf (undefined :: Word) - 1)
+-- data Box a = Box a
+#endif
+
+-- | Returns a guess as to whether or not a value has been evaluated. This is an impure function that relies on GHC internals and will return false negatives, but no false positives. This is unsafe as the value of this function will vary (from False to True) over the course of otherwise pure invocations!
+unsafeIsEvaluated :: a -> Bool
+unsafeIsEvaluated a = and# (unsafeCoerce# a) (int2Word# mask#) `gtWord#` int2Word# 0#
+ where
+ !(I# mask#) = sizeOf (undefined :: Int) - 1
+{-# INLINE unsafeIsEvaluated #-}
31 LICENSE
@@ -0,0 +1,31 @@
+Copyright (c) 2010, Edward Kmett
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Edward Kmett nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0  README.markdown
No changes.
3  Setup.lhs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMainWithHooks simpleUserHooks
33 tag-bits.cabal
@@ -0,0 +1,33 @@
+name: tag-bits
+version: 0.1.0
+license: BSD3
+license-file: LICENSE
+author: Edward A. Kmett
+maintainer: Edward A. Kmett <ekmett@gmail.com>
+stability: experimental
+homepage: http://github.com/ekmett/tag-bits
+category: Concurrency
+copyright: (c) 2010 Edward A. Kmett
+build-type: Simple
+cabal-version: >=1.6
+tested-with: GHC==6.12.1
+synopsis: Provides access to the dynamic pointer tagging bits used by GHC.
+description: Provides access to the dynamic pointer tagging bits used by GHC.
+
+extra-source-files:
+ README.markdown
+
+source-repository head
+ type: git
+ location: http://github.com/ekmett/tag-bits.git
+ branch: master
+
+library
+ ghc-options: -Wall
+
+ build-depends:
+ base >= 4 && < 6,
+ ghc-prim >= 0.2 && < 0.3
+
+ exposed-modules:
+ Data.TagBits
Please sign in to comment.
Something went wrong with that request. Please try again.