├── .gitignore ├── .gitmodules ├── .travis.yml ├── GenPrimOpStubs.hs ├── Main-pristine-8.0.hs ├── Main.hs ├── README.md ├── Veggies ├── ASTUtils.hs ├── CodeGen.hs ├── CodeGenTypes.hs ├── Common.hs ├── FFI.hs ├── GenMonad.hs └── Hooks.hs ├── base ├── .authorspellings ├── Control │ ├── Applicative.hs │ ├── Arrow.hs │ ├── Category.hs │ ├── Concurrent.hs │ ├── Concurrent │ │ ├── Chan.hs │ │ ├── MVar.hs │ │ ├── QSem.hs │ │ └── QSemN.hs │ ├── Exception.hs │ ├── Exception │ │ └── Base.hs │ ├── Monad.hs │ └── Monad │ │ ├── Fail.hs │ │ ├── Fix.hs │ │ ├── IO │ │ └── Class.hs │ │ ├── Instances.hs │ │ ├── ST.hs │ │ ├── ST │ │ ├── Imp.hs │ │ ├── Lazy.hs │ │ ├── Lazy │ │ │ ├── Imp.hs │ │ │ ├── Safe.hs │ │ │ └── Unsafe.hs │ │ ├── Safe.hs │ │ ├── Strict.hs │ │ └── Unsafe.hs │ │ └── Zip.hs ├── Data │ ├── Bifunctor.hs │ ├── Bits.hs │ ├── Bool.hs │ ├── Char.hs │ ├── Coerce.hs │ ├── Complex.hs │ ├── Data.hs │ ├── Dynamic.hs │ ├── Either.hs │ ├── Eq.hs │ ├── Fixed.hs │ ├── Foldable.hs │ ├── Function.hs │ ├── Functor.hs │ ├── Functor │ │ ├── Classes.hs │ │ ├── Compose.hs │ │ ├── Const.hs │ │ ├── Identity.hs │ │ ├── Product.hs │ │ └── Sum.hs │ ├── IORef.hs │ ├── Int.hs │ ├── Ix.hs │ ├── Kind.hs │ ├── List.hs │ ├── List │ │ └── NonEmpty.hs │ ├── Maybe.hs │ ├── Monoid.hs │ ├── OldList.hs │ ├── Ord.hs │ ├── Proxy.hs │ ├── Ratio.hs │ ├── STRef.hs │ ├── STRef │ │ ├── Lazy.hs │ │ └── Strict.hs │ ├── Semigroup.hs │ ├── String.hs │ ├── Traversable.hs │ ├── Tuple.hs │ ├── Type │ │ ├── Bool.hs │ │ ├── Coercion.hs │ │ └── Equality.hs │ ├── Typeable.hs │ ├── Typeable │ │ └── Internal.hs │ ├── Unique.hs │ ├── Version.hs │ ├── Void.hs │ └── Word.hs ├── Debug │ └── Trace.hs ├── Foreign.hs ├── Foreign │ ├── C.hs │ ├── C │ │ ├── Error.hs │ │ ├── String.hs │ │ └── Types.hs │ ├── Concurrent.hs │ ├── ForeignPtr.hs │ ├── ForeignPtr │ │ ├── Imp.hs │ │ ├── Safe.hs │ │ └── Unsafe.hs │ ├── Marshal.hs │ ├── Marshal │ │ ├── Alloc.hs │ │ ├── Array.hs │ │ ├── Error.hs │ │ ├── Pool.hs │ │ ├── Safe.hs │ │ ├── Unsafe.hs │ │ └── Utils.hs │ ├── Ptr.hs │ ├── Safe.hs │ ├── StablePtr.hs │ └── Storable.hs ├── GHC │ ├── Arr.hs │ ├── Base.hs │ ├── Char.hs │ ├── Conc.hs │ ├── Conc │ │ ├── IO.hs │ │ ├── Signal.hs │ │ ├── Sync.hs │ │ └── Windows.hs │ ├── ConsoleHandler.hs │ ├── Constants.hs │ ├── Desugar.hs │ ├── Enum.hs │ ├── Environment.hs │ ├── Err.hs │ ├── Event.hs │ ├── Event │ │ ├── Arr.hs │ │ ├── Array.hs │ │ ├── Clock.hsc │ │ ├── Control.hs │ │ ├── EPoll.hsc │ │ ├── IntTable.hs │ │ ├── Internal.hs │ │ ├── KQueue.hsc │ │ ├── Manager.hs │ │ ├── PSQ.hs │ │ ├── Poll.hsc │ │ ├── Thread.hs │ │ ├── TimerManager.hs │ │ └── Unique.hs │ ├── Exception.hs │ ├── Exception.hs-boot │ ├── ExecutionStack.hs │ ├── ExecutionStack │ │ └── Internal.hsc │ ├── Exts.hs │ ├── Fingerprint.hs │ ├── Fingerprint.hs-boot │ ├── Fingerprint │ │ └── Type.hs │ ├── Float.hs │ ├── Float │ │ ├── ConversionUtils.hs │ │ └── RealFracMethods.hs │ ├── Foreign.hs │ ├── ForeignPtr.hs │ ├── GHCi.hs │ ├── Generics.hs │ ├── IO.hs │ ├── IO.hs-boot │ ├── IO │ │ ├── Buffer.hs │ │ ├── BufferedIO.hs │ │ ├── Device.hs │ │ ├── Encoding.hs │ │ ├── Encoding.hs-boot │ │ ├── Encoding │ │ │ ├── CodePage.hs │ │ │ ├── CodePage │ │ │ │ ├── API.hs │ │ │ │ └── Table.hs │ │ │ ├── Failure.hs │ │ │ ├── Iconv.hs │ │ │ ├── Latin1.hs │ │ │ ├── Types.hs │ │ │ ├── UTF16.hs │ │ │ ├── UTF32.hs │ │ │ └── UTF8.hs │ │ ├── Exception.hs │ │ ├── Exception.hs-boot │ │ ├── FD.hs │ │ ├── Handle.hs │ │ ├── Handle.hs-boot │ │ ├── Handle │ │ │ ├── FD.hs │ │ │ ├── FD.hs-boot │ │ │ ├── Internals.hs │ │ │ ├── Text.hs │ │ │ └── Types.hs │ │ ├── IOMode.hs │ │ └── Unsafe.hs │ ├── IOArray.hs │ ├── IORef.hs │ ├── Int.hs │ ├── List.hs │ ├── MVar.hs │ ├── Natural.hs │ ├── Num.hs │ ├── OldList.hs │ ├── OverloadedLabels.hs │ ├── PArr.hs │ ├── Pack.hs │ ├── Profiling.hs │ ├── Ptr.hs │ ├── RTS │ │ └── Flags.hsc │ ├── Read.hs │ ├── Real.hs │ ├── ST.hs │ ├── STRef.hs │ ├── Show.hs │ ├── Stable.hs │ ├── Stack.hs │ ├── Stack │ │ ├── CCS.hs-boot │ │ ├── CCS.hsc │ │ └── Types.hs │ ├── StaticPtr.hs │ ├── Stats.hsc │ ├── Storable.hs │ ├── TopHandler.hs │ ├── TypeLits.hs │ ├── Unicode.hs │ ├── Weak.hs │ ├── Windows.hs │ └── Word.hs ├── LICENSE ├── Numeric.hs ├── Numeric │ └── Natural.hs ├── Prelude.hs ├── Setup.hs ├── System │ ├── CPUTime.hsc │ ├── Console │ │ └── GetOpt.hs │ ├── Environment.hs │ ├── Environment │ │ └── ExecutablePath.hsc │ ├── Exit.hs │ ├── IO.hs │ ├── IO │ │ ├── Error.hs │ │ └── Unsafe.hs │ ├── Info.hs │ ├── Mem.hs │ ├── Mem │ │ ├── StableName.hs │ │ └── Weak.hs │ ├── Posix │ │ ├── Internals.hs │ │ └── Types.hs │ └── Timeout.hs ├── Text │ ├── ParserCombinators │ │ ├── ReadP.hs │ │ └── ReadPrec.hs │ ├── Printf.hs │ ├── Read.hs │ ├── Read │ │ └── Lex.hs │ ├── Show.hs │ └── Show │ │ └── Functions.hs ├── Unsafe │ └── Coerce.hs ├── aclocal.m4 ├── base.buildinfo.in ├── base.cabal ├── cbits │ ├── DarwinUtils.c │ ├── PrelIOUtils.c │ ├── README.Unicode │ ├── SetEnv.c │ ├── WCsubst.c │ ├── Win32Utils.c │ ├── consUtils.c │ ├── iconv.c │ ├── inputReady.c │ ├── md5.c │ ├── primFloat.c │ ├── rts.c │ ├── sysconf.c │ └── ubconfc ├── changelog.md ├── codepages │ ├── MakeTable.hs │ └── Makefile ├── config.guess ├── config.sub ├── configure ├── configure.ac ├── include │ ├── CTypes.h │ ├── EventConfig.h │ ├── EventConfig.h.in │ ├── HsBase.h │ ├── HsBaseConfig.h │ ├── HsBaseConfig.h.in │ ├── HsEvent.h │ ├── WCsubst.h │ ├── consUtils.h │ ├── ieee-flpt.h │ └── md5.h ├── install-sh └── prologue.txt ├── boot-data ├── include │ ├── HsFFI.h │ ├── MachDeps.h │ ├── Rts.h │ ├── RtsAPI.h │ ├── Stg.h │ ├── ghcautoconf.h │ ├── ghcconfig.h │ ├── ghcplatform.h │ ├── ghcversion.h │ ├── rts │ │ ├── Adjustor.h │ │ ├── BlockSignals.h │ │ ├── Bytecodes.h │ │ ├── Config.h │ │ ├── Constants.h │ │ ├── EventLogFormat.h │ │ ├── FileLock.h │ │ ├── Flags.h │ │ ├── GetTime.h │ │ ├── Globals.h │ │ ├── Hpc.h │ │ ├── IOManager.h │ │ ├── Libdw.h │ │ ├── LibdwPool.h │ │ ├── Linker.h │ │ ├── Main.h │ │ ├── Messages.h │ │ ├── OSThreads.h │ │ ├── Parallel.h │ │ ├── PrimFloat.h │ │ ├── Signals.h │ │ ├── SpinLock.h │ │ ├── Stable.h │ │ ├── StaticPtrTable.h │ │ ├── TTY.h │ │ ├── Threads.h │ │ ├── Ticky.h │ │ ├── Timer.h │ │ ├── Types.h │ │ ├── Utils.h │ │ ├── prof │ │ │ ├── CCS.h │ │ │ └── LDV.h │ │ └── storage │ │ │ ├── Block.h │ │ │ ├── ClosureMacros.h │ │ │ ├── ClosureTypes.h │ │ │ ├── Closures.h │ │ │ ├── FunTypes.h │ │ │ ├── GC.h │ │ │ ├── InfoTables.h │ │ │ ├── MBlock.h │ │ │ ├── SMPClosureOps.h │ │ │ └── TSO.h │ └── stg │ │ ├── DLL.h │ │ ├── HaskellMachRegs.h │ │ ├── MachRegs.h │ │ ├── MiscClosures.h │ │ ├── Prim.h │ │ ├── Regs.h │ │ ├── RtsMachRegs.h │ │ ├── SMP.h │ │ ├── Ticky.h │ │ └── Types.h ├── platformConstants ├── rts.conf └── settings ├── boot.sh ├── callgraph.sh ├── fake-rts └── rts.ll ├── ghc-prim ├── GHC │ ├── CString.hs │ ├── Classes.hs │ ├── Debug.hs │ ├── IntWord64.hs │ ├── Magic.hs │ ├── Tuple.hs │ └── Types.hs ├── LICENSE ├── Setup.hs ├── cbits │ ├── atomic.c │ ├── bswap.c │ ├── clz.c │ ├── ctz.c │ ├── debug.c │ ├── longlong.c │ ├── popcnt.c │ └── word2float.c └── ghc-prim.cabal ├── integer-gmp ├── LICENSE ├── Setup.hs ├── aclocal.m4 ├── cbits │ └── wrappers.c ├── changelog.md ├── config.guess ├── config.sub ├── configure ├── configure.ac ├── gmp │ ├── config.mk.in │ ├── ghc-gmp.h │ ├── ghc.mk │ ├── gmpsrc.patch │ ├── ln │ └── tarball │ │ ├── README │ │ ├── gmp-5.0.3-nodoc-patched.tar.bz2 │ │ ├── gmp-5.0.4.patch │ │ └── patch ├── include │ ├── HsIntegerGmp.h │ ├── HsIntegerGmp.h.in │ └── ghc-gmp.h ├── install-sh ├── integer-gmp.buildinfo.in ├── integer-gmp.cabal └── src │ └── GHC │ ├── Integer.hs │ └── Integer │ ├── GMP │ └── Internals.hs │ ├── Logarithms.hs │ ├── Logarithms │ └── Internals.hs │ └── Type.hs ├── test ├── Empty.hs ├── Factorial.hs ├── Test.hs └── Thunks.hs └── vellvm-ast-pp ├── Ast2Assembly.hs ├── Ast2Ast.hs ├── Datatypes.hs ├── Ollvm_ast.hs ├── ShowAst.hs └── TestAst2Ast.hs /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | dist-* 3 | cabal-dev 4 | *.o 5 | *.hi 6 | *.chi 7 | *.chs.h 8 | *.dyn_o 9 | *.dyn_hi 10 | .hpc 11 | .hsenv 12 | .cabal-sandbox/ 13 | cabal.sandbox.config 14 | *.prof 15 | *.aux 16 | *.hp 17 | *.eventlog 18 | .stack-work/ 19 | cabal.project.local 20 | .HTF/ 21 | data 22 | test/Test 23 | boot-out 24 | Setup 25 | *.a 26 | a.out 27 | test/*.ll 28 | ghc-prim/**/*.ll 29 | base/**/*.ll 30 | integer-gmp/**/*.ll 31 | vellvm-ast-pp/ShowAst 32 | test/Factorial 33 | .gdb_history 34 | fake-rts/primops.ll 35 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "llvm-hs-pretty"] 2 | path = llvm-hs-pretty 3 | url = https://github.com/llvm-hs/llvm-hs-pretty 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: generic 3 | dist: trusty 4 | 5 | addons: 6 | apt: 7 | sources: 8 | - hvr-ghc 9 | - ubuntu-toolchain-r-test # useful dependencies of llvm 10 | - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main' 11 | key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key' 12 | packages: 13 | - cabal-install-1.24 14 | - ghc-8.0.1 15 | - alex-3.1.4 16 | - happy-1.19.5 17 | - clang-4.0 18 | - llvm-4.0 19 | - llvm-4.0-dev 20 | 21 | before_install: 22 | - export PATH=$HOME/.cabal/bin:$PATH 23 | - export PATH=/opt/cabal/1.24/bin:$PATH 24 | - export PATH=/opt/alex/3.1.4/bin:$PATH 25 | - export PATH=/opt/happy/1.19.5/bin:$PATH 26 | - export PATH=/opt/ghc/8.0.1/bin:$PATH 27 | 28 | install: 29 | - cabal update 30 | - cabal install groom 31 | - cabal install llvm-hs-pure 32 | - cabal install wl-pprint-text 33 | 34 | script: 35 | - ./boot.sh out/ 36 | -------------------------------------------------------------------------------- /base/.authorspellings: -------------------------------------------------------------------------------- 1 | Simon Marlow , simonmar, simonmar@microsoft.com 2 | Ross Paterson , ross 3 | Sven Panne , panne 4 | Malcolm Wallace , malcolm 5 | Simon Peyton Jones , simonpj 6 | Don Stewart , dons 7 | Tim Harris , tharris 8 | Lennart Augustsson , lennart.augustsson@credit-suisse.com 9 | Duncan Coutts , duncan.coutts@worc.ox.ac.uk, duncan@well-typed.com 10 | Ben Lippmeier , benl@cse.unsw.edu.au, Ben.Lippmeier@anu.edu.au 11 | Manuel M T Chakravarty , chak 12 | Jose Pedro Magalhaes , jpm@cs.uu.nl 13 | -------------------------------------------------------------------------------- /base/Control/Category.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE GADTs #-} 3 | {-# LANGUAGE NoImplicitPrelude #-} 4 | {-# LANGUAGE PolyKinds #-} 5 | {-# OPTIONS_GHC -Wno-inline-rule-shadowing #-} 6 | -- The RULES for the methods of class Category may never fire 7 | -- e.g. identity/left, identity/right, association; see Trac #10528 8 | 9 | ----------------------------------------------------------------------------- 10 | -- | 11 | -- Module : Control.Category 12 | -- Copyright : (c) Ashley Yakeley 2007 13 | -- License : BSD-style (see the LICENSE file in the distribution) 14 | -- 15 | -- Maintainer : ashley@semantic.org 16 | -- Stability : experimental 17 | -- Portability : portable 18 | 19 | -- http://ghc.haskell.org/trac/ghc/ticket/1773 20 | 21 | module Control.Category where 22 | 23 | import qualified GHC.Base (id,(.)) 24 | import Data.Type.Coercion 25 | import Data.Type.Equality 26 | import GHC.Prim (coerce) 27 | 28 | infixr 9 . 29 | infixr 1 >>>, <<< 30 | 31 | -- | A class for categories. 32 | -- id and (.) must form a monoid. 33 | class Category cat where 34 | -- | the identity morphism 35 | id :: cat a a 36 | 37 | -- | morphism composition 38 | (.) :: cat b c -> cat a b -> cat a c 39 | 40 | {-# RULES 41 | "identity/left" forall p . 42 | id . p = p 43 | "identity/right" forall p . 44 | p . id = p 45 | "association" forall p q r . 46 | (p . q) . r = p . (q . r) 47 | #-} 48 | 49 | instance Category (->) where 50 | id = GHC.Base.id 51 | (.) = (GHC.Base..) 52 | 53 | instance Category (:~:) where 54 | id = Refl 55 | Refl . Refl = Refl 56 | 57 | instance Category Coercion where 58 | id = Coercion 59 | (.) Coercion = coerce 60 | 61 | -- | Right-to-left composition 62 | (<<<) :: Category cat => cat b c -> cat a b -> cat a c 63 | (<<<) = (.) 64 | 65 | -- | Left-to-right composition 66 | (>>>) :: Category cat => cat a b -> cat b c -> cat a c 67 | f >>> g = g . f 68 | -------------------------------------------------------------------------------- /base/Control/Monad/Fail.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | -- | 5 | -- Module : Control.Monad.Fail 6 | -- Copyright : (C) 2015 David Luposchainsky, 7 | -- (C) 2015 Herbert Valerio Riedel 8 | -- License : BSD-style (see the file LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Transitional module providing the 'MonadFail' class and primitive 15 | -- instances. 16 | -- 17 | -- This module can be imported for defining forward compatible 18 | -- 'MonadFail' instances: 19 | -- 20 | -- @ 21 | -- import qualified Control.Monad.Fail as Fail 22 | -- 23 | -- instance Monad Foo where 24 | -- (>>=) = {- ...bind impl... -} 25 | -- 26 | -- -- Provide legacy 'fail' implementation for when 27 | -- -- new-style MonadFail desugaring is not enabled. 28 | -- fail = Fail.fail 29 | -- 30 | -- instance Fail.MonadFail Foo where 31 | -- fail = {- ...fail implementation... -} 32 | -- @ 33 | -- 34 | -- See 35 | -- for more details. 36 | -- 37 | -- @since 4.9.0.0 38 | -- 39 | module Control.Monad.Fail ( MonadFail(fail) ) where 40 | 41 | import GHC.Base (String, Monad(), Maybe(Nothing), IO()) 42 | import {-# SOURCE #-} GHC.IO (failIO) 43 | 44 | -- | When a value is bound in @do@-notation, the pattern on the left 45 | -- hand side of @<-@ might not match. In this case, this class 46 | -- provides a function to recover. 47 | -- 48 | -- A 'Monad' without a 'MonadFail' instance may only be used in conjunction 49 | -- with pattern that always match, such as newtypes, tuples, data types with 50 | -- only a single data constructor, and irrefutable patterns (@~pat@). 51 | -- 52 | -- Instances of 'MonadFail' should satisfy the following law: @fail s@ should 53 | -- be a left zero for '>>=', 54 | -- 55 | -- @ 56 | -- fail s >>= f = fail s 57 | -- @ 58 | -- 59 | -- If your 'Monad' is also 'MonadPlus', a popular definition is 60 | -- 61 | -- @ 62 | -- fail _ = mzero 63 | -- @ 64 | -- 65 | -- @since 4.9.0.0 66 | class Monad m => MonadFail m where 67 | fail :: String -> m a 68 | 69 | 70 | instance MonadFail Maybe where 71 | fail _ = Nothing 72 | 73 | instance MonadFail [] where 74 | {-# INLINE fail #-} 75 | fail _ = [] 76 | 77 | instance MonadFail IO where 78 | fail = failIO 79 | -------------------------------------------------------------------------------- /base/Control/Monad/IO/Class.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | ----------------------------------------------------------------------------- 3 | -- | 4 | -- Module : Control.Monad.IO.Class 5 | -- Copyright : (c) Andy Gill 2001, 6 | -- (c) Oregon Graduate Institute of Science and Technology, 2001 7 | -- License : BSD-style (see the file LICENSE) 8 | -- 9 | -- Maintainer : R.Paterson@city.ac.uk 10 | -- Stability : experimental 11 | -- Portability : portable 12 | -- 13 | -- Class of monads based on @IO@. 14 | ----------------------------------------------------------------------------- 15 | 16 | module Control.Monad.IO.Class ( 17 | MonadIO(..) 18 | ) where 19 | 20 | -- | Monads in which 'IO' computations may be embedded. 21 | -- Any monad built by applying a sequence of monad transformers to the 22 | -- 'IO' monad will be an instance of this class. 23 | -- 24 | -- Instances should satisfy the following laws, which state that 'liftIO' 25 | -- is a transformer of monads: 26 | -- 27 | -- * @'liftIO' . 'return' = 'return'@ 28 | -- 29 | -- * @'liftIO' (m >>= f) = 'liftIO' m >>= ('liftIO' . f)@ 30 | 31 | class (Monad m) => MonadIO m where 32 | -- | Lift a computation from the 'IO' monad. 33 | liftIO :: IO a -> m a 34 | 35 | instance MonadIO IO where 36 | liftIO = id 37 | -------------------------------------------------------------------------------- /base/Control/Monad/Instances.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.Instances 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : portable 12 | -- 13 | -- /This module is DEPRECATED and will be removed in the future!/ 14 | -- 15 | -- 'Functor' and 'Monad' instances for @(->) r@ and 16 | -- 'Functor' instances for @(,) a@ and @'Either' a@. 17 | 18 | module Control.Monad.Instances {-# DEPRECATED "This module now contains no instances and will be removed in the future" #-} -- deprecated in 7.8 19 | (Functor(..),Monad(..)) where 20 | -------------------------------------------------------------------------------- /base/Control/Monad/ST.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : experimental 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- This library provides support for /strict/ state threads, as 14 | -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton 15 | -- Jones /Lazy Functional State Threads/. 16 | -- 17 | -- References (variables) that can be used within the @ST@ monad are 18 | -- provided by "Data.STRef", and arrays are provided by 19 | -- "Data.Array.ST". 20 | 21 | ----------------------------------------------------------------------------- 22 | 23 | module Control.Monad.ST ( 24 | -- * The 'ST' Monad 25 | ST, -- abstract, instance of Functor, Monad, Typeable. 26 | runST, 27 | fixST, 28 | 29 | -- * Converting 'ST' to 'IO' 30 | RealWorld, -- abstract 31 | stToIO, 32 | ) where 33 | 34 | import Control.Monad.ST.Imp 35 | 36 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Imp.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# OPTIONS_HADDOCK hide #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Control.Monad.ST.Imp 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : non-portable (requires universal quantification for runST) 13 | -- 14 | -- This library provides support for /strict/ state threads, as 15 | -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton 16 | -- Jones /Lazy Functional State Threads/. 17 | -- 18 | ----------------------------------------------------------------------------- 19 | 20 | module Control.Monad.ST.Imp ( 21 | -- * The 'ST' Monad 22 | ST, -- abstract, instance of Functor, Monad, Typeable. 23 | runST, 24 | fixST, 25 | 26 | -- * Converting 'ST' to 'IO' 27 | RealWorld, -- abstract 28 | stToIO, 29 | 30 | -- * Unsafe operations 31 | unsafeInterleaveST, 32 | unsafeIOToST, 33 | unsafeSTToIO 34 | ) where 35 | 36 | import GHC.ST ( ST, runST, fixST, unsafeInterleaveST ) 37 | import GHC.Base ( RealWorld ) 38 | import GHC.IO ( stToIO, unsafeIOToST, unsafeSTToIO ) 39 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Lazy.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST.Lazy 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- This module presents an identical interface to "Control.Monad.ST", 14 | -- except that the monad delays evaluation of state operations until 15 | -- a value depending on them is required. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Control.Monad.ST.Lazy ( 20 | -- * The 'ST' monad 21 | ST, 22 | runST, 23 | fixST, 24 | 25 | -- * Converting between strict and lazy 'ST' 26 | strictToLazyST, lazyToStrictST, 27 | 28 | -- * Converting 'ST' To 'IO' 29 | RealWorld, 30 | stToIO, 31 | ) where 32 | 33 | import Control.Monad.ST.Lazy.Imp 34 | 35 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Lazy/Safe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST.Lazy.Safe 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- This module presents an identical interface to "Control.Monad.ST", 14 | -- except that the monad delays evaluation of state operations until 15 | -- a value depending on them is required. 16 | -- 17 | -- Safe API only. 18 | -- 19 | ----------------------------------------------------------------------------- 20 | 21 | module Control.Monad.ST.Lazy.Safe {-# DEPRECATED "Safe is now the default, please use Control.Monad.ST.Lazy instead" #-} ( 22 | -- * The 'ST' monad 23 | ST, 24 | runST, 25 | fixST, 26 | 27 | -- * Converting between strict and lazy 'ST' 28 | strictToLazyST, lazyToStrictST, 29 | 30 | -- * Converting 'ST' To 'IO' 31 | RealWorld, 32 | stToIO, 33 | ) where 34 | 35 | import Control.Monad.ST.Lazy.Imp 36 | 37 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Lazy/Unsafe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST.Lazy.Unsafe 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- This module presents an identical interface to "Control.Monad.ST", 14 | -- except that the monad delays evaluation of state operations until 15 | -- a value depending on them is required. 16 | -- 17 | -- Unsafe API. 18 | -- 19 | ----------------------------------------------------------------------------- 20 | 21 | module Control.Monad.ST.Lazy.Unsafe ( 22 | -- * Unsafe operations 23 | unsafeInterleaveST, 24 | unsafeIOToST 25 | ) where 26 | 27 | import Control.Monad.ST.Lazy.Imp 28 | 29 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Safe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST.Safe 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : experimental 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- This library provides support for /strict/ state threads, as 14 | -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton 15 | -- Jones /Lazy Functional State Threads/. 16 | -- 17 | -- Safe API Only. 18 | -- 19 | ----------------------------------------------------------------------------- 20 | 21 | module Control.Monad.ST.Safe {-# DEPRECATED "Safe is now the default, please use Control.Monad.ST instead" #-} ( 22 | -- * The 'ST' Monad 23 | ST, -- abstract 24 | runST, 25 | fixST, 26 | 27 | -- * Converting 'ST' to 'IO' 28 | RealWorld, -- abstract 29 | stToIO, 30 | ) where 31 | 32 | import Control.Monad.ST.Imp 33 | 34 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Strict.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST.Strict 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- The strict ST monad (re-export of "Control.Monad.ST") 14 | -- 15 | ----------------------------------------------------------------------------- 16 | 17 | module Control.Monad.ST.Strict ( 18 | module Control.Monad.ST 19 | ) where 20 | 21 | import Control.Monad.ST 22 | 23 | -------------------------------------------------------------------------------- /base/Control/Monad/ST/Unsafe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Control.Monad.ST.Unsafe 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : experimental 11 | -- Portability : non-portable (requires universal quantification for runST) 12 | -- 13 | -- This library provides support for /strict/ state threads, as 14 | -- described in the PLDI \'94 paper by John Launchbury and Simon Peyton 15 | -- Jones /Lazy Functional State Threads/. 16 | -- 17 | -- Unsafe API. 18 | -- 19 | ----------------------------------------------------------------------------- 20 | 21 | module Control.Monad.ST.Unsafe ( 22 | -- * Unsafe operations 23 | unsafeInterleaveST, 24 | unsafeIOToST, 25 | unsafeSTToIO 26 | ) where 27 | 28 | import Control.Monad.ST.Imp 29 | 30 | -------------------------------------------------------------------------------- /base/Data/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Bool 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- The 'Bool' type and related functions. 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Bool ( 19 | -- * Booleans 20 | Bool(..), 21 | -- ** Operations 22 | (&&), 23 | (||), 24 | not, 25 | otherwise, 26 | bool, 27 | ) where 28 | 29 | import GHC.Base 30 | 31 | -- | Case analysis for the 'Bool' type. @'bool' x y p@ evaluates to @x@ 32 | -- when @p@ is 'False', and evaluates to @y@ when @p@ is 'True'. 33 | -- 34 | -- This is equivalent to @if p then y else x@; that is, one can 35 | -- think of it as an if-then-else construct with its arguments 36 | -- reordered. 37 | -- 38 | -- @since 4.7.0.0 39 | -- 40 | -- ==== __Examples__ 41 | -- 42 | -- Basic usage: 43 | -- 44 | -- >>> bool "foo" "bar" True 45 | -- "bar" 46 | -- >>> bool "foo" "bar" False 47 | -- "foo" 48 | -- 49 | -- Confirm that @'bool' x y p@ and @if p then y else x@ are 50 | -- equivalent: 51 | -- 52 | -- >>> let p = True; x = "bar"; y = "foo" 53 | -- >>> bool x y p == if p then y else x 54 | -- True 55 | -- >>> let p = False 56 | -- >>> bool x y p == if p then y else x 57 | -- True 58 | -- 59 | bool :: a -> a -> Bool -> a 60 | bool f _ False = f 61 | bool _ t True = t 62 | -------------------------------------------------------------------------------- /base/Data/Coerce.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Coerce 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Safe coercions between data types. 15 | -- 16 | -- More in-depth information can be found on the 17 | -- 18 | -- 19 | -- @since 4.7.0.0 20 | ----------------------------------------------------------------------------- 21 | 22 | module Data.Coerce 23 | ( -- * Safe coercions 24 | coerce, Coercible, 25 | ) where 26 | import GHC.Prim (coerce) 27 | import GHC.Types (Coercible) 28 | 29 | import GHC.Base () -- for build ordering; see Notes in GHC.Base for more info 30 | -------------------------------------------------------------------------------- /base/Data/Eq.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Eq 7 | -- Copyright : (c) The University of Glasgow 2005 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : stable 12 | -- Portability : portable 13 | -- 14 | -- Equality 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Eq ( 19 | Eq(..), 20 | ) where 21 | 22 | import GHC.Base 23 | -------------------------------------------------------------------------------- /base/Data/Function.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Function 7 | -- Copyright : Nils Anders Danielsson 2006 8 | -- , Alexander Berntsen 2014 9 | -- License : BSD-style (see the LICENSE file in the distribution) 10 | -- 11 | -- Maintainer : libraries@haskell.org 12 | -- Stability : experimental 13 | -- Portability : portable 14 | -- 15 | -- Simple combinators working solely on and with functions. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Data.Function 20 | ( -- * "Prelude" re-exports 21 | id, const, (.), flip, ($) 22 | -- * Other combinators 23 | , (&) 24 | , fix 25 | , on 26 | ) where 27 | 28 | import GHC.Base ( ($), (.), id, const, flip ) 29 | 30 | infixl 0 `on` 31 | infixl 1 & 32 | 33 | -- | @'fix' f@ is the least fixed point of the function @f@, 34 | -- i.e. the least defined @x@ such that @f x = x@. 35 | fix :: (a -> a) -> a 36 | fix f = let x = f x in x 37 | 38 | -- | @(*) \`on\` f = \\x y -> f x * f y@. 39 | -- 40 | -- Typical usage: @'Data.List.sortBy' ('compare' \`on\` 'fst')@. 41 | -- 42 | -- Algebraic properties: 43 | -- 44 | -- * @(*) \`on\` 'id' = (*)@ (if @(*) ∉ {⊥, 'const' ⊥}@) 45 | -- 46 | -- * @((*) \`on\` f) \`on\` g = (*) \`on\` (f . g)@ 47 | -- 48 | -- * @'flip' on f . 'flip' on g = 'flip' on (g . f)@ 49 | 50 | -- Proofs (so that I don't have to edit the test-suite): 51 | 52 | -- (*) `on` id 53 | -- = 54 | -- \x y -> id x * id y 55 | -- = 56 | -- \x y -> x * y 57 | -- = { If (*) /= _|_ or const _|_. } 58 | -- (*) 59 | 60 | -- (*) `on` f `on` g 61 | -- = 62 | -- ((*) `on` f) `on` g 63 | -- = 64 | -- \x y -> ((*) `on` f) (g x) (g y) 65 | -- = 66 | -- \x y -> (\x y -> f x * f y) (g x) (g y) 67 | -- = 68 | -- \x y -> f (g x) * f (g y) 69 | -- = 70 | -- \x y -> (f . g) x * (f . g) y 71 | -- = 72 | -- (*) `on` (f . g) 73 | -- = 74 | -- (*) `on` f . g 75 | 76 | -- flip on f . flip on g 77 | -- = 78 | -- (\h (*) -> (*) `on` h) f . (\h (*) -> (*) `on` h) g 79 | -- = 80 | -- (\(*) -> (*) `on` f) . (\(*) -> (*) `on` g) 81 | -- = 82 | -- \(*) -> (*) `on` g `on` f 83 | -- = { See above. } 84 | -- \(*) -> (*) `on` g . f 85 | -- = 86 | -- (\h (*) -> (*) `on` h) (g . f) 87 | -- = 88 | -- flip on (g . f) 89 | 90 | on :: (b -> b -> c) -> (a -> b) -> a -> a -> c 91 | (.*.) `on` f = \x y -> f x .*. f y 92 | 93 | 94 | -- | '&' is a reverse application operator. This provides notational 95 | -- convenience. Its precedence is one higher than that of the forward 96 | -- application operator '$', which allows '&' to be nested in '$'. 97 | -- 98 | -- @since 4.8.0.0 99 | (&) :: a -> (a -> b) -> b 100 | x & f = f x 101 | -------------------------------------------------------------------------------- /base/Data/Functor/Const.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 3 | {-# LANGUAGE NoImplicitPrelude #-} 4 | {-# LANGUAGE PolyKinds #-} 5 | {-# LANGUAGE ScopedTypeVariables #-} 6 | {-# LANGUAGE Trustworthy #-} 7 | 8 | ----------------------------------------------------------------------------- 9 | -- | 10 | -- Module : Data.Functor.Const 11 | -- Copyright : Conor McBride and Ross Paterson 2005 12 | -- License : BSD-style (see the LICENSE file in the distribution) 13 | -- 14 | -- Maintainer : libraries@haskell.org 15 | -- Stability : experimental 16 | -- Portability : portable 17 | 18 | -- The 'Const' functor. 19 | -- 20 | -- @since 4.9.0.0 21 | 22 | module Data.Functor.Const (Const(..)) where 23 | 24 | import Data.Bits (Bits, FiniteBits) 25 | import Data.Foldable (Foldable(foldMap)) 26 | import Foreign.Storable (Storable) 27 | 28 | import GHC.Arr (Ix) 29 | import GHC.Base 30 | import GHC.Enum (Bounded, Enum) 31 | import GHC.Float (Floating, RealFloat) 32 | import GHC.Generics (Generic, Generic1) 33 | import GHC.Num (Num) 34 | import GHC.Real (Fractional, Integral, Real, RealFrac) 35 | import GHC.Read (Read(readsPrec), readParen, lex) 36 | import GHC.Show (Show(showsPrec), showParen, showString) 37 | 38 | -- | The 'Const' functor. 39 | newtype Const a b = Const { getConst :: a } 40 | deriving ( Bits, Bounded, Enum, Eq, FiniteBits, Floating, Fractional 41 | , Generic, Generic1, Integral, Ix, Monoid, Num, Ord, Real 42 | , RealFrac, RealFloat , Storable) 43 | 44 | -- | This instance would be equivalent to the derived instances of the 45 | -- 'Const' newtype if the 'runConst' field were removed 46 | instance Read a => Read (Const a b) where 47 | readsPrec d = readParen (d > 10) 48 | $ \r -> [(Const x,t) | ("Const", s) <- lex r, (x, t) <- readsPrec 11 s] 49 | 50 | -- | This instance would be equivalent to the derived instances of the 51 | -- 'Const' newtype if the 'runConst' field were removed 52 | instance Show a => Show (Const a b) where 53 | showsPrec d (Const x) = showParen (d > 10) $ 54 | showString "Const " . showsPrec 11 x 55 | 56 | instance Foldable (Const m) where 57 | foldMap _ _ = mempty 58 | 59 | instance Functor (Const m) where 60 | fmap _ (Const v) = Const v 61 | 62 | instance Monoid m => Applicative (Const m) where 63 | pure _ = Const mempty 64 | (<*>) = coerce (mappend :: m -> m -> m) 65 | -- This is pretty much the same as 66 | -- Const f <*> Const v = Const (f `mappend` v) 67 | -- but guarantees that mappend for Const a b will have the same arity 68 | -- as the one for a; it won't create a closure to raise the arity 69 | -- to 2. 70 | -------------------------------------------------------------------------------- /base/Data/Functor/Sum.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveDataTypeable #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE PolyKinds #-} 4 | {-# LANGUAGE Safe #-} 5 | ----------------------------------------------------------------------------- 6 | -- | 7 | -- Module : Data.Functor.Sum 8 | -- Copyright : (c) Ross Paterson 2014 9 | -- License : BSD-style (see the file LICENSE) 10 | -- 11 | -- Maintainer : libraries@haskell.org 12 | -- Stability : experimental 13 | -- Portability : portable 14 | -- 15 | -- Sums, lifted to functors. 16 | -- 17 | -- @since 4.9.0.0 18 | ----------------------------------------------------------------------------- 19 | 20 | module Data.Functor.Sum ( 21 | Sum(..), 22 | ) where 23 | 24 | import Data.Data (Data) 25 | import Data.Foldable (Foldable(foldMap)) 26 | import Data.Functor.Classes 27 | import Data.Monoid (mappend) 28 | import Data.Traversable (Traversable(traverse)) 29 | import GHC.Generics (Generic, Generic1) 30 | 31 | -- | Lifted sum of functors. 32 | data Sum f g a = InL (f a) | InR (g a) 33 | deriving (Data, Generic, Generic1) 34 | 35 | instance (Eq1 f, Eq1 g) => Eq1 (Sum f g) where 36 | liftEq eq (InL x1) (InL x2) = liftEq eq x1 x2 37 | liftEq _ (InL _) (InR _) = False 38 | liftEq _ (InR _) (InL _) = False 39 | liftEq eq (InR y1) (InR y2) = liftEq eq y1 y2 40 | 41 | instance (Ord1 f, Ord1 g) => Ord1 (Sum f g) where 42 | liftCompare comp (InL x1) (InL x2) = liftCompare comp x1 x2 43 | liftCompare _ (InL _) (InR _) = LT 44 | liftCompare _ (InR _) (InL _) = GT 45 | liftCompare comp (InR y1) (InR y2) = liftCompare comp y1 y2 46 | 47 | instance (Read1 f, Read1 g) => Read1 (Sum f g) where 48 | liftReadsPrec rp rl = readsData $ 49 | readsUnaryWith (liftReadsPrec rp rl) "InL" InL `mappend` 50 | readsUnaryWith (liftReadsPrec rp rl) "InR" InR 51 | 52 | instance (Show1 f, Show1 g) => Show1 (Sum f g) where 53 | liftShowsPrec sp sl d (InL x) = 54 | showsUnaryWith (liftShowsPrec sp sl) "InL" d x 55 | liftShowsPrec sp sl d (InR y) = 56 | showsUnaryWith (liftShowsPrec sp sl) "InR" d y 57 | 58 | instance (Eq1 f, Eq1 g, Eq a) => Eq (Sum f g a) where 59 | (==) = eq1 60 | instance (Ord1 f, Ord1 g, Ord a) => Ord (Sum f g a) where 61 | compare = compare1 62 | instance (Read1 f, Read1 g, Read a) => Read (Sum f g a) where 63 | readsPrec = readsPrec1 64 | instance (Show1 f, Show1 g, Show a) => Show (Sum f g a) where 65 | showsPrec = showsPrec1 66 | 67 | instance (Functor f, Functor g) => Functor (Sum f g) where 68 | fmap f (InL x) = InL (fmap f x) 69 | fmap f (InR y) = InR (fmap f y) 70 | 71 | instance (Foldable f, Foldable g) => Foldable (Sum f g) where 72 | foldMap f (InL x) = foldMap f x 73 | foldMap f (InR y) = foldMap f y 74 | 75 | instance (Traversable f, Traversable g) => Traversable (Sum f g) where 76 | traverse f (InL x) = InL <$> traverse f x 77 | traverse f (InR y) = InR <$> traverse f y 78 | -------------------------------------------------------------------------------- /base/Data/Int.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Int 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- Signed integer types 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Int 19 | ( 20 | -- * Signed integer types 21 | Int, 22 | Int8, Int16, Int32, Int64, 23 | 24 | -- * Notes 25 | 26 | -- $notes 27 | ) where 28 | 29 | import GHC.Base ( Int ) 30 | import GHC.Int ( Int8, Int16, Int32, Int64 ) 31 | 32 | {- $notes 33 | 34 | * All arithmetic is performed modulo 2^n, where @n@ is the number of 35 | bits in the type. 36 | 37 | * For coercing between any two integer types, use 'Prelude.fromIntegral', 38 | which is specialized for all the common cases so should be fast 39 | enough. Coercing word types (see "Data.Word") to and from integer 40 | types preserves representation, not sign. 41 | 42 | * The rules that hold for 'Prelude.Enum' instances over a 43 | bounded type such as 'Int' (see the section of the 44 | Haskell report dealing with arithmetic sequences) also hold for the 45 | 'Prelude.Enum' instances over the various 46 | 'Int' types defined here. 47 | 48 | * Right and left shifts by amounts greater than or equal to the width 49 | of the type result in either zero or -1, depending on the sign of 50 | the value being shifted. This is contrary to the behaviour in C, 51 | which is undefined; a common interpretation is to truncate the shift 52 | count to the width of the type, for example @1 \<\< 32 53 | == 1@ in some C implementations. 54 | -} 55 | 56 | -------------------------------------------------------------------------------- /base/Data/Ix.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Data.Ix 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : stable 11 | -- Portability : portable 12 | -- 13 | -- The 'Ix' class is used to map a contiguous subrange of values in 14 | -- type onto integers. It is used primarily for array indexing 15 | -- (see the array package). 'Ix' uses row-major order. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Data.Ix 20 | ( 21 | -- * The 'Ix' class 22 | Ix 23 | ( range 24 | , index 25 | , inRange 26 | , rangeSize 27 | ) 28 | -- Ix instances: 29 | -- 30 | -- Ix Char 31 | -- Ix Int 32 | -- Ix Integer 33 | -- Ix Bool 34 | -- Ix Ordering 35 | -- Ix () 36 | -- (Ix a, Ix b) => Ix (a, b) 37 | -- ... 38 | 39 | -- * Deriving Instances of 'Ix' 40 | -- | Derived instance declarations for the class 'Ix' are only possible 41 | -- for enumerations (i.e. datatypes having only nullary constructors) 42 | -- and single-constructor datatypes, including arbitrarily large tuples, 43 | -- whose constituent types are instances of 'Ix'. 44 | -- 45 | -- * For an enumeration, the nullary constructors are assumed to be 46 | -- numbered left-to-right with the indices being 0 to n-1 inclusive. This 47 | -- is the same numbering defined by the 'Enum' class. For example, given 48 | -- the datatype: 49 | -- 50 | -- > data Colour = Red | Orange | Yellow | Green | Blue | Indigo | Violet 51 | -- 52 | -- we would have: 53 | -- 54 | -- > range (Yellow,Blue) == [Yellow,Green,Blue] 55 | -- > index (Yellow,Blue) Green == 1 56 | -- > inRange (Yellow,Blue) Red == False 57 | -- 58 | -- * For single-constructor datatypes, the derived instance declarations 59 | -- are as shown for tuples in chapter 19, section 2 of the Haskell 2010 report: 60 | -- . 61 | 62 | ) where 63 | 64 | import GHC.Arr 65 | -------------------------------------------------------------------------------- /base/Data/Kind.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy, ExplicitNamespaces #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Data.Kind 6 | -- License : BSD-style (see the LICENSE file in the distribution) 7 | -- 8 | -- Maintainer : libraries@haskell.org 9 | -- Stability : experimental 10 | -- Portability : not portable 11 | -- 12 | -- Basic kinds 13 | -- 14 | -- @since 4.9.0.0 15 | ----------------------------------------------------------------------------- 16 | 17 | module Data.Kind ( Type, Constraint, type (*), type (★) ) where 18 | 19 | import GHC.Types 20 | -------------------------------------------------------------------------------- /base/Data/Ord.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Ord 7 | -- Copyright : (c) The University of Glasgow 2005 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : stable 12 | -- Portability : portable 13 | -- 14 | -- Orderings 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Ord ( 19 | Ord(..), 20 | Ordering(..), 21 | Down(..), 22 | comparing, 23 | ) where 24 | 25 | import GHC.Base 26 | import GHC.Show 27 | import GHC.Read 28 | 29 | -- | 30 | -- > comparing p x y = compare (p x) (p y) 31 | -- 32 | -- Useful combinator for use in conjunction with the @xxxBy@ family 33 | -- of functions from "Data.List", for example: 34 | -- 35 | -- > ... sortBy (comparing fst) ... 36 | comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering 37 | comparing p x y = compare (p x) (p y) 38 | 39 | -- | The 'Down' type allows you to reverse sort order conveniently. A value of type 40 | -- @'Down' a@ contains a value of type @a@ (represented as @'Down' a@). 41 | -- If @a@ has an @'Ord'@ instance associated with it then comparing two 42 | -- values thus wrapped will give you the opposite of their normal sort order. 43 | -- This is particularly useful when sorting in generalised list comprehensions, 44 | -- as in: @then sortWith by 'Down' x@ 45 | -- 46 | -- Provides 'Show' and 'Read' instances (/since: 4.7.0.0/). 47 | -- 48 | -- @since 4.6.0.0 49 | newtype Down a = Down a deriving (Eq, Show, Read) 50 | 51 | instance Ord a => Ord (Down a) where 52 | compare (Down x) (Down y) = y `compare` x 53 | -------------------------------------------------------------------------------- /base/Data/STRef.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Data.STRef 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : experimental 11 | -- Portability : non-portable (uses Control.Monad.ST) 12 | -- 13 | -- Mutable references in the (strict) ST monad. 14 | -- 15 | ----------------------------------------------------------------------------- 16 | 17 | module Data.STRef ( 18 | -- * STRefs 19 | STRef, -- abstract 20 | newSTRef, 21 | readSTRef, 22 | writeSTRef, 23 | modifySTRef, 24 | modifySTRef' 25 | ) where 26 | 27 | import GHC.ST 28 | import GHC.STRef 29 | 30 | -- | Mutate the contents of an 'STRef'. 31 | -- 32 | -- Be warned that 'modifySTRef' does not apply the function strictly. This 33 | -- means if the program calls 'modifySTRef' many times, but seldomly uses the 34 | -- value, thunks will pile up in memory resulting in a space leak. This is a 35 | -- common mistake made when using an STRef as a counter. For example, the 36 | -- following will leak memory and likely produce a stack overflow: 37 | -- 38 | -- >print $ runST $ do 39 | -- > ref <- newSTRef 0 40 | -- > replicateM_ 1000000 $ modifySTRef ref (+1) 41 | -- > readSTRef ref 42 | -- 43 | -- To avoid this problem, use 'modifySTRef'' instead. 44 | modifySTRef :: STRef s a -> (a -> a) -> ST s () 45 | modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref 46 | 47 | -- | Strict version of 'modifySTRef' 48 | -- 49 | -- @since 4.6.0.0 50 | modifySTRef' :: STRef s a -> (a -> a) -> ST s () 51 | modifySTRef' ref f = do 52 | x <- readSTRef ref 53 | let x' = f x 54 | x' `seq` writeSTRef ref x' 55 | -------------------------------------------------------------------------------- /base/Data/STRef/Lazy.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Data.STRef.Lazy 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : experimental 11 | -- Portability : non-portable (uses Control.Monad.ST.Lazy) 12 | -- 13 | -- Mutable references in the lazy ST monad. 14 | -- 15 | ----------------------------------------------------------------------------- 16 | 17 | module Data.STRef.Lazy ( 18 | -- * STRefs 19 | ST.STRef, -- abstract 20 | newSTRef, 21 | readSTRef, 22 | writeSTRef, 23 | modifySTRef 24 | ) where 25 | 26 | import Control.Monad.ST.Lazy 27 | import qualified Data.STRef as ST 28 | 29 | newSTRef :: a -> ST s (ST.STRef s a) 30 | readSTRef :: ST.STRef s a -> ST s a 31 | writeSTRef :: ST.STRef s a -> a -> ST s () 32 | modifySTRef :: ST.STRef s a -> (a -> a) -> ST s () 33 | 34 | newSTRef = strictToLazyST . ST.newSTRef 35 | readSTRef = strictToLazyST . ST.readSTRef 36 | writeSTRef r a = strictToLazyST (ST.writeSTRef r a) 37 | modifySTRef r f = strictToLazyST (ST.modifySTRef r f) 38 | 39 | -------------------------------------------------------------------------------- /base/Data/STRef/Strict.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Data.STRef.Strict 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : non-portable (uses Control.Monad.ST.Strict) 12 | -- 13 | -- Mutable references in the (strict) ST monad (re-export of "Data.STRef") 14 | -- 15 | ----------------------------------------------------------------------------- 16 | 17 | module Data.STRef.Strict ( 18 | module Data.STRef 19 | ) where 20 | 21 | import Data.STRef 22 | 23 | -------------------------------------------------------------------------------- /base/Data/String.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude, FlexibleInstances #-} 3 | {-# LANGUAGE TypeFamilies #-} 4 | 5 | ----------------------------------------------------------------------------- 6 | -- | 7 | -- Module : Data.String 8 | -- Copyright : (c) The University of Glasgow 2007 9 | -- License : BSD-style (see the file libraries/base/LICENSE) 10 | -- 11 | -- Maintainer : libraries@haskell.org 12 | -- Stability : experimental 13 | -- Portability : portable 14 | -- 15 | -- The @String@ type and associated operations. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Data.String ( 20 | String 21 | , IsString(..) 22 | 23 | -- * Functions on strings 24 | , lines 25 | , words 26 | , unlines 27 | , unwords 28 | ) where 29 | 30 | import GHC.Base 31 | import Data.Functor.Const (Const (Const)) 32 | import Data.List (lines, words, unlines, unwords) 33 | 34 | -- | Class for string-like datastructures; used by the overloaded string 35 | -- extension (-XOverloadedStrings in GHC). 36 | class IsString a where 37 | fromString :: String -> a 38 | 39 | {- Note [IsString String] 40 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 41 | Previously, the IsString instance that covered String was a flexible 42 | instance for [Char]. This is in some sense the most accurate choice, 43 | but there are cases where it can lead to an ambiguity, for instance: 44 | 45 | show $ "foo" ++ "bar" 46 | 47 | The use of (++) ensures that "foo" and "bar" must have type [t] for 48 | some t, but a flexible instance for [Char] will _only_ match if 49 | something further determines t to be Char, and nothing in the above 50 | example actually does. 51 | 52 | So, the above example generates an error about the ambiguity of t, 53 | and what's worse, the above behavior can be generated by simply 54 | typing: 55 | 56 | "foo" ++ "bar" 57 | 58 | into GHCi with the OverloadedStrings extension enabled. 59 | 60 | The new instance fixes this by defining an instance that matches all 61 | [a], and forces a to be Char. This instance, of course, overlaps 62 | with things that the [Char] flexible instance doesn't, but this was 63 | judged to be an acceptable cost, for the gain of providing a less 64 | confusing experience for people experimenting with overloaded strings. 65 | 66 | It may be possible to fix this via (extended) defaulting. Currently, 67 | the rules are not able to default t to Char in the above example. If 68 | a more flexible system that enabled this defaulting were put in place, 69 | then it would probably make sense to revert to the flexible [Char] 70 | instance, since extended defaulting is enabled in GHCi. However, it 71 | is not clear at the time of this note exactly what such a system 72 | would be, and it certainly hasn't been implemented. 73 | 74 | A test case (should_run/overloadedstringsrun01.hs) has been added to 75 | ensure the good behavior of the above example remains in the future. 76 | -} 77 | 78 | instance (a ~ Char) => IsString [a] where 79 | -- See Note [IsString String] 80 | fromString xs = xs 81 | 82 | instance IsString a => IsString (Const a b) where 83 | fromString = Const . fromString 84 | -------------------------------------------------------------------------------- /base/Data/Tuple.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Tuple 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- The tuple data types, and associated functions. 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Tuple 19 | ( fst 20 | , snd 21 | , curry 22 | , uncurry 23 | , swap 24 | ) where 25 | 26 | import GHC.Base () -- Note [Depend on GHC.Tuple] 27 | 28 | default () -- Double isn't available yet 29 | 30 | -- --------------------------------------------------------------------------- 31 | -- Standard functions over tuples 32 | 33 | -- | Extract the first component of a pair. 34 | fst :: (a,b) -> a 35 | fst (x,_) = x 36 | 37 | -- | Extract the second component of a pair. 38 | snd :: (a,b) -> b 39 | snd (_,y) = y 40 | 41 | -- | 'curry' converts an uncurried function to a curried function. 42 | curry :: ((a, b) -> c) -> a -> b -> c 43 | curry f x y = f (x, y) 44 | 45 | -- | 'uncurry' converts a curried function to a function on pairs. 46 | uncurry :: (a -> b -> c) -> ((a, b) -> c) 47 | uncurry f p = f (fst p) (snd p) 48 | 49 | -- | Swap the components of a pair. 50 | swap :: (a,b) -> (b,a) 51 | swap (a,b) = (b,a) 52 | -------------------------------------------------------------------------------- /base/Data/Type/Bool.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, NoImplicitPrelude, 3 | PolyKinds #-} 4 | 5 | ----------------------------------------------------------------------------- 6 | -- | 7 | -- Module : Data.Type.Bool 8 | -- License : BSD-style (see the LICENSE file in the distribution) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : not portable 13 | -- 14 | -- Basic operations on type-level Booleans. 15 | -- 16 | -- @since 4.7.0.0 17 | ----------------------------------------------------------------------------- 18 | 19 | module Data.Type.Bool ( 20 | If, type (&&), type (||), Not 21 | ) where 22 | 23 | import Data.Bool 24 | 25 | -- This needs to be in base because (&&) is used in Data.Type.Equality. 26 | -- The other functions do not need to be in base, but seemed to be appropriate 27 | -- here. 28 | 29 | -- | Type-level "If". @If True a b@ ==> @a@; @If False a b@ ==> @b@ 30 | type family If cond tru fls where 31 | If 'True tru fls = tru 32 | If 'False tru fls = fls 33 | 34 | -- | Type-level "and" 35 | type family a && b where 36 | 'False && a = 'False 37 | 'True && a = a 38 | a && 'False = 'False 39 | a && 'True = a 40 | a && a = a 41 | infixr 3 && 42 | 43 | -- | Type-level "or" 44 | type family a || b where 45 | 'False || a = a 46 | 'True || a = 'True 47 | a || 'False = a 48 | a || 'True = 'True 49 | a || a = a 50 | infixr 2 || 51 | 52 | -- | Type-level "not" 53 | type family Not a where 54 | Not 'False = 'True 55 | Not 'True = 'False 56 | -------------------------------------------------------------------------------- /base/Data/Unique.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE MagicHash #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Unique 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : non-portable 13 | -- 14 | -- An abstract interface to a unique symbol generator. 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Unique ( 19 | -- * Unique objects 20 | Unique, 21 | newUnique, 22 | hashUnique 23 | ) where 24 | 25 | import System.IO.Unsafe (unsafePerformIO) 26 | 27 | import GHC.Base 28 | import GHC.Num 29 | import Data.IORef 30 | 31 | -- | An abstract unique object. Objects of type 'Unique' may be 32 | -- compared for equality and ordering and hashed into 'Int'. 33 | newtype Unique = Unique Integer deriving (Eq,Ord) 34 | 35 | uniqSource :: IORef Integer 36 | uniqSource = unsafePerformIO (newIORef 0) 37 | {-# NOINLINE uniqSource #-} 38 | 39 | -- | Creates a new object of type 'Unique'. The value returned will 40 | -- not compare equal to any other value of type 'Unique' returned by 41 | -- previous calls to 'newUnique'. There is no limit on the number of 42 | -- times 'newUnique' may be called. 43 | newUnique :: IO Unique 44 | newUnique = do 45 | r <- atomicModifyIORef' uniqSource $ \x -> let z = x+1 in (z,z) 46 | return (Unique r) 47 | 48 | -- SDM (18/3/2010): changed from MVar to STM. This fixes 49 | -- 1. there was no async exception protection 50 | -- 2. there was a space leak (now new value is strict) 51 | -- 3. using atomicModifyIORef would be slightly quicker, but can 52 | -- suffer from adverse scheduling issues (see #3838) 53 | -- 4. also, the STM version is faster. 54 | 55 | -- SDM (30/4/2012): changed to IORef using atomicModifyIORef. Reasons: 56 | -- 1. STM version could not be used inside unsafePerformIO, if it 57 | -- happened to be poked inside an STM transaction. 58 | -- 2. IORef version can be used with unsafeIOToSTM inside STM, 59 | -- because if the transaction retries then we just get a new 60 | -- Unique. 61 | -- 3. IORef version is very slightly faster. 62 | 63 | -- IGL (08/06/2013): changed to using atomicModifyIORef' instead. 64 | -- This feels a little safer, from the point of view of not leaking 65 | -- memory, but the resulting core is identical. 66 | 67 | -- | Hashes a 'Unique' into an 'Int'. Two 'Unique's may hash to the 68 | -- same value, although in practice this is unlikely. The 'Int' 69 | -- returned makes a good hash key. 70 | hashUnique :: Unique -> Int 71 | hashUnique (Unique i) = I# (hashInteger i) 72 | -------------------------------------------------------------------------------- /base/Data/Void.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveDataTypeable #-} 2 | {-# LANGUAGE DeriveGeneric #-} 3 | {-# LANGUAGE EmptyCase #-} 4 | {-# LANGUAGE Safe #-} 5 | {-# LANGUAGE StandaloneDeriving #-} 6 | 7 | ----------------------------------------------------------------------------- 8 | -- | 9 | -- Copyright : (C) 2008-2014 Edward Kmett 10 | -- License : BSD-style (see the file libraries/base/LICENSE) 11 | -- 12 | -- Maintainer : Edward Kmett 13 | -- Stability : provisional 14 | -- Portability : portable 15 | -- 16 | -- A logically uninhabited data type, used to indicate that a given 17 | -- term should not exist. 18 | -- 19 | -- @since 4.8.0.0 20 | ---------------------------------------------------------------------------- 21 | module Data.Void 22 | ( Void 23 | , absurd 24 | , vacuous 25 | ) where 26 | 27 | import Control.Exception 28 | import Data.Data 29 | import Data.Ix 30 | import GHC.Generics 31 | 32 | -- | Uninhabited data type 33 | -- 34 | -- @since 4.8.0.0 35 | data Void deriving (Generic) 36 | 37 | deriving instance Data Void 38 | 39 | instance Eq Void where 40 | _ == _ = True 41 | 42 | instance Ord Void where 43 | compare _ _ = EQ 44 | 45 | -- | Reading a 'Void' value is always a parse error, considering 46 | -- 'Void' as a data type with no constructors. 47 | instance Read Void where 48 | readsPrec _ _ = [] 49 | 50 | instance Show Void where 51 | showsPrec _ = absurd 52 | 53 | instance Ix Void where 54 | range _ = [] 55 | index _ = absurd 56 | inRange _ = absurd 57 | rangeSize _ = 0 58 | 59 | instance Exception Void 60 | 61 | -- | Since 'Void' values logically don't exist, this witnesses the 62 | -- logical reasoning tool of \"ex falso quodlibet\". 63 | -- 64 | -- @since 4.8.0.0 65 | absurd :: Void -> a 66 | absurd a = case a of {} 67 | 68 | -- | If 'Void' is uninhabited then any 'Functor' that holds only 69 | -- values of type 'Void' is holding no values. 70 | -- 71 | -- @since 4.8.0.0 72 | vacuous :: Functor f => f Void -> f a 73 | vacuous = fmap absurd 74 | -------------------------------------------------------------------------------- /base/Data/Word.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Data.Word 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- Unsigned integer types. 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Data.Word 19 | ( 20 | -- * Unsigned integral types 21 | 22 | Word, 23 | Word8, Word16, Word32, Word64, 24 | 25 | -- * byte swapping 26 | byteSwap16, byteSwap32, byteSwap64, 27 | 28 | -- * Notes 29 | 30 | -- $notes 31 | ) where 32 | 33 | import GHC.Word 34 | 35 | {- $notes 36 | 37 | * All arithmetic is performed modulo 2^n, where n is the number of 38 | bits in the type. One non-obvious consequence of this is that 'Prelude.negate' 39 | should /not/ raise an error on negative arguments. 40 | 41 | * For coercing between any two integer types, use 42 | 'Prelude.fromIntegral', which is specialized for all the 43 | common cases so should be fast enough. Coercing word types to and 44 | from integer types preserves representation, not sign. 45 | 46 | * An unbounded size unsigned integer type is available with 47 | 'Numeric.Natural.Natural'. 48 | 49 | * The rules that hold for 'Prelude.Enum' instances over a bounded type 50 | such as 'Prelude.Int' (see the section of the Haskell report dealing 51 | with arithmetic sequences) also hold for the 'Prelude.Enum' instances 52 | over the various 'Word' types defined here. 53 | 54 | * Right and left shifts by amounts greater than or equal to the width 55 | of the type result in a zero result. This is contrary to the 56 | behaviour in C, which is undefined; a common interpretation is to 57 | truncate the shift count to the width of the type, for example @1 \<\< 58 | 32 == 1@ in some C implementations. 59 | -} 60 | 61 | -------------------------------------------------------------------------------- /base/Foreign.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign 7 | -- Copyright : (c) The FFI task force 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- A collection of data types, classes, and functions for interfacing 15 | -- with another programming language. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Foreign 20 | ( module Data.Bits 21 | , module Data.Int 22 | , module Data.Word 23 | , module Foreign.Ptr 24 | , module Foreign.ForeignPtr 25 | , module Foreign.StablePtr 26 | , module Foreign.Storable 27 | , module Foreign.Marshal 28 | ) where 29 | 30 | import Data.Bits 31 | import Data.Int 32 | import Data.Word 33 | import Foreign.Ptr 34 | import Foreign.ForeignPtr 35 | import Foreign.StablePtr 36 | import Foreign.Storable 37 | import Foreign.Marshal 38 | 39 | -------------------------------------------------------------------------------- /base/Foreign/C.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.C 7 | -- Copyright : (c) The FFI task force 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Bundles the C specific FFI library functionality 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Foreign.C 19 | ( module Foreign.C.Types 20 | , module Foreign.C.String 21 | , module Foreign.C.Error 22 | ) where 23 | 24 | import Foreign.C.Types 25 | import Foreign.C.String 26 | import Foreign.C.Error 27 | 28 | -------------------------------------------------------------------------------- /base/Foreign/Concurrent.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.Concurrent 7 | -- Copyright : (c) The University of Glasgow 2003 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : non-portable (requires concurrency) 13 | -- 14 | -- FFI datatypes and operations that use or require concurrency (GHC only). 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Foreign.Concurrent 19 | ( 20 | -- * Concurrency-based 'ForeignPtr' operations 21 | 22 | -- | These functions generalize their namesakes in the portable 23 | -- "Foreign.ForeignPtr" module by allowing arbitrary 'IO' actions 24 | -- as finalizers. These finalizers necessarily run in a separate 25 | -- thread, cf. /Destructors, Finalizers and Synchronization/, 26 | -- by Hans Boehm, /POPL/, 2003. 27 | 28 | newForeignPtr, 29 | addForeignPtrFinalizer, 30 | ) where 31 | 32 | import GHC.IO ( IO ) 33 | import GHC.Ptr ( Ptr ) 34 | import GHC.ForeignPtr ( ForeignPtr ) 35 | import qualified GHC.ForeignPtr 36 | 37 | newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a) 38 | -- ^Turns a plain memory reference into a foreign object by associating 39 | -- a finalizer - given by the monadic operation - with the reference. 40 | -- The finalizer will be executed after the last reference to the 41 | -- foreign object is dropped. There is no guarantee of promptness, and 42 | -- in fact there is no guarantee that the finalizer will eventually 43 | -- run at all. 44 | newForeignPtr = GHC.ForeignPtr.newConcForeignPtr 45 | 46 | addForeignPtrFinalizer :: ForeignPtr a -> IO () -> IO () 47 | -- ^This function adds a finalizer to the given 'ForeignPtr'. 48 | -- The finalizer will run after the last reference to the foreign object 49 | -- is dropped, but /before/ all previously registered finalizers for the 50 | -- same object. 51 | addForeignPtrFinalizer = GHC.ForeignPtr.addForeignPtrConcFinalizer 52 | -------------------------------------------------------------------------------- /base/Foreign/ForeignPtr.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.ForeignPtr 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- The 'ForeignPtr' type and operations. This module is part of the 15 | -- Foreign Function Interface (FFI) and will usually be imported via 16 | -- the "Foreign" module. 17 | -- 18 | ----------------------------------------------------------------------------- 19 | 20 | module Foreign.ForeignPtr ( 21 | -- * Finalised data pointers 22 | ForeignPtr 23 | , FinalizerPtr 24 | , FinalizerEnvPtr 25 | 26 | -- ** Basic operations 27 | , newForeignPtr 28 | , newForeignPtr_ 29 | , addForeignPtrFinalizer 30 | , newForeignPtrEnv 31 | , addForeignPtrFinalizerEnv 32 | , withForeignPtr 33 | , finalizeForeignPtr 34 | 35 | -- ** Low-level operations 36 | , touchForeignPtr 37 | , castForeignPtr 38 | 39 | -- ** Allocating managed memory 40 | , mallocForeignPtr 41 | , mallocForeignPtrBytes 42 | , mallocForeignPtrArray 43 | , mallocForeignPtrArray0 44 | ) where 45 | 46 | import Foreign.ForeignPtr.Imp 47 | 48 | -------------------------------------------------------------------------------- /base/Foreign/ForeignPtr/Safe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.ForeignPtr.Safe 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- The 'ForeignPtr' type and operations. This module is part of the 15 | -- Foreign Function Interface (FFI) and will usually be imported via 16 | -- the "Foreign" module. 17 | -- 18 | -- Safe API Only. 19 | -- 20 | ----------------------------------------------------------------------------- 21 | 22 | module Foreign.ForeignPtr.Safe {-# DEPRECATED "Safe is now the default, please use Foreign.ForeignPtr instead" #-} ( 23 | -- * Finalised data pointers 24 | ForeignPtr 25 | , FinalizerPtr 26 | , FinalizerEnvPtr 27 | 28 | -- ** Basic operations 29 | , newForeignPtr 30 | , newForeignPtr_ 31 | , addForeignPtrFinalizer 32 | , newForeignPtrEnv 33 | , addForeignPtrFinalizerEnv 34 | , withForeignPtr 35 | , finalizeForeignPtr 36 | 37 | -- ** Low-level operations 38 | , touchForeignPtr 39 | , castForeignPtr 40 | 41 | -- ** Allocating managed memory 42 | , mallocForeignPtr 43 | , mallocForeignPtrBytes 44 | , mallocForeignPtrArray 45 | , mallocForeignPtrArray0 46 | ) where 47 | 48 | import Foreign.ForeignPtr.Imp 49 | 50 | -------------------------------------------------------------------------------- /base/Foreign/ForeignPtr/Unsafe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.ForeignPtr.Unsafe 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- The 'ForeignPtr' type and operations. This module is part of the 15 | -- Foreign Function Interface (FFI) and will usually be imported via 16 | -- the "Foreign" module. 17 | -- 18 | -- Unsafe API Only. 19 | -- 20 | ----------------------------------------------------------------------------- 21 | 22 | module Foreign.ForeignPtr.Unsafe ( 23 | -- ** Unsafe low-level operations 24 | unsafeForeignPtrToPtr, 25 | ) where 26 | 27 | import Foreign.ForeignPtr.Imp 28 | 29 | -------------------------------------------------------------------------------- /base/Foreign/Marshal.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.Marshal 7 | -- Copyright : (c) The FFI task force 2003 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Marshalling support 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Foreign.Marshal 19 | ( 20 | -- | The module "Foreign.Marshal.Safe" re-exports the other modules in the 21 | -- @Foreign.Marshal@ hierarchy (except for @Foreign.Marshal.Unsafe@): 22 | module Foreign.Marshal.Alloc 23 | , module Foreign.Marshal.Array 24 | , module Foreign.Marshal.Error 25 | , module Foreign.Marshal.Pool 26 | , module Foreign.Marshal.Utils 27 | ) where 28 | 29 | import Foreign.Marshal.Alloc 30 | import Foreign.Marshal.Array 31 | import Foreign.Marshal.Error 32 | import Foreign.Marshal.Pool 33 | import Foreign.Marshal.Utils 34 | 35 | -------------------------------------------------------------------------------- /base/Foreign/Marshal/Error.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE CPP, NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.Marshal.Error 7 | -- Copyright : (c) The FFI task force 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Routines for testing return values and raising a 'userError' exception 15 | -- in case of values indicating an error state. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Foreign.Marshal.Error ( 20 | throwIf, 21 | throwIf_, 22 | throwIfNeg, 23 | throwIfNeg_, 24 | throwIfNull, 25 | 26 | -- Discard return value 27 | -- 28 | void 29 | ) where 30 | 31 | import Foreign.Ptr 32 | 33 | import GHC.Base 34 | import GHC.Num 35 | import GHC.IO.Exception 36 | 37 | -- exported functions 38 | -- ------------------ 39 | 40 | -- |Execute an 'IO' action, throwing a 'userError' if the predicate yields 41 | -- 'True' when applied to the result returned by the 'IO' action. 42 | -- If no exception is raised, return the result of the computation. 43 | -- 44 | throwIf :: (a -> Bool) -- ^ error condition on the result of the 'IO' action 45 | -> (a -> String) -- ^ computes an error message from erroneous results 46 | -- of the 'IO' action 47 | -> IO a -- ^ the 'IO' action to be executed 48 | -> IO a 49 | throwIf pred msgfct act = 50 | do 51 | res <- act 52 | (if pred res then ioError . userError . msgfct else return) res 53 | 54 | -- |Like 'throwIf', but discarding the result 55 | -- 56 | throwIf_ :: (a -> Bool) -> (a -> String) -> IO a -> IO () 57 | throwIf_ pred msgfct act = void $ throwIf pred msgfct act 58 | 59 | -- |Guards against negative result values 60 | -- 61 | throwIfNeg :: (Ord a, Num a) => (a -> String) -> IO a -> IO a 62 | throwIfNeg = throwIf (< 0) 63 | 64 | -- |Like 'throwIfNeg', but discarding the result 65 | -- 66 | throwIfNeg_ :: (Ord a, Num a) => (a -> String) -> IO a -> IO () 67 | throwIfNeg_ = throwIf_ (< 0) 68 | 69 | -- |Guards against null pointers 70 | -- 71 | throwIfNull :: String -> IO (Ptr a) -> IO (Ptr a) 72 | throwIfNull = throwIf (== nullPtr) . const 73 | 74 | -- |Discard the return value of an 'IO' action 75 | -- 76 | void :: IO a -> IO () 77 | void act = act >> return () 78 | {-# DEPRECATED void "use 'Control.Monad.void' instead" #-} -- deprecated in 7.6 79 | -------------------------------------------------------------------------------- /base/Foreign/Marshal/Safe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.Marshal.Safe 7 | -- Copyright : (c) The FFI task force 2003 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Marshalling support 15 | -- 16 | -- Safe API Only. 17 | -- 18 | ----------------------------------------------------------------------------- 19 | 20 | module Foreign.Marshal.Safe {-# DEPRECATED "Safe is now the default, please use Foreign.Marshal instead" #-} 21 | ( 22 | -- | The module "Foreign.Marshal.Safe" re-exports the other modules in the 23 | -- @Foreign.Marshal@ hierarchy: 24 | module Foreign.Marshal.Alloc 25 | , module Foreign.Marshal.Array 26 | , module Foreign.Marshal.Error 27 | , module Foreign.Marshal.Pool 28 | , module Foreign.Marshal.Utils 29 | ) where 30 | 31 | import Foreign.Marshal.Alloc 32 | import Foreign.Marshal.Array 33 | import Foreign.Marshal.Error 34 | import Foreign.Marshal.Pool 35 | import Foreign.Marshal.Utils 36 | 37 | -------------------------------------------------------------------------------- /base/Foreign/Marshal/Unsafe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.Marshal.Unsafe 7 | -- Copyright : (c) The FFI task force 2003 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Marshalling support. Unsafe API. 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module Foreign.Marshal.Unsafe ( 19 | -- * Unsafe functions 20 | unsafeLocalState 21 | ) where 22 | 23 | import GHC.IO 24 | 25 | {- | 26 | Sometimes an external entity is a pure function, except that it passes 27 | arguments and/or results via pointers. The function 28 | @unsafeLocalState@ permits the packaging of such entities as pure 29 | functions. 30 | 31 | The only IO operations allowed in the IO action passed to 32 | @unsafeLocalState@ are (a) local allocation (@alloca@, @allocaBytes@ 33 | and derived operations such as @withArray@ and @withCString@), and (b) 34 | pointer operations (@Foreign.Storable@ and @Foreign.Ptr@) on the 35 | pointers to local storage, and (c) foreign functions whose only 36 | observable effect is to read and/or write the locally allocated 37 | memory. Passing an IO operation that does not obey these rules 38 | results in undefined behaviour. 39 | 40 | It is expected that this operation will be 41 | replaced in a future revision of Haskell. 42 | -} 43 | unsafeLocalState :: IO a -> a 44 | unsafeLocalState = unsafeDupablePerformIO 45 | 46 | -------------------------------------------------------------------------------- /base/Foreign/Safe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.Safe 7 | -- Copyright : (c) The FFI task force 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- A collection of data types, classes, and functions for interfacing 15 | -- with another programming language. 16 | -- 17 | -- Safe API Only. 18 | -- 19 | ----------------------------------------------------------------------------- 20 | 21 | module Foreign.Safe {-# DEPRECATED "Safe is now the default, please use Foreign instead" #-} 22 | ( module Data.Bits 23 | , module Data.Int 24 | , module Data.Word 25 | , module Foreign.Ptr 26 | , module Foreign.ForeignPtr 27 | , module Foreign.StablePtr 28 | , module Foreign.Storable 29 | , module Foreign.Marshal 30 | ) where 31 | 32 | import Data.Bits 33 | import Data.Int 34 | import Data.Word 35 | import Foreign.Ptr 36 | import Foreign.ForeignPtr 37 | import Foreign.StablePtr 38 | import Foreign.Storable 39 | import Foreign.Marshal 40 | 41 | -------------------------------------------------------------------------------- /base/Foreign/StablePtr.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Foreign.StablePtr 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : ffi@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- This module is part of the Foreign Function Interface (FFI) and will usually 15 | -- be imported via the module "Foreign". 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | 20 | module Foreign.StablePtr 21 | ( -- * Stable references to Haskell values 22 | StablePtr -- abstract 23 | , newStablePtr 24 | , deRefStablePtr 25 | , freeStablePtr 26 | , castStablePtrToPtr 27 | , castPtrToStablePtr 28 | , -- ** The C-side interface 29 | 30 | -- $cinterface 31 | ) where 32 | 33 | import GHC.Stable 34 | 35 | -- $cinterface 36 | -- 37 | -- The following definition is available to C programs inter-operating with 38 | -- Haskell code when including the header @HsFFI.h@. 39 | -- 40 | -- > typedef void *HsStablePtr; /* C representation of a StablePtr */ 41 | -- 42 | -- Note that no assumptions may be made about the values representing stable 43 | -- pointers. In fact, they need not even be valid memory addresses. The only 44 | -- guarantee provided is that if they are passed back to Haskell land, the 45 | -- function 'deRefStablePtr' will be able to reconstruct the 46 | -- Haskell value referred to by the stable pointer. 47 | 48 | -------------------------------------------------------------------------------- /base/GHC/Char.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude, MagicHash #-} 3 | 4 | module GHC.Char 5 | ( -- * Utilities 6 | chr 7 | 8 | -- * Monomorphic equality operators 9 | -- | See GHC.Classes#matching_overloaded_methods_in_rules 10 | , eqChar, neChar 11 | ) where 12 | 13 | import GHC.Base 14 | import GHC.Show 15 | 16 | -- | The 'Prelude.toEnum' method restricted to the type 'Data.Char.Char'. 17 | chr :: Int -> Char 18 | chr i@(I# i#) 19 | | isTrue# (int2Word# i# `leWord#` 0x10FFFF##) = C# (chr# i#) 20 | | otherwise 21 | = errorWithoutStackTrace ("Prelude.chr: bad argument: " ++ showSignedInt (I# 9#) i "") 22 | 23 | -------------------------------------------------------------------------------- /base/GHC/Constants.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.Constants where 5 | 6 | -- TODO: This used to include HaskellConstants.hs, but that has now gone. 7 | -- We probably want to include the constants in platformConstants somehow 8 | -- instead. 9 | 10 | import GHC.Base () -- dummy dependency 11 | -------------------------------------------------------------------------------- /base/GHC/Desugar.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude 3 | , RankNTypes 4 | , ExistentialQuantification 5 | #-} 6 | {-# OPTIONS_HADDOCK hide #-} 7 | 8 | ----------------------------------------------------------------------------- 9 | -- | 10 | -- Module : GHC.Desugar 11 | -- Copyright : (c) The University of Glasgow, 2007 12 | -- License : see libraries/base/LICENSE 13 | -- 14 | -- Maintainer : cvs-ghc@haskell.org 15 | -- Stability : internal 16 | -- Portability : non-portable (GHC extensions) 17 | -- 18 | -- Support code for desugaring in GHC 19 | -- 20 | ----------------------------------------------------------------------------- 21 | 22 | module GHC.Desugar ((>>>), AnnotationWrapper(..), toAnnotationWrapper) where 23 | 24 | import Control.Arrow (Arrow(..)) 25 | import Control.Category ((.)) 26 | import Data.Data (Data) 27 | 28 | -- A version of Control.Category.>>> overloaded on Arrow 29 | (>>>) :: forall arr. Arrow arr => forall a b c. arr a b -> arr b c -> arr a c 30 | -- NB: the type of this function is the "shape" that GHC expects 31 | -- in tcInstClassOp. So don't put all the foralls at the front! 32 | -- Yes, this is a bit grotesque, but heck it works and the whole 33 | -- arrows stuff needs reworking anyway! 34 | f >>> g = g . f 35 | 36 | -- A wrapper data type that lets the typechecker get at the appropriate dictionaries for an annotation 37 | data AnnotationWrapper = forall a. (Data a) => AnnotationWrapper a 38 | 39 | toAnnotationWrapper :: (Data a) => a -> AnnotationWrapper 40 | toAnnotationWrapper what = AnnotationWrapper what 41 | 42 | -------------------------------------------------------------------------------- /base/GHC/Environment.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | {-# LANGUAGE CPP #-} 4 | 5 | module GHC.Environment (getFullArgs) where 6 | 7 | import Foreign 8 | import Foreign.C 9 | import GHC.Base 10 | import GHC.Real ( fromIntegral ) 11 | 12 | #ifdef mingw32_HOST_OS 13 | import GHC.IO (finally) 14 | import GHC.Windows 15 | 16 | # if defined(i386_HOST_ARCH) 17 | # define WINDOWS_CCONV stdcall 18 | # elif defined(x86_64_HOST_ARCH) 19 | # define WINDOWS_CCONV ccall 20 | # else 21 | # error Unknown mingw32 arch 22 | # endif 23 | #else 24 | import GHC.IO.Encoding 25 | import qualified GHC.Foreign as GHC 26 | #endif 27 | 28 | -- | Computation 'getFullArgs' is the "raw" version of 'getArgs', similar 29 | -- to @argv@ in other languages. It returns a list of the program's 30 | -- command line arguments, starting with the program name, and 31 | -- including those normally eaten by the RTS (+RTS ... -RTS). 32 | getFullArgs :: IO [String] 33 | #ifdef mingw32_HOST_OS 34 | -- Ignore the arguments to hs_init on Windows for the sake of Unicode compat 35 | getFullArgs = do 36 | p_arg_string <- c_GetCommandLine 37 | alloca $ \p_argc -> do 38 | p_argv <- c_CommandLineToArgv p_arg_string p_argc 39 | if p_argv == nullPtr 40 | then throwGetLastError "getFullArgs" 41 | else flip finally (c_LocalFree p_argv) $ do 42 | argc <- peek p_argc 43 | p_argvs <- peekArray (fromIntegral argc) p_argv 44 | mapM peekCWString p_argvs 45 | 46 | foreign import WINDOWS_CCONV unsafe "windows.h GetCommandLineW" 47 | c_GetCommandLine :: IO (Ptr CWString) 48 | 49 | foreign import WINDOWS_CCONV unsafe "windows.h CommandLineToArgvW" 50 | c_CommandLineToArgv :: Ptr CWString -> Ptr CInt -> IO (Ptr CWString) 51 | 52 | foreign import WINDOWS_CCONV unsafe "Windows.h LocalFree" 53 | c_LocalFree :: Ptr a -> IO (Ptr a) 54 | #else 55 | getFullArgs = 56 | alloca $ \ p_argc -> 57 | alloca $ \ p_argv -> do 58 | getFullProgArgv p_argc p_argv 59 | p <- fromIntegral `liftM` peek p_argc 60 | argv <- peek p_argv 61 | enc <- getFileSystemEncoding 62 | peekArray p argv >>= mapM (GHC.peekCString enc) 63 | 64 | foreign import ccall unsafe "getFullProgArgv" 65 | getFullProgArgv :: Ptr CInt -> Ptr (Ptr CString) -> IO () 66 | #endif 67 | -------------------------------------------------------------------------------- /base/GHC/Event.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | -- ---------------------------------------------------------------------------- 5 | -- | This module provides scalable event notification for file 6 | -- descriptors and timeouts. 7 | -- 8 | -- This module should be considered GHC internal. 9 | -- 10 | -- ---------------------------------------------------------------------------- 11 | 12 | module GHC.Event 13 | ( -- * Types 14 | EventManager 15 | , TimerManager 16 | 17 | -- * Creation 18 | , getSystemEventManager 19 | , new 20 | , getSystemTimerManager 21 | 22 | -- * Registering interest in I/O events 23 | , Event 24 | , evtRead 25 | , evtWrite 26 | , IOCallback 27 | , FdKey(keyFd) 28 | , Lifetime(..) 29 | , registerFd 30 | , unregisterFd 31 | , unregisterFd_ 32 | , closeFd 33 | 34 | -- * Registering interest in timeout events 35 | , TimeoutCallback 36 | , TimeoutKey 37 | , registerTimeout 38 | , updateTimeout 39 | , unregisterTimeout 40 | ) where 41 | 42 | import GHC.Event.Manager 43 | import GHC.Event.TimerManager (TimeoutCallback, TimeoutKey, registerTimeout, 44 | updateTimeout, unregisterTimeout, TimerManager) 45 | import GHC.Event.Thread (getSystemEventManager, getSystemTimerManager) 46 | 47 | -------------------------------------------------------------------------------- /base/GHC/Event/Arr.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash, NoImplicitPrelude, UnboxedTuples #-} 2 | 3 | module GHC.Event.Arr 4 | ( 5 | Arr(..) 6 | , new 7 | , size 8 | , read 9 | , write 10 | ) where 11 | 12 | import GHC.Base (($)) 13 | import GHC.Prim (MutableArray#, RealWorld, newArray#, readArray#, 14 | sizeofMutableArray#, writeArray#) 15 | import GHC.Types (IO(..), Int(..)) 16 | 17 | data Arr a = Arr (MutableArray# RealWorld a) 18 | 19 | new :: a -> Int -> IO (Arr a) 20 | new defval (I# n#) = IO $ \s0# -> 21 | case newArray# n# defval s0# of (# s1#, marr# #) -> (# s1#, Arr marr# #) 22 | 23 | size :: Arr a -> Int 24 | size (Arr a) = I# (sizeofMutableArray# a) 25 | 26 | read :: Arr a -> Int -> IO a 27 | read (Arr a) (I# n#) = IO $ \s0# -> 28 | case readArray# a n# s0# of (# s1#, val #) -> (# s1#, val #) 29 | 30 | write :: Arr a -> Int -> a -> IO () 31 | write (Arr a) (I# n#) val = IO $ \s0# -> 32 | case writeArray# a n# val s0# of s1# -> (# s1#, () #) 33 | -------------------------------------------------------------------------------- /base/GHC/Event/Clock.hsc: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.Event.Clock (getMonotonicTime) where 5 | 6 | import GHC.Base 7 | import GHC.Real 8 | import Data.Word 9 | 10 | -- | Return monotonic time in seconds, since some unspecified starting point 11 | getMonotonicTime :: IO Double 12 | getMonotonicTime = do w <- getMonotonicNSec 13 | return (fromIntegral w / 1000000000) 14 | 15 | foreign import ccall unsafe "getMonotonicNSec" 16 | getMonotonicNSec :: IO Word64 17 | 18 | -------------------------------------------------------------------------------- /base/GHC/Event/Unique.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving, NoImplicitPrelude #-} 3 | 4 | module GHC.Event.Unique 5 | ( 6 | UniqueSource 7 | , Unique(..) 8 | , newSource 9 | , newUnique 10 | ) where 11 | 12 | import Data.Int (Int64) 13 | import GHC.Base 14 | import GHC.Conc.Sync (TVar, atomically, newTVarIO, readTVar, writeTVar) 15 | import GHC.Num (Num(..)) 16 | import GHC.Show (Show(..)) 17 | 18 | -- We used to use IORefs here, but Simon switched us to STM when we 19 | -- found that our use of atomicModifyIORef was subject to a severe RTS 20 | -- performance problem when used in a tight loop from multiple 21 | -- threads: http://ghc.haskell.org/trac/ghc/ticket/3838 22 | -- 23 | -- There seems to be no performance cost to using a TVar instead. 24 | 25 | newtype UniqueSource = US (TVar Int64) 26 | 27 | newtype Unique = Unique { asInt64 :: Int64 } 28 | deriving (Eq, Ord, Num) 29 | 30 | instance Show Unique where 31 | show = show . asInt64 32 | 33 | newSource :: IO UniqueSource 34 | newSource = US `fmap` newTVarIO 0 35 | 36 | newUnique :: UniqueSource -> IO Unique 37 | newUnique (US ref) = atomically $ do 38 | u <- readTVar ref 39 | let !u' = u+1 40 | writeTVar ref u' 41 | return $ Unique u' 42 | {-# INLINE newUnique #-} 43 | 44 | -------------------------------------------------------------------------------- /base/GHC/Exception.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | {- 5 | This SOURCE-imported hs-boot module cuts a big dependency loop: 6 | 7 | GHC.Exception 8 | imports Data.Maybe 9 | imports GHC.Base 10 | imports GHC.Err 11 | imports {-# SOURCE #-} GHC.Exception 12 | 13 | More dramatically 14 | 15 | GHC.Exception 16 | imports Data.Typeable 17 | imports Data.Typeable.Internals 18 | imports GHC.Arr (fingerprint representation etc) 19 | imports GHC.Real 20 | imports {-# SOURCE #-} GHC.Exception 21 | 22 | However, GHC.Exceptions loop-breaking exports are all nice, 23 | well-behaved, non-bottom values. The clients use 'raise#' 24 | to get a visibly-bottom value. 25 | -} 26 | 27 | module GHC.Exception ( SomeException, errorCallException, 28 | errorCallWithCallStackException, 29 | divZeroException, overflowException, ratioZeroDenomException 30 | ) where 31 | import GHC.Types ( Char ) 32 | import GHC.Stack.Types ( CallStack ) 33 | 34 | data SomeException 35 | divZeroException, overflowException, ratioZeroDenomException :: SomeException 36 | 37 | errorCallException :: [Char] -> SomeException 38 | errorCallWithCallStackException :: [Char] -> CallStack -> SomeException 39 | -------------------------------------------------------------------------------- /base/GHC/ExecutionStack.hs: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- | 3 | -- Module : GHC.ExecutionStack 4 | -- Copyright : (c) The University of Glasgow 2013-2015 5 | -- License : see libraries/base/LICENSE 6 | -- 7 | -- Maintainer : cvs-ghc@haskell.org 8 | -- Stability : internal 9 | -- Portability : non-portable (GHC Extensions) 10 | -- 11 | -- This is a module for efficient stack traces. This stack trace implementation 12 | -- is considered low overhead. Basic usage looks like this: 13 | -- 14 | -- @ 15 | -- import GHC.ExecutionStack 16 | -- 17 | -- myFunction :: IO () 18 | -- myFunction = do 19 | -- putStrLn =<< showStackTrace 20 | -- @ 21 | -- 22 | -- Your GHC must have been built with @libdw@ support for this to work. 23 | -- 24 | -- @ 25 | -- user@host:~$ ghc --info | grep libdw 26 | -- ,("RTS expects libdw","YES") 27 | -- @ 28 | -- 29 | -- @since 4.9.0.0 30 | ----------------------------------------------------------------------------- 31 | 32 | module GHC.ExecutionStack ( 33 | Location (..) 34 | , SrcLoc (..) 35 | , getStackTrace 36 | , showStackTrace 37 | ) where 38 | 39 | import Control.Monad (join) 40 | import GHC.ExecutionStack.Internal 41 | 42 | -- | Get a trace of the current execution stack state. 43 | -- 44 | -- Returns @Nothing@ if stack trace support isn't available on host machine. 45 | getStackTrace :: IO (Maybe [Location]) 46 | getStackTrace = (join . fmap stackFrames) `fmap` collectStackTrace 47 | 48 | -- | Get a string representation of the current execution stack state. 49 | showStackTrace :: IO (Maybe String) 50 | showStackTrace = fmap (\st -> showStackFrames st "") `fmap` getStackTrace 51 | -------------------------------------------------------------------------------- /base/GHC/Fingerprint.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.Fingerprint ( 5 | fingerprintString, 6 | fingerprintFingerprints 7 | ) where 8 | 9 | import GHC.Base 10 | import GHC.Fingerprint.Type 11 | 12 | fingerprintFingerprints :: [Fingerprint] -> Fingerprint 13 | fingerprintString :: String -> Fingerprint 14 | 15 | -------------------------------------------------------------------------------- /base/GHC/Fingerprint/Type.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | -- ---------------------------------------------------------------------------- 5 | -- 6 | -- (c) The University of Glasgow 2006 7 | -- 8 | -- Fingerprints for recompilation checking and ABI versioning, and 9 | -- implementing fast comparison of Typeable. 10 | -- 11 | -- ---------------------------------------------------------------------------- 12 | 13 | module GHC.Fingerprint.Type (Fingerprint(..)) where 14 | 15 | import GHC.Base 16 | import GHC.List (length, replicate) 17 | import GHC.Num 18 | import GHC.Show 19 | import GHC.Word 20 | import Numeric (showHex) 21 | 22 | -- Using 128-bit MD5 fingerprints for now. 23 | 24 | data Fingerprint = Fingerprint {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64 25 | deriving (Eq, Ord) 26 | 27 | instance Show Fingerprint where 28 | show (Fingerprint w1 w2) = hex16 w1 ++ hex16 w2 29 | where 30 | -- | Formats a 64 bit number as 16 digits hex. 31 | hex16 :: Word64 -> String 32 | hex16 i = let hex = showHex i "" 33 | in replicate (16 - length hex) '0' ++ hex 34 | -------------------------------------------------------------------------------- /base/GHC/GHCi.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | {-# OPTIONS_HADDOCK hide #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : GHC.GHCi 7 | -- Copyright : (c) The University of Glasgow 2012 8 | -- License : see libraries/base/LICENSE 9 | -- 10 | -- Maintainer : cvs-ghc@haskell.org 11 | -- Stability : internal 12 | -- Portability : non-portable (GHC Extensions) 13 | -- 14 | -- The GHCi Monad lifting interface. 15 | -- 16 | -- EXPERIMENTAL! DON'T USE. 17 | -- 18 | ----------------------------------------------------------------------------- 19 | 20 | module GHC.GHCi {-# WARNING "This is an unstable interface." #-} ( 21 | GHCiSandboxIO(..), NoIO() 22 | ) where 23 | 24 | import GHC.Base (IO(), Monad, Functor(fmap), Applicative(..), (>>=), id, (.), ap) 25 | 26 | -- | A monad that can execute GHCi statements by lifting them out of 27 | -- m into the IO monad. (e.g state monads) 28 | class (Monad m) => GHCiSandboxIO m where 29 | ghciStepIO :: m a -> IO a 30 | 31 | instance GHCiSandboxIO IO where 32 | ghciStepIO = id 33 | 34 | -- | A monad that doesn't allow any IO. 35 | newtype NoIO a = NoIO { noio :: IO a } 36 | 37 | instance Functor NoIO where 38 | fmap f (NoIO a) = NoIO (fmap f a) 39 | 40 | instance Applicative NoIO where 41 | pure a = NoIO (pure a) 42 | (<*>) = ap 43 | 44 | instance Monad NoIO where 45 | (>>=) k f = NoIO (noio k >>= noio . f) 46 | 47 | instance GHCiSandboxIO NoIO where 48 | ghciStepIO = noio 49 | 50 | -------------------------------------------------------------------------------- /base/GHC/IO.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.IO where 5 | 6 | import GHC.Types 7 | 8 | failIO :: [Char] -> IO a 9 | mplusIO :: IO a -> IO a -> IO a 10 | -------------------------------------------------------------------------------- /base/GHC/IO/Encoding.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.IO.Encoding where 5 | 6 | import GHC.IO (IO) 7 | import GHC.IO.Encoding.Types 8 | 9 | getLocaleEncoding, getFileSystemEncoding, getForeignEncoding :: IO TextEncoding 10 | 11 | -------------------------------------------------------------------------------- /base/GHC/IO/Exception.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.IO.Exception where 5 | 6 | import GHC.Base 7 | import GHC.Exception 8 | 9 | data IOException 10 | instance Exception IOException 11 | 12 | type IOError = IOException 13 | userError :: String -> IOError 14 | unsupportedOperation :: IOError 15 | 16 | -------------------------------------------------------------------------------- /base/GHC/IO/Handle.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.IO.Handle where 5 | 6 | import GHC.IO 7 | import GHC.IO.Handle.Types 8 | 9 | hFlush :: Handle -> IO () 10 | 11 | -------------------------------------------------------------------------------- /base/GHC/IO/Handle/FD.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | module GHC.IO.Handle.FD where 5 | 6 | import GHC.IO.Handle.Types 7 | 8 | -- used in GHC.Conc, which is below GHC.IO.Handle.FD 9 | stdout :: Handle 10 | 11 | -------------------------------------------------------------------------------- /base/GHC/IO/IOMode.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | {-# OPTIONS_HADDOCK hide #-} 4 | 5 | ----------------------------------------------------------------------------- 6 | -- | 7 | -- Module : GHC.IO.IOMode 8 | -- Copyright : (c) The University of Glasgow, 1994-2008 9 | -- License : see libraries/base/LICENSE 10 | -- 11 | -- Maintainer : libraries@haskell.org 12 | -- Stability : internal 13 | -- Portability : non-portable 14 | -- 15 | -- The IOMode type 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module GHC.IO.IOMode (IOMode(..)) where 20 | 21 | import GHC.Base 22 | import GHC.Show 23 | import GHC.Read 24 | import GHC.Arr 25 | import GHC.Enum 26 | 27 | -- | See 'System.IO.openFile' 28 | data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode 29 | deriving (Eq, Ord, Ix, Enum, Read, Show) 30 | 31 | -------------------------------------------------------------------------------- /base/GHC/IOArray.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude, RoleAnnotations #-} 3 | {-# OPTIONS_GHC -funbox-strict-fields #-} 4 | {-# OPTIONS_HADDOCK hide #-} 5 | 6 | ----------------------------------------------------------------------------- 7 | -- | 8 | -- Module : GHC.IOArray 9 | -- Copyright : (c) The University of Glasgow 2008 10 | -- License : see libraries/base/LICENSE 11 | -- 12 | -- Maintainer : cvs-ghc@haskell.org 13 | -- Stability : internal 14 | -- Portability : non-portable (GHC Extensions) 15 | -- 16 | -- The IOArray type 17 | -- 18 | ----------------------------------------------------------------------------- 19 | 20 | module GHC.IOArray ( 21 | IOArray(..), 22 | newIOArray, unsafeReadIOArray, unsafeWriteIOArray, 23 | readIOArray, writeIOArray, 24 | boundsIOArray 25 | ) where 26 | 27 | import GHC.Base 28 | import GHC.IO 29 | import GHC.Arr 30 | 31 | -- --------------------------------------------------------------------------- 32 | -- | An 'IOArray' is a mutable, boxed, non-strict array in the 'IO' monad. 33 | -- The type arguments are as follows: 34 | -- 35 | -- * @i@: the index type of the array (should be an instance of 'Ix') 36 | -- 37 | -- * @e@: the element type of the array. 38 | -- 39 | -- 40 | 41 | newtype IOArray i e = IOArray (STArray RealWorld i e) 42 | 43 | -- index type should have a nominal role due to Ix class. See also #9220. 44 | type role IOArray nominal representational 45 | 46 | -- explicit instance because Haddock can't figure out a derived one 47 | instance Eq (IOArray i e) where 48 | IOArray x == IOArray y = x == y 49 | 50 | -- |Build a new 'IOArray' 51 | newIOArray :: Ix i => (i,i) -> e -> IO (IOArray i e) 52 | {-# INLINE newIOArray #-} 53 | newIOArray lu initial = stToIO $ do {marr <- newSTArray lu initial; return (IOArray marr)} 54 | 55 | -- | Read a value from an 'IOArray' 56 | unsafeReadIOArray :: IOArray i e -> Int -> IO e 57 | {-# INLINE unsafeReadIOArray #-} 58 | unsafeReadIOArray (IOArray marr) i = stToIO (unsafeReadSTArray marr i) 59 | 60 | -- | Write a new value into an 'IOArray' 61 | unsafeWriteIOArray :: IOArray i e -> Int -> e -> IO () 62 | {-# INLINE unsafeWriteIOArray #-} 63 | unsafeWriteIOArray (IOArray marr) i e = stToIO (unsafeWriteSTArray marr i e) 64 | 65 | -- | Read a value from an 'IOArray' 66 | readIOArray :: Ix i => IOArray i e -> i -> IO e 67 | readIOArray (IOArray marr) i = stToIO (readSTArray marr i) 68 | 69 | -- | Write a new value into an 'IOArray' 70 | writeIOArray :: Ix i => IOArray i e -> i -> e -> IO () 71 | writeIOArray (IOArray marr) i e = stToIO (writeSTArray marr i e) 72 | 73 | {-# INLINE boundsIOArray #-} 74 | boundsIOArray :: IOArray i e -> (i,i) 75 | boundsIOArray (IOArray marr) = boundsSTArray marr 76 | 77 | -------------------------------------------------------------------------------- /base/GHC/IORef.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude, MagicHash #-} 3 | {-# OPTIONS_GHC -funbox-strict-fields #-} 4 | {-# OPTIONS_HADDOCK hide #-} 5 | 6 | ----------------------------------------------------------------------------- 7 | -- | 8 | -- Module : GHC.IORef 9 | -- Copyright : (c) The University of Glasgow 2008 10 | -- License : see libraries/base/LICENSE 11 | -- 12 | -- Maintainer : cvs-ghc@haskell.org 13 | -- Stability : internal 14 | -- Portability : non-portable (GHC Extensions) 15 | -- 16 | -- The IORef type 17 | -- 18 | ----------------------------------------------------------------------------- 19 | 20 | module GHC.IORef ( 21 | IORef(..), 22 | newIORef, readIORef, writeIORef, atomicModifyIORef 23 | ) where 24 | 25 | import GHC.Base 26 | import GHC.STRef 27 | import GHC.IO 28 | 29 | -- --------------------------------------------------------------------------- 30 | -- IORefs 31 | 32 | -- |A mutable variable in the 'IO' monad 33 | newtype IORef a = IORef (STRef RealWorld a) 34 | 35 | -- explicit instance because Haddock can't figure out a derived one 36 | instance Eq (IORef a) where 37 | IORef x == IORef y = x == y 38 | 39 | -- |Build a new 'IORef' 40 | newIORef :: a -> IO (IORef a) 41 | newIORef v = stToIO (newSTRef v) >>= \ var -> return (IORef var) 42 | 43 | -- |Read the value of an 'IORef' 44 | readIORef :: IORef a -> IO a 45 | readIORef (IORef var) = stToIO (readSTRef var) 46 | 47 | -- |Write a new value into an 'IORef' 48 | writeIORef :: IORef a -> a -> IO () 49 | writeIORef (IORef var) v = stToIO (writeSTRef var v) 50 | 51 | atomicModifyIORef :: IORef a -> (a -> (a,b)) -> IO b 52 | atomicModifyIORef (IORef (STRef r#)) f = IO $ \s -> atomicModifyMutVar# r# f s 53 | 54 | -------------------------------------------------------------------------------- /base/GHC/OldList.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | {-# LANGUAGE Safe #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : GHC.OldList 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- This legacy module provides access to the list-specialised operations 15 | -- of "Data.List". This module may go away again in future GHC versions and 16 | -- is provided as transitional tool to access some of the list-specialised 17 | -- operations that had to be generalised due to the implementation of the 18 | -- . 19 | -- 20 | -- If the operations needed are available in "GHC.List", it's 21 | -- recommended to avoid importing this module and use "GHC.List" 22 | -- instead for now. 23 | -- 24 | -- @since 4.8.0.0 25 | ----------------------------------------------------------------------------- 26 | 27 | module GHC.OldList (module Data.OldList) where 28 | 29 | import Data.OldList 30 | -------------------------------------------------------------------------------- /base/GHC/OverloadedLabels.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude 2 | , MultiParamTypeClasses 3 | , MagicHash 4 | , KindSignatures 5 | , DataKinds 6 | #-} 7 | 8 | ----------------------------------------------------------------------------- 9 | -- | 10 | -- Module : GHC.OverloadedLabels 11 | -- Copyright : (c) Adam Gundry 2015 12 | -- License : see libraries/base/LICENSE 13 | -- 14 | -- Maintainer : cvs-ghc@haskell.org 15 | -- Stability : internal 16 | -- Portability : non-portable (GHC extensions) 17 | -- 18 | -- This module defines the `IsLabel` class is used by the 19 | -- OverloadedLabels extension. See the 20 | -- 21 | -- for more details. 22 | -- 23 | -- The key idea is that when GHC sees an occurrence of the new 24 | -- overloaded label syntax @#foo@, it is replaced with 25 | -- 26 | -- > fromLabel (proxy# :: Proxy# "foo") :: alpha 27 | -- 28 | -- plus a wanted constraint @IsLabel "foo" alpha@. 29 | -- 30 | ----------------------------------------------------------------------------- 31 | 32 | -- Note [Overloaded labels] 33 | -- ~~~~~~~~~~~~~~~~~~~~~~~~ 34 | -- An overloaded label is represented by the 'HsOverLabel' constructor 35 | -- of 'HsExpr', which stores a 'FastString'. It is passed through 36 | -- unchanged by the renamer, and the type-checker transforms it into a 37 | -- call to 'fromLabel'. See Note [Type-checking overloaded labels] in 38 | -- TcExpr for more details in how type-checking works. 39 | 40 | module GHC.OverloadedLabels 41 | ( IsLabel(..) 42 | ) where 43 | 44 | import GHC.Base ( Symbol ) 45 | import GHC.Exts ( Proxy# ) 46 | 47 | class IsLabel (x :: Symbol) a where 48 | fromLabel :: Proxy# x -> a 49 | -------------------------------------------------------------------------------- /base/GHC/PArr.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | {-# LANGUAGE ParallelArrays, MagicHash #-} 4 | {-# OPTIONS_GHC -funbox-strict-fields #-} 5 | {-# OPTIONS_HADDOCK hide #-} 6 | 7 | ----------------------------------------------------------------------------- 8 | -- | 9 | -- Module : GHC.PArr 10 | -- Copyright : (c) 2001-2011 The Data Parallel Haskell team 11 | -- License : see libraries/base/LICENSE 12 | -- 13 | -- Maintainer : cvs-ghc@haskell.org 14 | -- Stability : internal 15 | -- Portability : non-portable (GHC Extensions) 16 | -- 17 | -- BIG UGLY HACK: The desugarer special cases this module. Despite the uses of '-XParallelArrays', 18 | -- the desugarer does not load 'Data.Array.Parallel' into its global state. (Hence, 19 | -- the present module may not use any other piece of '-XParallelArray' syntax.) 20 | -- 21 | -- This will be cleaned up when we change the internal represention of '[::]' to not 22 | -- rely on a wired-in type constructor. 23 | 24 | module GHC.PArr where 25 | 26 | import GHC.Base 27 | 28 | -- Representation of parallel arrays 29 | -- 30 | -- Vanilla representation of parallel Haskell based on standard GHC arrays that is used if the 31 | -- vectorised is /not/ used. 32 | -- 33 | -- NB: This definition *must* be kept in sync with `TysWiredIn.parrTyCon'! 34 | -- 35 | data [::] e = PArr !Int (Array# e) 36 | 37 | type PArr = [::] -- this synonym is to get access to '[::]' without using the special syntax 38 | -------------------------------------------------------------------------------- /base/GHC/Profiling.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | -- | @since 4.7.0.0 5 | module GHC.Profiling where 6 | 7 | import GHC.Base 8 | 9 | foreign import ccall startProfTimer :: IO () 10 | foreign import ccall stopProfTimer :: IO () 11 | -------------------------------------------------------------------------------- /base/GHC/STRef.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-} 3 | {-# OPTIONS_HADDOCK hide #-} 4 | 5 | ----------------------------------------------------------------------------- 6 | -- | 7 | -- Module : GHC.STRef 8 | -- Copyright : (c) The University of Glasgow, 1994-2002 9 | -- License : see libraries/base/LICENSE 10 | -- 11 | -- Maintainer : cvs-ghc@haskell.org 12 | -- Stability : internal 13 | -- Portability : non-portable (GHC Extensions) 14 | -- 15 | -- References in the 'ST' monad. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module GHC.STRef ( 20 | STRef(..), 21 | newSTRef, readSTRef, writeSTRef 22 | ) where 23 | 24 | import GHC.ST 25 | import GHC.Base 26 | 27 | data STRef s a = STRef (MutVar# s a) 28 | -- ^ a value of type @STRef s a@ is a mutable variable in state thread @s@, 29 | -- containing a value of type @a@ 30 | 31 | -- |Build a new 'STRef' in the current state thread 32 | newSTRef :: a -> ST s (STRef s a) 33 | newSTRef init = ST $ \s1# -> 34 | case newMutVar# init s1# of { (# s2#, var# #) -> 35 | (# s2#, STRef var# #) } 36 | 37 | -- |Read the value of an 'STRef' 38 | readSTRef :: STRef s a -> ST s a 39 | readSTRef (STRef var#) = ST $ \s1# -> readMutVar# var# s1# 40 | 41 | -- |Write a new value into an 'STRef' 42 | writeSTRef :: STRef s a -> a -> ST s () 43 | writeSTRef (STRef var#) val = ST $ \s1# -> 44 | case writeMutVar# var# val s1# of { s2# -> 45 | (# s2#, () #) } 46 | 47 | -- Just pointer equality on mutable references: 48 | instance Eq (STRef s a) where 49 | STRef v1# == STRef v2# = isTrue# (sameMutVar# v1# v2#) 50 | -------------------------------------------------------------------------------- /base/GHC/Stack/CCS.hs-boot: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | module GHC.Stack.CCS where 3 | 4 | {- Cuts the following loop: 5 | 6 | GHC.Exception.errorCallWithCallStackException requires 7 | GHC.Stack.CCS.currentCallStack, which requires 8 | Foreign.C (for peeking CostCentres) 9 | GHC.Foreign, GHC.IO.Encoding (for decoding UTF-8 strings) 10 | .. lots of stuff ... 11 | GHC.Exception 12 | -} 13 | 14 | import GHC.Base 15 | 16 | currentCallStack :: IO [String] 17 | -------------------------------------------------------------------------------- /base/Numeric/Natural.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | {-# LANGUAGE Trustworthy #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Numeric.Natural 7 | -- Copyright : (C) 2014 Herbert Valerio Riedel, 8 | -- (C) 2011 Edward Kmett 9 | -- License : see libraries/base/LICENSE 10 | -- 11 | -- Maintainer : libraries@haskell.org 12 | -- Stability : provisional 13 | -- Portability : portable 14 | -- 15 | -- The arbitrary-precision 'Natural' number type. 16 | -- 17 | -- @since 4.8.0.0 18 | ----------------------------------------------------------------------------- 19 | 20 | module Numeric.Natural 21 | ( Natural 22 | ) where 23 | 24 | import GHC.Natural 25 | -------------------------------------------------------------------------------- /base/Setup.hs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import Distribution.Simple 4 | 5 | main :: IO () 6 | main = defaultMainWithHooks autoconfUserHooks 7 | -------------------------------------------------------------------------------- /base/System/Exit.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : System.Exit 6 | -- Copyright : (c) The University of Glasgow 2001 7 | -- License : BSD-style (see the file libraries/base/LICENSE) 8 | -- 9 | -- Maintainer : libraries@haskell.org 10 | -- Stability : provisional 11 | -- Portability : portable 12 | -- 13 | -- Exiting the program. 14 | -- 15 | ----------------------------------------------------------------------------- 16 | 17 | module System.Exit 18 | ( 19 | ExitCode(ExitSuccess,ExitFailure) 20 | , exitWith 21 | , exitFailure 22 | , exitSuccess 23 | , die 24 | ) where 25 | 26 | import System.IO 27 | 28 | import GHC.IO 29 | import GHC.IO.Exception 30 | 31 | -- --------------------------------------------------------------------------- 32 | -- exitWith 33 | 34 | -- | Computation 'exitWith' @code@ throws 'ExitCode' @code@. 35 | -- Normally this terminates the program, returning @code@ to the 36 | -- program's caller. 37 | -- 38 | -- On program termination, the standard 'Handle's 'stdout' and 39 | -- 'stderr' are flushed automatically; any other buffered 'Handle's 40 | -- need to be flushed manually, otherwise the buffered data will be 41 | -- discarded. 42 | -- 43 | -- A program that fails in any other way is treated as if it had 44 | -- called 'exitFailure'. 45 | -- A program that terminates successfully without calling 'exitWith' 46 | -- explicitly is treated as it it had called 'exitWith' 'ExitSuccess'. 47 | -- 48 | -- As an 'ExitCode' is not an 'IOError', 'exitWith' bypasses 49 | -- the error handling in the 'IO' monad and cannot be intercepted by 50 | -- 'catch' from the "Prelude". However it is a 'SomeException', and can 51 | -- be caught using the functions of "Control.Exception". This means 52 | -- that cleanup computations added with 'Control.Exception.bracket' 53 | -- (from "Control.Exception") are also executed properly on 'exitWith'. 54 | -- 55 | -- Note: in GHC, 'exitWith' should be called from the main program 56 | -- thread in order to exit the process. When called from another 57 | -- thread, 'exitWith' will throw an 'ExitException' as normal, but the 58 | -- exception will not cause the process itself to exit. 59 | -- 60 | exitWith :: ExitCode -> IO a 61 | exitWith ExitSuccess = throwIO ExitSuccess 62 | exitWith code@(ExitFailure n) 63 | | n /= 0 = throwIO code 64 | | otherwise = ioError (IOError Nothing InvalidArgument "exitWith" "ExitFailure 0" Nothing Nothing) 65 | 66 | -- | The computation 'exitFailure' is equivalent to 67 | -- 'exitWith' @(@'ExitFailure' /exitfail/@)@, 68 | -- where /exitfail/ is implementation-dependent. 69 | exitFailure :: IO a 70 | exitFailure = exitWith (ExitFailure 1) 71 | 72 | -- | The computation 'exitSuccess' is equivalent to 73 | -- 'exitWith' 'ExitSuccess', It terminates the program 74 | -- successfully. 75 | exitSuccess :: IO a 76 | exitSuccess = exitWith ExitSuccess 77 | 78 | -- | Write given error message to `stderr` and terminate with `exitFailure`. 79 | -- 80 | -- @since 4.8.0.0 81 | die :: String -> IO a 82 | die err = hPutStrLn stderr err >> exitFailure 83 | -------------------------------------------------------------------------------- /base/System/IO/Unsafe.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : System.IO.Unsafe 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- \"Unsafe\" IO operations. 15 | -- 16 | ----------------------------------------------------------------------------- 17 | 18 | module System.IO.Unsafe ( 19 | -- * Unsafe 'System.IO.IO' operations 20 | unsafePerformIO, 21 | unsafeDupablePerformIO, 22 | unsafeInterleaveIO, 23 | unsafeFixIO, 24 | ) where 25 | 26 | import GHC.Base 27 | import GHC.IO 28 | import GHC.IORef 29 | import GHC.Exception 30 | import Control.Exception 31 | 32 | -- | A slightly faster version of `System.IO.fixIO` that may not be 33 | -- safe to use with multiple threads. The unsafety arises when used 34 | -- like this: 35 | -- 36 | -- > unsafeFixIO $ \r -> do 37 | -- > forkIO (print r) 38 | -- > return (...) 39 | -- 40 | -- In this case, the child thread will receive a @NonTermination@ 41 | -- exception instead of waiting for the value of @r@ to be computed. 42 | -- 43 | -- @since 4.5.0.0 44 | unsafeFixIO :: (a -> IO a) -> IO a 45 | unsafeFixIO k = do 46 | ref <- newIORef (throw NonTermination) 47 | ans <- unsafeDupableInterleaveIO (readIORef ref) 48 | result <- k ans 49 | writeIORef ref result 50 | return result 51 | -------------------------------------------------------------------------------- /base/System/Info.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE CPP #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : System.Info 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- Information about the characteristics of the host 15 | -- system lucky enough to run your program. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module System.Info 20 | ( 21 | os, 22 | arch, 23 | compilerName, 24 | compilerVersion 25 | ) where 26 | 27 | import Data.Version 28 | 29 | -- | The version of 'compilerName' with which the program was compiled 30 | -- or is being interpreted. 31 | compilerVersion :: Version 32 | compilerVersion = Version [major, minor] [] 33 | where (major, minor) = compilerVersionRaw `divMod` 100 34 | 35 | #include "ghcplatform.h" 36 | 37 | -- | The operating system on which the program is running. 38 | os :: String 39 | os = HOST_OS 40 | 41 | -- | The machine architecture on which the program is running. 42 | arch :: String 43 | arch = HOST_ARCH 44 | 45 | -- | The Haskell implementation with which the program was compiled 46 | -- or is being interpreted. 47 | compilerName :: String 48 | compilerName = "ghc" 49 | 50 | compilerVersionRaw :: Int 51 | compilerVersionRaw = __GLASGOW_HASKELL__ 52 | -------------------------------------------------------------------------------- /base/System/Mem.hs: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- | 3 | -- Module : System.Mem 4 | -- Copyright : (c) The University of Glasgow 2001 5 | -- License : BSD-style (see the file libraries/base/LICENSE) 6 | -- 7 | -- Maintainer : libraries@haskell.org 8 | -- Stability : provisional 9 | -- Portability : portable 10 | -- 11 | -- Memory-related system things. 12 | -- 13 | ----------------------------------------------------------------------------- 14 | 15 | {-# LANGUAGE Trustworthy #-} 16 | -- allocation counter stuff is safe, but GHC.Conc.Sync is Unsafe 17 | 18 | module System.Mem 19 | ( 20 | -- * Garbage collection 21 | performGC 22 | , performMajorGC 23 | , performMinorGC 24 | 25 | -- * Allocation counter and limits 26 | , setAllocationCounter 27 | , getAllocationCounter 28 | , enableAllocationLimit 29 | , disableAllocationLimit 30 | ) where 31 | 32 | import GHC.Conc.Sync 33 | 34 | -- | Triggers an immediate major garbage collection. 35 | performGC :: IO () 36 | performGC = performMajorGC 37 | 38 | -- | Triggers an immediate major garbage collection. 39 | -- 40 | -- @since 4.7.0.0 41 | foreign import ccall "performMajorGC" performMajorGC :: IO () 42 | 43 | -- | Triggers an immediate minor garbage collection. 44 | -- 45 | -- @since 4.7.0.0 46 | foreign import ccall "performGC" performMinorGC :: IO () 47 | -------------------------------------------------------------------------------- /base/Text/Read.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Text.Read 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : provisional 12 | -- Portability : non-portable (uses Text.ParserCombinators.ReadP) 13 | -- 14 | -- Converting strings to values. 15 | -- 16 | -- The "Text.Read" library is the canonical library to import for 17 | -- 'Read'-class facilities. For GHC only, it offers an extended and much 18 | -- improved 'Read' class, which constitutes a proposed alternative to the 19 | -- Haskell 2010 'Read'. In particular, writing parsers is easier, and 20 | -- the parsers are much more efficient. 21 | -- 22 | ----------------------------------------------------------------------------- 23 | 24 | module Text.Read ( 25 | -- * The 'Read' class 26 | Read(..), 27 | ReadS, 28 | 29 | -- * Haskell 2010 functions 30 | reads, 31 | read, 32 | readParen, 33 | lex, 34 | 35 | -- * New parsing functions 36 | module Text.ParserCombinators.ReadPrec, 37 | L.Lexeme(..), 38 | lexP, 39 | parens, 40 | readListDefault, 41 | readListPrecDefault, 42 | readEither, 43 | readMaybe 44 | 45 | ) where 46 | 47 | import GHC.Base 48 | import GHC.Read 49 | import Data.Either 50 | import Text.ParserCombinators.ReadP as P 51 | import Text.ParserCombinators.ReadPrec 52 | import qualified Text.Read.Lex as L 53 | 54 | ------------------------------------------------------------------------ 55 | -- utility functions 56 | 57 | -- | equivalent to 'readsPrec' with a precedence of 0. 58 | reads :: Read a => ReadS a 59 | reads = readsPrec minPrec 60 | 61 | -- | Parse a string using the 'Read' instance. 62 | -- Succeeds if there is exactly one valid result. 63 | -- A 'Left' value indicates a parse error. 64 | -- 65 | -- @since 4.6.0.0 66 | readEither :: Read a => String -> Either String a 67 | readEither s = 68 | case [ x | (x,"") <- readPrec_to_S read' minPrec s ] of 69 | [x] -> Right x 70 | [] -> Left "Prelude.read: no parse" 71 | _ -> Left "Prelude.read: ambiguous parse" 72 | where 73 | read' = 74 | do x <- readPrec 75 | lift P.skipSpaces 76 | return x 77 | 78 | -- | Parse a string using the 'Read' instance. 79 | -- Succeeds if there is exactly one valid result. 80 | -- 81 | -- @since 4.6.0.0 82 | readMaybe :: Read a => String -> Maybe a 83 | readMaybe s = case readEither s of 84 | Left _ -> Nothing 85 | Right a -> Just a 86 | 87 | -- | The 'read' function reads input from a string, which must be 88 | -- completely consumed by the input process. 89 | read :: Read a => String -> a 90 | read s = either errorWithoutStackTrace id (readEither s) 91 | -------------------------------------------------------------------------------- /base/Text/Show.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | {-# LANGUAGE NoImplicitPrelude #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Text.Show 7 | -- Copyright : (c) The University of Glasgow 2001 8 | -- License : BSD-style (see the file libraries/base/LICENSE) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : provisional 12 | -- Portability : portable 13 | -- 14 | -- Converting values to readable strings: 15 | -- the 'Show' class and associated functions. 16 | -- 17 | ----------------------------------------------------------------------------- 18 | 19 | module Text.Show ( 20 | ShowS, 21 | Show(showsPrec, show, showList), 22 | shows, 23 | showChar, 24 | showString, 25 | showParen, 26 | showListWith, 27 | ) where 28 | 29 | import GHC.Show 30 | 31 | -- | Show a list (using square brackets and commas), given a function 32 | -- for showing elements. 33 | showListWith :: (a -> ShowS) -> [a] -> ShowS 34 | showListWith = showList__ 35 | -------------------------------------------------------------------------------- /base/Text/Show/Functions.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Safe #-} 2 | -- This module deliberately declares orphan instances: 3 | {-# OPTIONS_GHC -Wno-orphans #-} 4 | 5 | ----------------------------------------------------------------------------- 6 | -- | 7 | -- Module : Text.Show.Functions 8 | -- Copyright : (c) The University of Glasgow 2001 9 | -- License : BSD-style (see the file libraries/base/LICENSE) 10 | -- 11 | -- Maintainer : libraries@haskell.org 12 | -- Stability : provisional 13 | -- Portability : portable 14 | -- 15 | -- Optional instance of 'Text.Show.Show' for functions: 16 | -- 17 | -- > instance Show (a -> b) where 18 | -- > showsPrec _ _ = showString \"\\" 19 | -- 20 | ----------------------------------------------------------------------------- 21 | 22 | module Text.Show.Functions () where 23 | 24 | instance Show (a -> b) where 25 | showsPrec _ _ = showString "" 26 | 27 | -------------------------------------------------------------------------------- /base/Unsafe/Coerce.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Unsafe #-} 2 | {-# LANGUAGE NoImplicitPrelude, MagicHash #-} 3 | 4 | ----------------------------------------------------------------------------- 5 | -- | 6 | -- Module : Unsafe.Coerce 7 | -- Copyright : Malcolm Wallace 2006 8 | -- License : BSD-style (see the LICENSE file in the distribution) 9 | -- 10 | -- Maintainer : libraries@haskell.org 11 | -- Stability : experimental 12 | -- Portability : portable 13 | -- 14 | -- The highly unsafe primitive 'unsafeCoerce' converts a value from any 15 | -- type to any other type. Needless to say, if you use this function, 16 | -- it is your responsibility to ensure that the old and new types have 17 | -- identical internal representations, in order to prevent runtime corruption. 18 | -- 19 | -- The types for which 'unsafeCoerce' is representation-safe may differ 20 | -- from compiler to compiler (and version to version). 21 | -- 22 | -- * Documentation for correct usage in GHC will be found under 23 | -- 'unsafeCoerce#' in GHC.Base (around which 'unsafeCoerce' is just a 24 | -- trivial wrapper). 25 | -- 26 | -- * In nhc98, the only representation-safe coercions are between Enum 27 | -- types with the same range (e.g. Int, Int32, Char, Word32), 28 | -- or between a newtype and the type that it wraps. 29 | -- 30 | ----------------------------------------------------------------------------- 31 | 32 | module Unsafe.Coerce (unsafeCoerce) where 33 | 34 | import GHC.Integer () -- for build ordering 35 | import GHC.Prim (unsafeCoerce#) 36 | 37 | local_id :: a -> a 38 | local_id x = x -- See Note [Mega-hack for coerce] 39 | 40 | {- Note [Mega-hack for coerce] 41 | 42 | If we just say 43 | unsafeCoerce x = unsafeCoerce# x 44 | then the simple-optimiser that the desugarer runs will eta-reduce to 45 | unsafeCoerce :: forall (a:*) (b:*). a -> b 46 | unsafeCoerce = unsafeCoerce# 47 | And that, sadly, is ill-typed because unsafeCoerce# has OpenKind type variables 48 | And rightly so, because we shouldn't be calling unsafeCoerce# in a higher 49 | order way; it has a compulsory unfolding 50 | unsafeCoerce# a b x = x |> UnsafeCo a b 51 | and we really rely on it being inlined pronto. But the simple-optimiser doesn't. 52 | The identity function local_id delays the eta reduction just long enough 53 | for unsafeCoerce# to get inlined. 54 | 55 | Sigh. This is horrible, but then so is unsafeCoerce. 56 | -} 57 | 58 | unsafeCoerce :: a -> b 59 | unsafeCoerce x = local_id (unsafeCoerce# x) 60 | -- See Note [Unsafe coerce magic] in basicTypes/MkId 61 | -- NB: Do not eta-reduce this definition, else the type checker 62 | -- give usafeCoerce the same (dangerous) type as unsafeCoerce# 63 | -------------------------------------------------------------------------------- /base/base.buildinfo.in: -------------------------------------------------------------------------------- 1 | extra-lib-dirs: @ICONV_LIB_DIRS@ 2 | extra-libraries: @EXTRA_LIBS@ 3 | include-dirs: @ICONV_INCLUDE_DIRS@ 4 | install-includes: HsBaseConfig.h EventConfig.h 5 | -------------------------------------------------------------------------------- /base/cbits/DarwinUtils.c: -------------------------------------------------------------------------------- 1 | #include "HsBase.h" 2 | 3 | #if defined(darwin_HOST_OS) || defined(ios_HOST_OS) 4 | #include 5 | 6 | static double scaling_factor = 0.0; 7 | 8 | void initialize_timer() 9 | { 10 | mach_timebase_info_data_t info; 11 | (void) mach_timebase_info(&info); 12 | scaling_factor = (double)info.numer / (double)info.denom; 13 | scaling_factor *= 1e-9; 14 | } 15 | 16 | void absolute_time(double *result) 17 | { 18 | uint64_t time = mach_absolute_time(); 19 | *result = (double)time * scaling_factor; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /base/cbits/PrelIOUtils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) The University of Glasgow 2002 3 | * 4 | * static versions of the inline functions in HsBase.h 5 | */ 6 | 7 | #define INLINE 8 | 9 | #include "Rts.h" 10 | #include "HsBase.h" 11 | 12 | void errorBelch2(const char*s, char *t) 13 | { 14 | fprintf(stderr, s, t); 15 | fprintf(stderr, "\n"); 16 | } 17 | 18 | void debugBelch2(const char*s, char *t) 19 | { 20 | fprintf(stderr, s, t); 21 | fflush(stderr); 22 | } 23 | 24 | #if defined(HAVE_LIBCHARSET) 25 | # include 26 | #elif defined(HAVE_LANGINFO_H) 27 | # include 28 | #endif 29 | 30 | #if !defined(mingw32_HOST_OS) 31 | const char* localeEncoding(void) 32 | { 33 | #if defined(HAVE_LIBCHARSET) 34 | return locale_charset(); 35 | 36 | #elif defined(HAVE_LANGINFO_H) 37 | return nl_langinfo(CODESET); 38 | 39 | #else 40 | #warning Depending on the unportable behavior of GNU iconv due to absence of both libcharset and langinfo.h 41 | /* GNU iconv accepts "" to mean the current locale's 42 | * encoding. Warning: This isn't portable. 43 | */ 44 | return ""; 45 | #endif 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /base/cbits/README.Unicode: -------------------------------------------------------------------------------- 1 | 2 | WCsubst.c is generated with: 3 | 4 | sh ubconfc < UnicodeData.txt > WCsubst.c 5 | 6 | where UnicodeData.txt came from 7 | 8 | http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt 9 | -------------------------------------------------------------------------------- /base/cbits/SetEnv.c: -------------------------------------------------------------------------------- 1 | #include "HsBase.h" 2 | #ifdef HAVE_UNSETENV 3 | int __hsbase_unsetenv(const char *name) { 4 | #ifdef UNSETENV_RETURNS_VOID 5 | unsetenv(name); 6 | return 0; 7 | #else 8 | return unsetenv(name); 9 | #endif 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /base/cbits/consUtils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) The University of Glasgow 2002 3 | * 4 | * Win32 Console API support 5 | */ 6 | #if defined(_WIN32) || defined(__CYGWIN__) 7 | /* to the end */ 8 | 9 | #include "consUtils.h" 10 | #include 11 | #include 12 | 13 | #if defined(__CYGWIN__) 14 | #define _get_osfhandle get_osfhandle 15 | #endif 16 | 17 | int is_console__(int fd) { 18 | DWORD st; 19 | HANDLE h; 20 | if (!_isatty(fd)) { 21 | /* TTY must be a character device */ 22 | return 0; 23 | } 24 | h = (HANDLE)_get_osfhandle(fd); 25 | if (h == INVALID_HANDLE_VALUE) { 26 | /* Broken handle can't be terminal */ 27 | return 0; 28 | } 29 | if (!GetConsoleMode(h, &st)) { 30 | /* GetConsoleMode appears to fail when it's not a TTY. In 31 | particular, it's what most of our terminal functions 32 | assume works, so if it doesn't work for all intents 33 | and purposes we're not dealing with a terminal. */ 34 | return 0; 35 | } 36 | return 1; 37 | } 38 | 39 | 40 | int 41 | set_console_buffering__(int fd, int cooked) 42 | { 43 | HANDLE h; 44 | DWORD st; 45 | /* According to GetConsoleMode() docs, it is not possible to 46 | leave ECHO_INPUT enabled without also having LINE_INPUT, 47 | so we have to turn both off here. */ 48 | DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; 49 | 50 | if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { 51 | if ( GetConsoleMode(h,&st) && 52 | SetConsoleMode(h, cooked ? (st | ENABLE_LINE_INPUT) : st & ~flgs) ) { 53 | return 0; 54 | } 55 | } 56 | return -1; 57 | } 58 | 59 | int 60 | set_console_echo__(int fd, int on) 61 | { 62 | HANDLE h; 63 | DWORD st; 64 | DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; 65 | 66 | if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { 67 | if ( GetConsoleMode(h,&st) && 68 | SetConsoleMode(h,( on ? (st | flgs) : (st & ~ENABLE_ECHO_INPUT))) ) { 69 | return 0; 70 | } 71 | } 72 | return -1; 73 | } 74 | 75 | int 76 | get_console_echo__(int fd) 77 | { 78 | HANDLE h; 79 | DWORD st; 80 | 81 | if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) { 82 | if ( GetConsoleMode(h,&st) ) { 83 | return (st & ENABLE_ECHO_INPUT ? 1 : 0); 84 | } 85 | } 86 | return -1; 87 | } 88 | 89 | int 90 | flush_input_console__(int fd) 91 | { 92 | HANDLE h = (HANDLE)_get_osfhandle(fd); 93 | 94 | if ( h != INVALID_HANDLE_VALUE ) { 95 | /* If the 'fd' isn't connected to a console; treat the flush 96 | * operation as a NOP. 97 | */ 98 | DWORD unused; 99 | if ( !GetConsoleMode(h,&unused) && 100 | GetLastError() == ERROR_INVALID_HANDLE ) { 101 | return 0; 102 | } 103 | if ( FlushConsoleInputBuffer(h) ) { 104 | return 0; 105 | } 106 | } 107 | /* ToDo: translate GetLastError() into something errno-friendly */ 108 | return -1; 109 | } 110 | 111 | #endif /* defined(_WIN32) || ... */ 112 | -------------------------------------------------------------------------------- /base/cbits/iconv.c: -------------------------------------------------------------------------------- 1 | #ifndef _WIN32 2 | 3 | #include 4 | #include 5 | 6 | iconv_t hs_iconv_open(const char* tocode, 7 | const char* fromcode) 8 | { 9 | return iconv_open(tocode, fromcode); 10 | } 11 | 12 | size_t hs_iconv(iconv_t cd, 13 | const char* * inbuf, size_t * inbytesleft, 14 | char* * outbuf, size_t * outbytesleft) 15 | { 16 | // (void*) cast avoids a warning. Some iconvs use (const 17 | // char**inbuf), other use (char **inbuf). 18 | return iconv(cd, (void*)inbuf, inbytesleft, outbuf, outbytesleft); 19 | } 20 | 21 | int hs_iconv_close(iconv_t cd) { 22 | return iconv_close(cd); 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /base/cbits/rts.c: -------------------------------------------------------------------------------- 1 | #include "Rts.h" 2 | #include "rts/Flags.h" 3 | 4 | GC_FLAGS *getGcFlags() 5 | { 6 | return &RtsFlags.GcFlags; 7 | } 8 | 9 | CONCURRENT_FLAGS *getConcFlags() 10 | { 11 | return &RtsFlags.ConcFlags; 12 | } 13 | 14 | MISC_FLAGS *getMiscFlags() 15 | { 16 | return &RtsFlags.MiscFlags; 17 | } 18 | 19 | DEBUG_FLAGS *getDebugFlags() 20 | { 21 | return &RtsFlags.DebugFlags; 22 | } 23 | 24 | COST_CENTRE_FLAGS *getCcFlags() 25 | { 26 | return &RtsFlags.CcFlags; 27 | } 28 | 29 | PROFILING_FLAGS *getProfFlags() 30 | { 31 | return &RtsFlags.ProfFlags; 32 | } 33 | 34 | TRACE_FLAGS *getTraceFlags() 35 | { 36 | return &RtsFlags.TraceFlags; 37 | } 38 | 39 | TICKY_FLAGS *getTickyFlags() 40 | { 41 | return &RtsFlags.TickyFlags; 42 | } 43 | -------------------------------------------------------------------------------- /base/cbits/sysconf.c: -------------------------------------------------------------------------------- 1 | #include "HsBaseConfig.h" 2 | 3 | /* For _SC_CLK_TCK */ 4 | #if HAVE_UNISTD_H 5 | #include 6 | #endif 7 | 8 | /* for CLK_TCK */ 9 | #if HAVE_TIME_H 10 | #include 11 | #endif 12 | 13 | long clk_tck(void) { 14 | #if defined(CLK_TCK) 15 | return (CLK_TCK); 16 | #else 17 | return sysconf(_SC_CLK_TCK); 18 | #endif 19 | } 20 | -------------------------------------------------------------------------------- /base/codepages/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: default 3 | default: 4 | $(MAKE) getCodepages 5 | $(MAKE) genTable 6 | 7 | .PHONY: getCodepages 8 | getCodepages: 9 | rm -rf www.unicode.org 10 | rm -rf CPs 11 | mkdir CPs 12 | wget -r -np http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/ 13 | find www.unicode.org -name 'CP*' -exec cp {} CPs \; 14 | 15 | .PHONY: genTable 16 | genTable: 17 | ghc --make MakeTable 18 | ./MakeTable GHC.IO.Encoding.CodePage.Table ../GHC/IO/Encoding/CodePage/Table.hs CPs/* 19 | 20 | -------------------------------------------------------------------------------- /base/include/CTypes.h: -------------------------------------------------------------------------------- 1 | {- -------------------------------------------------------------------------- 2 | // Dirty CPP hackery for CTypes/CTypesISO 3 | // 4 | // (c) The FFI task force, 2000 5 | // -------------------------------------------------------------------------- 6 | -} 7 | 8 | #ifndef CTYPES__H 9 | #define CTYPES__H 10 | 11 | {- 12 | // As long as there is no automatic derivation of classes for newtypes we resort 13 | // to extremely dirty cpp-hackery. :-P Some care has to be taken when the 14 | // macros below are modified, otherwise the layout rule will bite you. 15 | -} 16 | 17 | -- // GHC can derive any class for a newtype, so we make use of that here... 18 | 19 | #define ARITHMETIC_CLASSES Eq,Ord,Num,Enum,Storable,Real 20 | #define INTEGRAL_CLASSES Bounded,Integral,Bits,FiniteBits 21 | #define FLOATING_CLASSES Fractional,Floating,RealFrac,RealFloat 22 | 23 | #define ARITHMETIC_TYPE(T,B) \ 24 | newtype T = T B deriving (ARITHMETIC_CLASSES); \ 25 | INSTANCE_READ(T,B); \ 26 | INSTANCE_SHOW(T,B); 27 | 28 | #define INTEGRAL_TYPE(T,B) \ 29 | newtype T = T B deriving (ARITHMETIC_CLASSES, INTEGRAL_CLASSES); \ 30 | INSTANCE_READ(T,B); \ 31 | INSTANCE_SHOW(T,B); 32 | 33 | #define INTEGRAL_TYPE_WITH_CTYPE(T,THE_CTYPE,B) \ 34 | newtype {-# CTYPE "THE_CTYPE" #-} T = T B deriving (ARITHMETIC_CLASSES, INTEGRAL_CLASSES); \ 35 | INSTANCE_READ(T,B); \ 36 | INSTANCE_SHOW(T,B); 37 | 38 | #define FLOATING_TYPE(T,B) \ 39 | newtype T = T B deriving (ARITHMETIC_CLASSES, FLOATING_CLASSES); \ 40 | INSTANCE_READ(T,B); \ 41 | INSTANCE_SHOW(T,B); 42 | 43 | #define INSTANCE_READ(T,B) \ 44 | instance Read T where { \ 45 | readsPrec = unsafeCoerce# (readsPrec :: Int -> ReadS B); \ 46 | readList = unsafeCoerce# (readList :: ReadS [B]); } 47 | 48 | #define INSTANCE_SHOW(T,B) \ 49 | instance Show T where { \ 50 | showsPrec = unsafeCoerce# (showsPrec :: Int -> B -> ShowS); \ 51 | show = unsafeCoerce# (show :: B -> String); \ 52 | showList = unsafeCoerce# (showList :: [B] -> ShowS); } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /base/include/EventConfig.h: -------------------------------------------------------------------------------- 1 | /* include/EventConfig.h. Generated from EventConfig.h.in by configure. */ 2 | /* include/EventConfig.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define if you have epoll support. */ 5 | #define HAVE_EPOLL 1 6 | 7 | /* Define to 1 if you have the `epoll_create1' function. */ 8 | /* #undef HAVE_EPOLL_CREATE1 */ 9 | 10 | /* Define to 1 if you have the `epoll_ctl' function. */ 11 | #define HAVE_EPOLL_CTL 1 12 | 13 | /* Define to 1 if you have the `eventfd' function. */ 14 | #define HAVE_EVENTFD 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 if you have the `kevent' function. */ 20 | /* #undef HAVE_KEVENT */ 21 | 22 | /* Define to 1 if you have the `kevent64' function. */ 23 | /* #undef HAVE_KEVENT64 */ 24 | 25 | /* Define if you have kqueue support. */ 26 | /* #undef HAVE_KQUEUE */ 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_MEMORY_H 1 30 | 31 | /* Define if you have poll support. */ 32 | #define HAVE_POLL 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_POLL_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_SIGNAL_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_STDINT_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_STDLIB_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_STRINGS_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_STRING_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_SYS_EPOLL_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_SYS_EVENTFD_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | /* #undef HAVE_SYS_EVENT_H */ 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_SYS_STAT_H 1 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #define HAVE_SYS_TYPES_H 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_UNISTD_H 1 69 | 70 | /* Define to the address where bug reports for this package should be sent. */ 71 | #define PACKAGE_BUGREPORT "libraries@haskell.org" 72 | 73 | /* Define to the full name of this package. */ 74 | #define PACKAGE_NAME "Haskell base package" 75 | 76 | /* Define to the full name and version of this package. */ 77 | #define PACKAGE_STRING "Haskell base package 1.0" 78 | 79 | /* Define to the one symbol short name of this package. */ 80 | #define PACKAGE_TARNAME "base" 81 | 82 | /* Define to the version of this package. */ 83 | #define PACKAGE_VERSION "1.0" 84 | 85 | /* Define to 1 if you have the ANSI C header files. */ 86 | #define STDC_HEADERS 1 87 | 88 | /* The size of `kev.filter', as computed by sizeof. */ 89 | /* #undef SIZEOF_KEV_FILTER */ 90 | 91 | /* The size of `kev.flags', as computed by sizeof. */ 92 | /* #undef SIZEOF_KEV_FLAGS */ 93 | -------------------------------------------------------------------------------- /base/include/EventConfig.h.in: -------------------------------------------------------------------------------- 1 | /* include/EventConfig.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define if you have epoll support. */ 4 | #undef HAVE_EPOLL 5 | 6 | /* Define to 1 if you have the `epoll_create1' function. */ 7 | #undef HAVE_EPOLL_CREATE1 8 | 9 | /* Define to 1 if you have the `epoll_ctl' function. */ 10 | #undef HAVE_EPOLL_CTL 11 | 12 | /* Define to 1 if you have the `eventfd' function. */ 13 | #undef HAVE_EVENTFD 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the `kevent' function. */ 19 | #undef HAVE_KEVENT 20 | 21 | /* Define to 1 if you have the `kevent64' function. */ 22 | #undef HAVE_KEVENT64 23 | 24 | /* Define if you have kqueue support. */ 25 | #undef HAVE_KQUEUE 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_MEMORY_H 29 | 30 | /* Define if you have poll support. */ 31 | #undef HAVE_POLL 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_POLL_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_SIGNAL_H 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_STDINT_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_STDLIB_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_STRINGS_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_STRING_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_SYS_EPOLL_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_SYS_EVENTFD_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_SYS_EVENT_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_SYS_STAT_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_SYS_TYPES_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_UNISTD_H 68 | 69 | /* Define to the address where bug reports for this package should be sent. */ 70 | #undef PACKAGE_BUGREPORT 71 | 72 | /* Define to the full name of this package. */ 73 | #undef PACKAGE_NAME 74 | 75 | /* Define to the full name and version of this package. */ 76 | #undef PACKAGE_STRING 77 | 78 | /* Define to the one symbol short name of this package. */ 79 | #undef PACKAGE_TARNAME 80 | 81 | /* Define to the version of this package. */ 82 | #undef PACKAGE_VERSION 83 | 84 | /* Define to 1 if you have the ANSI C header files. */ 85 | #undef STDC_HEADERS 86 | 87 | /* The size of `kev.filter', as computed by sizeof. */ 88 | #undef SIZEOF_KEV_FILTER 89 | 90 | /* The size of `kev.flags', as computed by sizeof. */ 91 | #undef SIZEOF_KEV_FLAGS 92 | -------------------------------------------------------------------------------- /base/include/HsEvent.h: -------------------------------------------------------------------------------- 1 | #ifndef __HS_EVENT_H__ 2 | #define __HS_EVENT_H__ 3 | 4 | #include "EventConfig.h" 5 | 6 | #include 7 | #include 8 | 9 | #if !defined(INLINE) 10 | # if defined(_MSC_VER) 11 | # define INLINE extern __inline 12 | # else 13 | # define INLINE inline 14 | # endif 15 | #endif 16 | 17 | INLINE int __hsevent_num_signals(void) 18 | { 19 | #if defined(_NSIG) 20 | return _NSIG; 21 | #else 22 | return 128; /* best guess */ 23 | #endif 24 | } 25 | 26 | INLINE void __hsevent_thread_self(pthread_t *tid) 27 | { 28 | *tid = pthread_self(); 29 | } 30 | 31 | INLINE int __hsevent_kill_thread(pthread_t *tid, int sig) 32 | { 33 | return pthread_kill(*tid, sig); 34 | } 35 | 36 | #endif /* __HS_EVENT_H__ */ 37 | /* 38 | * Local Variables: 39 | * c-file-style: "stroustrup" 40 | * End: 41 | */ 42 | -------------------------------------------------------------------------------- /base/include/WCsubst.h: -------------------------------------------------------------------------------- 1 | #ifndef WCSUBST_INCL 2 | 3 | #define WCSUBST_INCL 4 | 5 | #include "HsFFI.h" 6 | #include 7 | 8 | HsInt u_iswupper(HsInt wc); 9 | HsInt u_iswdigit(HsInt wc); 10 | HsInt u_iswalpha(HsInt wc); 11 | HsInt u_iswcntrl(HsInt wc); 12 | HsInt u_iswspace(HsInt wc); 13 | HsInt u_iswprint(HsInt wc); 14 | HsInt u_iswlower(HsInt wc); 15 | 16 | HsInt u_iswalnum(HsInt wc); 17 | 18 | HsInt u_towlower(HsInt wc); 19 | HsInt u_towupper(HsInt wc); 20 | HsInt u_towtitle(HsInt wc); 21 | 22 | HsInt u_gencat(HsInt wc); 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /base/include/consUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) The University of Glasgow, 2000-2002 3 | * 4 | * Win32 Console API helpers. 5 | */ 6 | #ifndef __CONSUTILS_H__ 7 | #define __CONSUTILS_H__ 8 | extern int is_console__(int fd); 9 | extern int set_console_buffering__(int fd, int cooked); 10 | extern int set_console_echo__(int fd, int on); 11 | extern int get_console_echo__(int fd); 12 | extern int flush_input_console__ (int fd); 13 | #endif 14 | -------------------------------------------------------------------------------- /base/include/ieee-flpt.h: -------------------------------------------------------------------------------- 1 | /* this file is #included into both C (.c and .hc) and Haskell files */ 2 | 3 | /* IEEE format floating-point */ 4 | #define IEEE_FLOATING_POINT 1 5 | 6 | /* Radix of exponent representation */ 7 | #ifndef FLT_RADIX 8 | # define FLT_RADIX 2 9 | #endif 10 | 11 | /* Number of base-FLT_RADIX digits in the significand of a float */ 12 | #ifndef FLT_MANT_DIG 13 | # define FLT_MANT_DIG 24 14 | #endif 15 | /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ 16 | #ifndef FLT_MIN_EXP 17 | # define FLT_MIN_EXP (-125) 18 | #endif 19 | /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ 20 | #ifndef FLT_MAX_EXP 21 | # define FLT_MAX_EXP 128 22 | #endif 23 | 24 | /* Number of base-FLT_RADIX digits in the significand of a double */ 25 | #ifndef DBL_MANT_DIG 26 | # define DBL_MANT_DIG 53 27 | #endif 28 | /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ 29 | #ifndef DBL_MIN_EXP 30 | # define DBL_MIN_EXP (-1021) 31 | #endif 32 | /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ 33 | #ifndef DBL_MAX_EXP 34 | # define DBL_MAX_EXP 1024 35 | #endif 36 | -------------------------------------------------------------------------------- /base/include/md5.h: -------------------------------------------------------------------------------- 1 | /* MD5 message digest */ 2 | #ifndef _MD5_H 3 | #define _MD5_H 4 | 5 | #include "HsFFI.h" 6 | 7 | typedef HsWord32 word32; 8 | typedef HsWord8 byte; 9 | 10 | struct MD5Context { 11 | word32 buf[4]; 12 | word32 bytes[2]; 13 | word32 in[16]; 14 | }; 15 | 16 | void __hsbase_MD5Init(struct MD5Context *context); 17 | void __hsbase_MD5Update(struct MD5Context *context, byte const *buf, int len); 18 | void __hsbase_MD5Final(byte digest[16], struct MD5Context *context); 19 | void __hsbase_MD5Transform(word32 buf[4], word32 const in[16]); 20 | 21 | #endif /* _MD5_H */ 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /base/prologue.txt: -------------------------------------------------------------------------------- 1 | This package contains the @Prelude@ and its support libraries, and a large 2 | collection of useful libraries ranging from data structures to parsing 3 | combinators and debugging utilities. 4 | -------------------------------------------------------------------------------- /boot-data/include/ghcconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef __GHCCONFIG_H__ 2 | #define __GHCCONFIG_H__ 3 | 4 | #include "ghcautoconf.h" 5 | #include "ghcplatform.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /boot-data/include/ghcplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __GHCPLATFORM_H__ 2 | #define __GHCPLATFORM_H__ 3 | 4 | #define BuildPlatform_TYPE x86_64_unknown_linux 5 | #define HostPlatform_TYPE x86_64_unknown_linux 6 | 7 | #define x86_64_unknown_linux_BUILD 1 8 | #define x86_64_unknown_linux_HOST 1 9 | 10 | #define x86_64_BUILD_ARCH 1 11 | #define x86_64_HOST_ARCH 1 12 | #define BUILD_ARCH "x86_64" 13 | #define HOST_ARCH "x86_64" 14 | 15 | #define linux_BUILD_OS 1 16 | #define linux_HOST_OS 1 17 | #define BUILD_OS "linux" 18 | #define HOST_OS "linux" 19 | 20 | #define unknown_BUILD_VENDOR 1 21 | #define unknown_HOST_VENDOR 1 22 | #define BUILD_VENDOR "unknown" 23 | #define HOST_VENDOR "unknown" 24 | 25 | /* These TARGET macros are for backwards compatibility... DO NOT USE! */ 26 | #define TargetPlatform_TYPE x86_64_unknown_linux 27 | #define x86_64_unknown_linux_TARGET 1 28 | #define x86_64_TARGET_ARCH 1 29 | #define TARGET_ARCH "x86_64" 30 | #define linux_TARGET_OS 1 31 | #define TARGET_OS "linux" 32 | #define unknown_TARGET_VENDOR 1 33 | 34 | #endif /* __GHCPLATFORM_H__ */ 35 | -------------------------------------------------------------------------------- /boot-data/include/ghcversion.h: -------------------------------------------------------------------------------- 1 | #ifndef __GHCVERSION_H__ 2 | #define __GHCVERSION_H__ 3 | 4 | #ifndef __GLASGOW_HASKELL__ 5 | # define __GLASGOW_HASKELL__ 800 6 | #endif 7 | 8 | #define __GLASGOW_HASKELL_PATCHLEVEL1__ 1 9 | 10 | #define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\ 11 | ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \ 12 | ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ 13 | && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \ 14 | ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \ 15 | && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \ 16 | && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ ) 17 | 18 | #endif /* __GHCVERSION_H__ */ 19 | -------------------------------------------------------------------------------- /boot-data/include/rts/Adjustor.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * Adjustor API 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * -------------------------------------------------------------------------- */ 13 | 14 | #ifndef RTS_ADJUSTOR_H 15 | #define RTS_ADJUSTOR_H 16 | 17 | /* Creating and destroying an adjustor thunk */ 18 | void* createAdjustor (int cconv, 19 | StgStablePtr hptr, 20 | StgFunPtr wptr, 21 | char *typeString); 22 | 23 | void freeHaskellFunctionPtr (void* ptr); 24 | 25 | #endif /* RTS_ADJUSTOR_H */ 26 | -------------------------------------------------------------------------------- /boot-data/include/rts/BlockSignals.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * RTS signal handling 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_BLOCKSIGNALS_H 15 | #define RTS_BLOCKSIGNALS_H 16 | 17 | /* Used by runProcess() in the process package 18 | */ 19 | 20 | /* 21 | * Function: blockUserSignals() 22 | * 23 | * Temporarily block the delivery of further console events. Needed to 24 | * avoid race conditions when GCing the queue of outstanding handlers or 25 | * when emptying the queue by running the handlers. 26 | * 27 | */ 28 | void blockUserSignals(void); 29 | 30 | /* 31 | * Function: unblockUserSignals() 32 | * 33 | * The inverse of blockUserSignals(); re-enable the deliver of console events. 34 | */ 35 | void unblockUserSignals(void); 36 | 37 | #endif /* RTS_BLOCKSIGNALS_H */ 38 | -------------------------------------------------------------------------------- /boot-data/include/rts/Config.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * Rts settings. 6 | * 7 | * NOTE: assumes #include "ghcconfig.h" 8 | * 9 | * NB: THIS FILE IS INCLUDED IN NON-C CODE AND DATA! #defines only please. 10 | * 11 | * To understand the structure of the RTS headers, see the wiki: 12 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 13 | * 14 | * ---------------------------------------------------------------------------*/ 15 | 16 | #ifndef RTS_CONFIG_H 17 | #define RTS_CONFIG_H 18 | 19 | #if defined(TICKY_TICKY) && defined(THREADED_RTS) 20 | #error TICKY_TICKY is incompatible with THREADED_RTS 21 | #endif 22 | 23 | /* 24 | * Whether the runtime system will use libbfd for debugging purposes. 25 | */ 26 | #if defined(DEBUG) && defined(HAVE_BFD_H) && defined(HAVE_LIBBFD) && !defined(_WIN32) 27 | #define USING_LIBBFD 1 28 | #endif 29 | 30 | /* DEBUG implies TRACING and TICKY_TICKY 31 | */ 32 | #if defined(DEBUG) 33 | #define TRACING 34 | #define TICKY_TICKY 35 | #endif 36 | 37 | /* ----------------------------------------------------------------------------- 38 | Signals - supported on non-PAR versions of the runtime. See RtsSignals.h. 39 | -------------------------------------------------------------------------- */ 40 | 41 | #define RTS_USER_SIGNALS 1 42 | 43 | /* Profile spin locks */ 44 | 45 | #define PROF_SPIN 46 | 47 | #endif /* RTS_CONFIG_H */ 48 | -------------------------------------------------------------------------------- /boot-data/include/rts/FileLock.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2007-2009 4 | * 5 | * File locking support as required by Haskell 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_FILELOCK_H 15 | #define RTS_FILELOCK_H 16 | 17 | #include "Stg.h" 18 | 19 | int lockFile(int fd, StgWord64 dev, StgWord64 ino, int for_writing); 20 | int unlockFile(int fd); 21 | 22 | #endif /* RTS_FILELOCK_H */ 23 | -------------------------------------------------------------------------------- /boot-data/include/rts/GetTime.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1995-2009 4 | * 5 | * Interface to the RTS time 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_GETTIME_H 15 | #define RTS_GETTIME_H 16 | 17 | StgWord64 getMonotonicNSec (void); 18 | 19 | #endif /* RTS_GETTIME_H */ 20 | -------------------------------------------------------------------------------- /boot-data/include/rts/Globals.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2006-2009 4 | * 5 | * The RTS stores some "global" values on behalf of libraries, so that 6 | * some libraries can ensure that certain top-level things are shared 7 | * even when multiple versions of the library are loaded. e.g. see 8 | * Data.Typeable and GHC.Conc. 9 | * 10 | * Do not #include this file directly: #include "Rts.h" instead. 11 | * 12 | * To understand the structure of the RTS headers, see the wiki: 13 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 14 | * 15 | * ---------------------------------------------------------------------------*/ 16 | 17 | #ifndef RTS_GLOBALS_H 18 | #define RTS_GLOBALS_H 19 | 20 | StgStablePtr getOrSetGHCConcSignalSignalHandlerStore(StgStablePtr value); 21 | StgStablePtr getOrSetGHCConcWindowsPendingDelaysStore(StgStablePtr ptr); 22 | StgStablePtr getOrSetGHCConcWindowsIOManagerThreadStore(StgStablePtr ptr); 23 | StgStablePtr getOrSetGHCConcWindowsProddingStore(StgStablePtr ptr); 24 | StgStablePtr getOrSetSystemEventThreadEventManagerStore(StgStablePtr ptr); 25 | StgStablePtr getOrSetSystemEventThreadIOManagerThreadStore(StgStablePtr ptr); 26 | StgStablePtr getOrSetSystemTimerThreadEventManagerStore(StgStablePtr ptr); 27 | StgStablePtr getOrSetSystemTimerThreadIOManagerThreadStore(StgStablePtr ptr); 28 | StgStablePtr getOrSetLibHSghcFastStringTable(StgStablePtr ptr); 29 | 30 | #endif /* RTS_GLOBALS_H */ 31 | -------------------------------------------------------------------------------- /boot-data/include/rts/Hpc.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2008-2009 4 | * 5 | * Haskell Program Coverage 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * -------------------------------------------------------------------------- */ 13 | 14 | #ifndef RTS_HPC_H 15 | #define RTS_HPC_H 16 | 17 | // Simple linked list of modules 18 | typedef struct _HpcModuleInfo { 19 | char *modName; // name of module 20 | StgWord32 tickCount; // number of ticks 21 | StgWord32 hashNo; // Hash number for this module's mix info 22 | StgWord64 *tixArr; // tix Array; local for this module 23 | rtsBool from_file; // data was read from the .tix file 24 | struct _HpcModuleInfo *next; 25 | } HpcModuleInfo; 26 | 27 | void hs_hpc_module (char *modName, 28 | StgWord32 modCount, 29 | StgWord32 modHashNo, 30 | StgWord64 *tixArr); 31 | 32 | HpcModuleInfo * hs_hpc_rootModule (void); 33 | 34 | void startupHpc(void); 35 | void exitHpc(void); 36 | 37 | #endif /* RTS_HPC_H */ 38 | -------------------------------------------------------------------------------- /boot-data/include/rts/IOManager.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * IO Manager functionality in the RTS 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * -------------------------------------------------------------------------- */ 13 | 14 | #ifndef RTS_IOMANAGER_H 15 | #define RTS_IOMANAGER_H 16 | 17 | #if defined(mingw32_HOST_OS) 18 | 19 | int rts_InstallConsoleEvent ( int action, StgStablePtr *handler ); 20 | void rts_ConsoleHandlerDone ( int ev ); 21 | extern StgInt console_handler; 22 | 23 | void * getIOManagerEvent (void); 24 | HsWord32 readIOManagerEvent (void); 25 | void sendIOManagerEvent (HsWord32 event); 26 | 27 | #else 28 | 29 | void setIOManagerControlFd (nat cap_no, int fd); 30 | void setTimerManagerControlFd(int fd); 31 | void setIOManagerWakeupFd (int fd); 32 | 33 | #endif 34 | 35 | // 36 | // Communicating with the IO manager thread (see GHC.Conc). 37 | // Posix implementation in posix/Signals.c 38 | // Win32 implementation in win32/ThrIOManager.c 39 | // 40 | void ioManagerWakeup (void); 41 | #if defined(THREADED_RTS) 42 | void ioManagerDie (void); 43 | void ioManagerStart (void); 44 | #endif 45 | 46 | #endif /* RTS_IOMANAGER_H */ 47 | -------------------------------------------------------------------------------- /boot-data/include/rts/LibdwPool.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2015-2016 4 | * 5 | * A pool of libdw sessions 6 | * 7 | * --------------------------------------------------------------------------*/ 8 | 9 | #ifndef RTS_LIBDW_POOL_H 10 | #define RTS_LIBDW_POOL_H 11 | 12 | /* Claim a session from the pool */ 13 | LibdwSession *libdwPoolTake(void); 14 | 15 | /* Return a session to the pool */ 16 | void libdwPoolRelease(LibdwSession *sess); 17 | 18 | /* Free any sessions in the pool forcing a reload of any loaded debug 19 | * information */ 20 | void libdwPoolClear(void); 21 | 22 | #endif /* RTS_LIBDW_POOL_H */ 23 | -------------------------------------------------------------------------------- /boot-data/include/rts/Main.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2009 4 | * 5 | * Entry point for standalone Haskell programs. 6 | * 7 | * ---------------------------------------------------------------------------*/ 8 | 9 | #ifndef RTSMAIN_H 10 | #define RTSMAIN_H 11 | 12 | /* ----------------------------------------------------------------------------- 13 | * The entry point for Haskell programs that use a Haskell main function 14 | * -------------------------------------------------------------------------- */ 15 | 16 | int hs_main (int argc, char *argv[], // program args 17 | StgClosure *main_closure, // closure for Main.main 18 | RtsConfig rts_config) // RTS configuration 19 | GNUC3_ATTRIBUTE(__noreturn__); 20 | 21 | #endif /* RTSMAIN_H */ 22 | -------------------------------------------------------------------------------- /boot-data/include/rts/Parallel.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * Parallelism-related functionality 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * -------------------------------------------------------------------------- */ 13 | 14 | #ifndef RTS_PARALLEL_H 15 | #define RTS_PARALLEL_H 16 | 17 | StgInt newSpark (StgRegTable *reg, StgClosure *p); 18 | 19 | #endif /* RTS_PARALLEL_H */ 20 | -------------------------------------------------------------------------------- /boot-data/include/rts/PrimFloat.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * Primitive floating-point operations 6 | * 7 | * To understand the structure of the RTS headers, see the wiki: 8 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 9 | * 10 | * ---------------------------------------------------------------------------*/ 11 | 12 | #ifndef RTS_PRIMFLOAT_H 13 | #define RTS_PRIMFLOAT_H 14 | 15 | StgDouble __int_encodeDouble (I_ j, I_ e); 16 | StgFloat __int_encodeFloat (I_ j, I_ e); 17 | StgDouble __word_encodeDouble (W_ j, I_ e); 18 | StgFloat __word_encodeFloat (W_ j, I_ e); 19 | 20 | #endif /* RTS_PRIMFLOAT_H */ 21 | -------------------------------------------------------------------------------- /boot-data/include/rts/Signals.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * RTS signal handling 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_SIGNALS_H 15 | #define RTS_SIGNALS_H 16 | 17 | /* NB. #included in Haskell code, no prototypes in here. */ 18 | 19 | /* arguments to stg_sig_install() */ 20 | #define STG_SIG_DFL (-1) 21 | #define STG_SIG_IGN (-2) 22 | #define STG_SIG_ERR (-3) 23 | #define STG_SIG_HAN (-4) 24 | #define STG_SIG_RST (-5) 25 | 26 | #endif /* RTS_SIGNALS_H */ 27 | -------------------------------------------------------------------------------- /boot-data/include/rts/Stable.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * Stable Pointers 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_STABLE_H 15 | #define RTS_STABLE_H 16 | 17 | EXTERN_INLINE StgPtr deRefStablePtr (StgStablePtr stable_ptr); 18 | StgStablePtr getStablePtr (StgPtr p); 19 | 20 | /* ----------------------------------------------------------------------------- 21 | PRIVATE from here. 22 | -------------------------------------------------------------------------- */ 23 | 24 | typedef struct { 25 | StgPtr addr; /* Haskell object, free list, or NULL */ 26 | StgPtr old; /* old Haskell object, used during GC */ 27 | StgClosure *sn_obj; /* the StableName object (or NULL) */ 28 | } snEntry; 29 | 30 | typedef struct { 31 | StgPtr addr; 32 | } spEntry; 33 | 34 | extern DLL_IMPORT_RTS snEntry *stable_name_table; 35 | extern DLL_IMPORT_RTS spEntry *stable_ptr_table; 36 | 37 | EXTERN_INLINE 38 | StgPtr deRefStablePtr(StgStablePtr sp) 39 | { 40 | return stable_ptr_table[(StgWord)sp].addr; 41 | } 42 | 43 | #endif /* RTS_STABLE_H */ 44 | -------------------------------------------------------------------------------- /boot-data/include/rts/StaticPtrTable.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2008-2009 4 | * 5 | * Initialization of the Static Pointer Table 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * -------------------------------------------------------------------------- */ 13 | 14 | #ifndef RTS_STATICPTRTABLE_H 15 | #define RTS_STATICPTRTABLE_H 16 | 17 | /** Inserts an entry in the Static Pointer Table. 18 | * 19 | * The key is a fingerprint computed from the static pointer and the spe_closure 20 | * is a pointer to the closure defining the table entry. 21 | * 22 | * A stable pointer to the closure is made to prevent it from being garbage 23 | * collected while the entry exists on the table. 24 | * 25 | * This function is called from the code generated by 26 | * compiler/deSugar/StaticPtrTable.sptInitCode 27 | * 28 | * */ 29 | void hs_spt_insert (StgWord64 key[2],void* spe_closure); 30 | 31 | /** Removes an entry from the Static Pointer Table. 32 | * 33 | * This function is called from the code generated by 34 | * compiler/deSugar/StaticPtrTable.sptInitCode 35 | * 36 | * */ 37 | void hs_spt_remove (StgWord64 key[2]); 38 | 39 | #endif /* RTS_STATICPTRTABLE_H */ 40 | -------------------------------------------------------------------------------- /boot-data/include/rts/TTY.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2009 4 | * 5 | * POSIX TTY-related functionality 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * -------------------------------------------------------------------------- */ 13 | 14 | #ifndef RTS_TTY_H 15 | #define RTS_TTY_H 16 | 17 | void* __hscore_get_saved_termios(int fd); 18 | void __hscore_set_saved_termios(int fd, void* ts); 19 | 20 | #endif /* RTS_TTY_H */ 21 | -------------------------------------------------------------------------------- /boot-data/include/rts/Threads.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team 1998-2009 4 | * 5 | * External API for the scheduler. For most uses, the functions in 6 | * RtsAPI.h should be enough. 7 | * 8 | * Do not #include this file directly: #include "Rts.h" instead. 9 | * 10 | * To understand the structure of the RTS headers, see the wiki: 11 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 12 | * 13 | * ---------------------------------------------------------------------------*/ 14 | 15 | #ifndef RTS_THREADS_H 16 | #define RTS_THREADS_H 17 | 18 | #ifdef HAVE_SYS_TYPES_H 19 | #include 20 | #endif 21 | 22 | // 23 | // Creating threads 24 | // 25 | StgTSO *createThread (Capability *cap, W_ stack_size); 26 | 27 | void scheduleWaitThread (/* in */ StgTSO *tso, 28 | /* out */ HaskellObj* ret, 29 | /* inout */ Capability **cap); 30 | 31 | StgTSO *createGenThread (Capability *cap, W_ stack_size, 32 | StgClosure *closure); 33 | StgTSO *createIOThread (Capability *cap, W_ stack_size, 34 | StgClosure *closure); 35 | StgTSO *createStrictIOThread (Capability *cap, W_ stack_size, 36 | StgClosure *closure); 37 | 38 | // Suspending/resuming threads around foreign calls 39 | void * suspendThread (StgRegTable *, rtsBool interruptible); 40 | StgRegTable * resumeThread (void *); 41 | 42 | // 43 | // Thread operations from Threads.c 44 | // 45 | int cmp_thread (StgPtr tso1, StgPtr tso2); 46 | int rts_getThreadId (StgPtr tso); 47 | HsInt64 rts_getThreadAllocationCounter (StgPtr tso); 48 | void rts_setThreadAllocationCounter (StgPtr tso, HsInt64 i); 49 | void rts_enableThreadAllocationLimit (StgPtr tso); 50 | void rts_disableThreadAllocationLimit (StgPtr tso); 51 | 52 | #if !defined(mingw32_HOST_OS) 53 | pid_t forkProcess (HsStablePtr *entry); 54 | #else 55 | pid_t forkProcess (HsStablePtr *entry) 56 | GNU_ATTRIBUTE(__noreturn__); 57 | #endif 58 | 59 | HsBool rtsSupportsBoundThreads (void); 60 | 61 | // The number of Capabilities 62 | extern unsigned int n_capabilities; 63 | 64 | // The number of Capabilities that are not disabled 65 | extern nat enabled_capabilities; 66 | 67 | #if !IN_STG_CODE 68 | extern Capability MainCapability; 69 | #endif 70 | 71 | // 72 | // Change the number of capabilities (only supports increasing the 73 | // current value at the moment). 74 | // 75 | extern void setNumCapabilities (nat new_); 76 | 77 | #endif /* RTS_THREADS_H */ 78 | -------------------------------------------------------------------------------- /boot-data/include/rts/Ticky.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * TICKY_TICKY types 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_TICKY_H 15 | #define RTS_TICKY_H 16 | 17 | /* ----------------------------------------------------------------------------- 18 | The StgEntCounter type - needed regardless of TICKY_TICKY 19 | -------------------------------------------------------------------------- */ 20 | 21 | typedef struct _StgEntCounter { 22 | /* Using StgWord for everything, because both the C and asm code 23 | generators make trouble if you try to pack things tighter */ 24 | StgWord registeredp; /* 0 == no, 1 == yes */ 25 | StgInt arity; /* arity (static info) */ 26 | StgInt allocd; /* # allocation of this closure */ 27 | /* (rest of args are in registers) */ 28 | char *str; /* name of the thing */ 29 | char *arg_kinds; /* info about the args types */ 30 | StgInt entry_count; /* Trips to fast entry code */ 31 | StgInt allocs; /* number of allocations by this fun */ 32 | struct _StgEntCounter *link;/* link to chain them all together */ 33 | } StgEntCounter; 34 | 35 | #endif /* RTS_TICKY_H */ 36 | -------------------------------------------------------------------------------- /boot-data/include/rts/Timer.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1995-2009 4 | * 5 | * Interface to the RTS timer signal (uses OS-dependent Ticker.h underneath) 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_TIMER_H 15 | #define RTS_TIMER_H 16 | 17 | void startTimer (void); 18 | void stopTimer (void); 19 | int rtsTimerSignal (void); 20 | 21 | #endif /* RTS_TIMER_H */ 22 | -------------------------------------------------------------------------------- /boot-data/include/rts/Types.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * RTS-specific types. 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_TYPES_H 15 | #define RTS_TYPES_H 16 | 17 | #include 18 | 19 | typedef unsigned int nat; /* at least 32 bits (like int) */ 20 | 21 | // Deprecated; just use StgWord instead 22 | typedef StgWord lnat; 23 | 24 | /* ullong (64|128-bit) type: only include if needed (not ANSI) */ 25 | #if defined(__GNUC__) 26 | #define LL(x) (x##LL) 27 | #else 28 | #define LL(x) (x##L) 29 | #endif 30 | 31 | typedef enum { 32 | rtsFalse = 0, 33 | rtsTrue 34 | } rtsBool; 35 | 36 | typedef struct StgClosure_ StgClosure; 37 | typedef struct StgInfoTable_ StgInfoTable; 38 | typedef struct StgTSO_ StgTSO; 39 | 40 | #endif /* RTS_TYPES_H */ 41 | -------------------------------------------------------------------------------- /boot-data/include/rts/Utils.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * RTS external APIs. This file declares everything that the GHC RTS 6 | * exposes externally. 7 | * 8 | * To understand the structure of the RTS headers, see the wiki: 9 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 10 | * 11 | * ---------------------------------------------------------------------------*/ 12 | 13 | #ifndef RTS_UTILS_H 14 | #define RTS_UTILS_H 15 | 16 | /* Alternate to raise(3) for threaded rts, for BSD-based OSes */ 17 | int genericRaise(int sig); 18 | 19 | #endif /* RTS_UTILS_H */ 20 | -------------------------------------------------------------------------------- /boot-data/include/rts/prof/LDV.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The University of Glasgow, 2009 4 | * 5 | * Lag/Drag/Void profiling. 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef RTS_PROF_LDV_H 15 | #define RTS_PROF_LDV_H 16 | 17 | #ifdef PROFILING 18 | 19 | /* retrieves the LDV word from closure c */ 20 | #define LDVW(c) (((StgClosure *)(c))->header.prof.hp.ldvw) 21 | 22 | /* 23 | * Stores the creation time for closure c. 24 | * This macro is called at the very moment of closure creation. 25 | * 26 | * NOTE: this initializes LDVW(c) to zero, which ensures that there 27 | * is no conflict between retainer profiling and LDV profiling, 28 | * because retainer profiling also expects LDVW(c) to be initialised 29 | * to zero. 30 | */ 31 | 32 | #ifdef CMINUSMINUS 33 | 34 | #else 35 | 36 | #define LDV_RECORD_CREATE(c) \ 37 | LDVW((c)) = ((StgWord)RTS_DEREF(era) << LDV_SHIFT) | LDV_STATE_CREATE 38 | 39 | #endif 40 | 41 | #else /* !PROFILING */ 42 | 43 | #define LDV_RECORD_CREATE(c) /* nothing */ 44 | 45 | #endif /* PROFILING */ 46 | 47 | #endif /* STGLDVPROF_H */ 48 | -------------------------------------------------------------------------------- /boot-data/include/rts/storage/FunTypes.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 2002 4 | * 5 | * Things for functions. 6 | * 7 | * ---------------------------------------------------------------------------*/ 8 | 9 | #ifndef RTS_STORAGE_FUNTYPES_H 10 | #define RTS_STORAGE_FUNTYPES_H 11 | 12 | /* generic - function comes with a small bitmap */ 13 | #define ARG_GEN 0 14 | 15 | /* generic - function comes with a large bitmap */ 16 | #define ARG_GEN_BIG 1 17 | 18 | /* BCO - function is really a BCO */ 19 | #define ARG_BCO 2 20 | 21 | /* 22 | * Specialised function types: bitmaps and calling sequences 23 | * for these functions are pre-generated: see ghc/utils/genapply and 24 | * generated code in ghc/rts/AutoApply.cmm. 25 | * 26 | * NOTE: other places to change if you change this table: 27 | * - utils/genapply/GenApply.hs: stackApplyTypes 28 | * - compiler/codeGen/CgCallConv.lhs: stdPattern 29 | */ 30 | #define ARG_NONE 3 31 | #define ARG_N 4 32 | #define ARG_P 5 33 | #define ARG_F 6 34 | #define ARG_D 7 35 | #define ARG_L 8 36 | #define ARG_V16 9 37 | #define ARG_V32 10 38 | #define ARG_V64 11 39 | #define ARG_NN 12 40 | #define ARG_NP 13 41 | #define ARG_PN 14 42 | #define ARG_PP 15 43 | #define ARG_NNN 16 44 | #define ARG_NNP 17 45 | #define ARG_NPN 18 46 | #define ARG_NPP 19 47 | #define ARG_PNN 20 48 | #define ARG_PNP 21 49 | #define ARG_PPN 22 50 | #define ARG_PPP 23 51 | #define ARG_PPPP 24 52 | #define ARG_PPPPP 25 53 | #define ARG_PPPPPP 26 54 | #define ARG_PPPPPPP 27 55 | #define ARG_PPPPPPPP 28 56 | 57 | #endif /* RTS_STORAGE_FUNTYPES_H */ 58 | -------------------------------------------------------------------------------- /boot-data/include/rts/storage/MBlock.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2008 4 | * 5 | * MegaBlock Allocator interface. 6 | * 7 | * See wiki commentary at 8 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/HeapAlloced 9 | * 10 | * ---------------------------------------------------------------------------*/ 11 | 12 | #ifndef RTS_STORAGE_MBLOCK_H 13 | #define RTS_STORAGE_MBLOCK_H 14 | 15 | extern W_ peak_mblocks_allocated; 16 | extern W_ mblocks_allocated; 17 | 18 | extern void initMBlocks(void); 19 | extern void * getMBlock(void); 20 | extern void * getMBlocks(nat n); 21 | extern void freeMBlocks(void *addr, nat n); 22 | extern void releaseFreeMemory(void); 23 | extern void freeAllMBlocks(void); 24 | 25 | extern void *getFirstMBlock(void **state); 26 | extern void *getNextMBlock(void **state, void *mblock); 27 | 28 | #ifdef THREADED_RTS 29 | // needed for HEAP_ALLOCED below 30 | extern SpinLock gc_alloc_block_sync; 31 | #endif 32 | 33 | #endif /* RTS_STORAGE_MBLOCK_H */ 34 | -------------------------------------------------------------------------------- /boot-data/include/stg/DLL.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2009 4 | * 5 | * Support for Windows DLLs. 6 | * 7 | * Do not #include this file directly: #include "Rts.h" instead. 8 | * 9 | * To understand the structure of the RTS headers, see the wiki: 10 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 11 | * 12 | * ---------------------------------------------------------------------------*/ 13 | 14 | #ifndef __STGDLL_H__ 15 | #define __STGDLL_H__ 1 16 | 17 | #if defined(COMPILING_WINDOWS_DLL) 18 | # if defined(x86_64_HOST_ARCH) 19 | # define DLL_IMPORT_DATA_REF(x) (__imp_##x) 20 | # define DLL_IMPORT_DATA_VARNAME(x) *__imp_##x 21 | # else 22 | # define DLL_IMPORT_DATA_REF(x) (_imp__##x) 23 | # define DLL_IMPORT_DATA_VARNAME(x) *_imp__##x 24 | # endif 25 | # if __GNUC__ && !defined(__declspec) 26 | # define DLLIMPORT 27 | # else 28 | # define DLLIMPORT __declspec(dllimport) 29 | # if defined(x86_64_HOST_ARCH) 30 | # define DLLIMPORT_DATA(x) __imp_##x 31 | # else 32 | # define DLLIMPORT_DATA(x) _imp__##x 33 | # endif 34 | # endif 35 | #else 36 | # define DLL_IMPORT_DATA_REF(x) (&(x)) 37 | # define DLL_IMPORT_DATA_VARNAME(x) x 38 | # define DLLIMPORT 39 | #endif 40 | 41 | /* The view of the ghc/includes/ header files differ ever so 42 | slightly depending on whether the RTS is being compiled 43 | or not - so we're forced to distinguish between two. 44 | [oh, you want details :) : Data symbols defined by the RTS 45 | have to be accessed through an extra level of indirection 46 | when compiling generated .hc code compared to when the RTS 47 | sources are being processed. This is only the case when 48 | using Win32 DLLs. ] 49 | */ 50 | #ifdef COMPILING_RTS 51 | #define DLL_IMPORT DLLIMPORT 52 | #define DLL_IMPORT_RTS 53 | #define DLL_IMPORT_DATA_VAR(x) x 54 | #else 55 | #define DLL_IMPORT 56 | #define DLL_IMPORT_RTS DLLIMPORT 57 | # if defined(COMPILING_WINDOWS_DLL) 58 | # if defined(x86_64_HOST_ARCH) 59 | # define DLL_IMPORT_DATA_VAR(x) __imp_##x 60 | # else 61 | # define DLL_IMPORT_DATA_VAR(x) _imp__##x 62 | # endif 63 | # else 64 | # define DLL_IMPORT_DATA_VAR(x) x 65 | # endif 66 | #endif 67 | 68 | 69 | #ifdef COMPILING_STDLIB 70 | #define DLL_IMPORT_STDLIB 71 | #else 72 | #define DLL_IMPORT_STDLIB DLLIMPORT 73 | #endif 74 | 75 | #endif /* __STGDLL_H__ */ 76 | -------------------------------------------------------------------------------- /boot-data/include/stg/HaskellMachRegs.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2011 4 | * 5 | * Registers used in STG code. Might or might not correspond to 6 | * actual machine registers. 7 | * 8 | * Do not #include this file directly: #include "Rts.h" instead. 9 | * 10 | * To understand the structure of the RTS headers, see the wiki: 11 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 12 | * 13 | * ---------------------------------------------------------------------------*/ 14 | 15 | #ifndef HASKELLMACHREGS_H 16 | #define HASKELLMACHREGS_H 17 | 18 | /* 19 | * Defining NO_REGS causes no global registers to be used. NO_REGS is 20 | * typically defined by GHC, via a command-line option passed to gcc, 21 | * when the -funregisterised flag is given. 22 | * 23 | * NB. When NO_REGS is on, calling & return conventions may be 24 | * different. For example, all function arguments will be passed on 25 | * the stack, and components of an unboxed tuple will be returned on 26 | * the stack rather than in registers. 27 | */ 28 | #ifdef NO_REGS 29 | 30 | #define MACHREGS_NO_REGS 1 31 | 32 | #else 33 | 34 | #define MACHREGS_NO_REGS 0 35 | 36 | #define MACHREGS_i386 i386_TARGET_ARCH 37 | #define MACHREGS_x86_64 x86_64_TARGET_ARCH 38 | #define MACHREGS_powerpc (powerpc_TARGET_ARCH || powerpc64_TARGET_ARCH \ 39 | || powerpc64le_TARGET_ARCH || rs6000_TARGET_ARCH) 40 | #define MACHREGS_sparc sparc_TARGET_ARCH 41 | #define MACHREGS_arm arm_TARGET_ARCH 42 | #define MACHREGS_aarch64 aarch64_TARGET_ARCH 43 | #define MACHREGS_darwin darwin_TARGET_OS 44 | 45 | #endif 46 | 47 | #include "MachRegs.h" 48 | 49 | #endif /* HASKELLMACHREGS_H */ 50 | -------------------------------------------------------------------------------- /boot-data/include/stg/RtsMachRegs.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * 3 | * (c) The GHC Team, 1998-2011 4 | * 5 | * Registers used in STG code. Might or might not correspond to 6 | * actual machine registers. 7 | * 8 | * Do not #include this file directly: #include "Rts.h" instead. 9 | * 10 | * To understand the structure of the RTS headers, see the wiki: 11 | * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes 12 | * 13 | * ---------------------------------------------------------------------------*/ 14 | 15 | #ifndef RTSMACHREGS_H 16 | #define RTSMACHREGS_H 17 | 18 | #ifdef UnregisterisedCompiler 19 | #ifndef NO_REGS 20 | #define NO_REGS 21 | #endif 22 | #endif 23 | 24 | /* 25 | * Defining NO_REGS causes no global registers to be used. NO_REGS is 26 | * typically defined by GHC, via a command-line option passed to gcc, 27 | * when the -funregisterised flag is given. 28 | * 29 | * NB. When NO_REGS is on, calling & return conventions may be 30 | * different. For example, all function arguments will be passed on 31 | * the stack, and components of an unboxed tuple will be returned on 32 | * the stack rather than in registers. 33 | */ 34 | #ifdef NO_REGS 35 | 36 | #define MACHREGS_NO_REGS 1 37 | 38 | #else 39 | 40 | #define MACHREGS_NO_REGS 0 41 | 42 | #define MACHREGS_i386 i386_HOST_ARCH 43 | #define MACHREGS_x86_64 x86_64_HOST_ARCH 44 | #define MACHREGS_powerpc (powerpc_HOST_ARCH || powerpc64_HOST_ARCH \ 45 | || powerpc64le_HOST_ARCH || rs6000_HOST_ARCH) 46 | #define MACHREGS_sparc sparc_HOST_ARCH 47 | #define MACHREGS_arm arm_HOST_ARCH 48 | #define MACHREGS_aarch64 aarch64_HOST_ARCH 49 | #define MACHREGS_darwin darwin_HOST_OS 50 | 51 | #endif 52 | 53 | #include "MachRegs.h" 54 | 55 | #endif /* RTSMACHREGS_H */ 56 | -------------------------------------------------------------------------------- /boot-data/rts.conf: -------------------------------------------------------------------------------- 1 | name: rts 2 | version: 1.0 3 | id: rts 4 | key: rts 5 | license: BSD3 6 | maintainer: glasgow-haskell-users@haskell.org 7 | exposed: True 8 | abi: 9 | trusted: False 10 | library-dirs: /usr/lib/ghc/rts 11 | hs-libraries: HSrts 12 | extra-libraries: 13 | m 14 | -- m rt dl ffi 15 | include-dirs: /usr/lib/ghc/include 16 | --includes: 17 | -- Stg.h 18 | -- ld-options: "-Wl,-u,ZCMain_main" 19 | -- "-Wl,-u,ghczmprim_GHCziTypes_Izh_static_info" 20 | -- "-Wl,-u,ghczmprim_GHCziTypes_Czh_static_info" 21 | -- "-Wl,-u,ghczmprim_GHCziTypes_Fzh_static_info" 22 | -- "-Wl,-u,ghczmprim_GHCziTypes_Dzh_static_info" 23 | -- "-Wl,-u,base_GHCziPtr_Ptr_static_info" 24 | -- "-Wl,-u,ghczmprim_GHCziTypes_Wzh_static_info" 25 | -- "-Wl,-u,base_GHCziInt_I8zh_static_info" 26 | -- "-Wl,-u,base_GHCziInt_I16zh_static_info" 27 | -- "-Wl,-u,base_GHCziInt_I32zh_static_info" 28 | -- "-Wl,-u,base_GHCziInt_I64zh_static_info" 29 | -- "-Wl,-u,base_GHCziWord_W8zh_static_info" 30 | -- "-Wl,-u,base_GHCziWord_W16zh_static_info" 31 | -- "-Wl,-u,base_GHCziWord_W32zh_static_info" 32 | -- "-Wl,-u,base_GHCziWord_W64zh_static_info" 33 | -- "-Wl,-u,base_GHCziStable_StablePtr_static_info" 34 | -- "-Wl,-u,ghczmprim_GHCziTypes_Izh_con_info" 35 | -- "-Wl,-u,ghczmprim_GHCziTypes_Czh_con_info" 36 | -- "-Wl,-u,ghczmprim_GHCziTypes_Fzh_con_info" 37 | -- "-Wl,-u,ghczmprim_GHCziTypes_Dzh_con_info" 38 | -- "-Wl,-u,base_GHCziPtr_Ptr_con_info" 39 | -- "-Wl,-u,base_GHCziPtr_FunPtr_con_info" 40 | -- "-Wl,-u,base_GHCziStable_StablePtr_con_info" 41 | -- "-Wl,-u,ghczmprim_GHCziTypes_False_closure" 42 | -- "-Wl,-u,ghczmprim_GHCziTypes_True_closure" 43 | -- "-Wl,-u,base_GHCziPack_unpackCString_closure" 44 | -- "-Wl,-u,base_GHCziIOziException_stackOverflow_closure" 45 | -- "-Wl,-u,base_GHCziIOziException_heapOverflow_closure" 46 | -- "-Wl,-u,base_ControlziExceptionziBase_nonTermination_closure" 47 | -- "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnMVar_closure" 48 | -- "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnSTM_closure" 49 | -- "-Wl,-u,base_GHCziIOziException_allocationLimitExceeded_closure" 50 | -- "-Wl,-u,base_ControlziExceptionziBase_nestedAtomically_closure" 51 | -- "-Wl,-u,base_GHCziEventziThread_blockedOnBadFD_closure" 52 | -- "-Wl,-u,base_GHCziWeak_runFinalizzerBatch_closure" 53 | -- "-Wl,-u,base_GHCziTopHandler_flushStdHandles_closure" 54 | -- "-Wl,-u,base_GHCziTopHandler_runIO_closure" 55 | -- "-Wl,-u,base_GHCziTopHandler_runNonIO_closure" 56 | -- "-Wl,-u,base_GHCziConcziIO_ensureIOManagerIsRunning_closure" 57 | -- "-Wl,-u,base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure" 58 | -- "-Wl,-u,base_GHCziConcziSync_runSparks_closure" 59 | -- "-Wl,-u,base_GHCziConcziSignal_runHandlersPtr_closure" 60 | -------------------------------------------------------------------------------- /boot-data/settings: -------------------------------------------------------------------------------- 1 | [("GCC extra via C opts", " -fwrapv -fno-builtin"), 2 | ("C compiler command", "/usr/bin/gcc"), 3 | ("C compiler flags", " -fno-stack-protector"), 4 | ("C compiler link flags", ""), 5 | ("C compiler supports -no-pie", "YES"), 6 | ("Haskell CPP command","/usr/bin/gcc"), 7 | ("Haskell CPP flags","-E -undef -traditional"), 8 | ("ld command", "/usr/bin/ld"), 9 | ("ld flags", ""), 10 | ("ld supports compact unwind", "YES"), 11 | ("ld supports build-id", "YES"), 12 | ("ld supports filelist", "NO"), 13 | ("ld is GNU ld", "YES"), 14 | ("ar command", "/usr/bin/ar"), 15 | ("ar flags", "q"), 16 | ("ar supports at file", "YES"), 17 | ("touch command", "touch"), 18 | ("dllwrap command", "/bin/false"), 19 | ("windres command", "/bin/false"), 20 | ("libtool command", "libtool"), 21 | ("perl command", "/usr/bin/perl"), 22 | ("cross compiling", "NO"), 23 | ("target os", "OSLinux"), 24 | ("target arch", "ArchX86_64"), 25 | ("target word size", "8"), 26 | ("target has GNU nonexec stack", "True"), 27 | ("target has .ident directive", "True"), 28 | ("target has subsections via symbols", "False"), 29 | ("Unregisterised", "NO"), 30 | ("LLVM llc command", "llc-4.0"), 31 | ("LLVM opt command", "opt-4.0") 32 | ] 33 | 34 | -------------------------------------------------------------------------------- /fake-rts/rts.ll: -------------------------------------------------------------------------------- 1 | target triple = "x86_64-pc-linux-gnu" 2 | 3 | %hs = type { %hs* (%hs*)* } 4 | %ind = type { %hs* (%hs*)*, %hs* } 5 | %printAndExitClosure = type { %hs* (%hs*)*, i8* } 6 | 7 | ; External declaration of the puts function 8 | declare void @puts(i8* nocapture) nounwind 9 | declare void @exit(i64) nounwind 10 | 11 | define %hs* @rts_printAndExit(%hs* %clos) { 12 | %cast = bitcast %hs* %clos to %printAndExitClosure* 13 | %strP = getelementptr %printAndExitClosure, %printAndExitClosure* %cast, i32 0, i32 1 14 | %str = load i8*, i8** %strP 15 | call void @puts(i8* %str) 16 | call void @exit(i64 1) 17 | unreachable 18 | } 19 | 20 | ; stubs, required by the GHC-generated main() function 21 | @defaultRtsConfig = constant i8* null 22 | @ZCMain_main_closure = constant i8* null 23 | 24 | ; some embedded things 25 | 26 | define %hs* @rts_returnArg(%hs* %clos) { 27 | ret %hs* %clos 28 | } 29 | 30 | define %hs* @rts_indirection(%hs* %clos) { 31 | %cast = bitcast %hs* %clos to %ind* 32 | %indirecteeP = getelementptr %ind, %ind* %cast, i32 0, i32 1 33 | %indirectee = load %hs*, %hs** %indirecteeP 34 | 35 | %enterPtr = getelementptr %hs, %hs* %indirectee, i32 0, i32 0 36 | %enter = load %hs* (%hs*)*, %hs* (%hs*)** %enterPtr 37 | 38 | %ret = call %hs* %enter(%hs* %indirectee) 39 | ret %hs* %ret 40 | } 41 | -------------------------------------------------------------------------------- /ghc-prim/GHC/Debug.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE Trustworthy #-} 2 | {-# LANGUAGE MagicHash, NoImplicitPrelude, UnboxedTuples, UnliftedFFITypes #-} 3 | 4 | module GHC.Debug ( debugLn, debugErrLn ) where 5 | 6 | import GHC.Prim 7 | import GHC.Types 8 | import GHC.Tuple () 9 | 10 | debugLn :: [Char] -> IO () 11 | debugLn xs = IO (\s0 -> 12 | case mkMBA s0 xs of 13 | (# s1, mba #) -> 14 | case c_debugLn mba of 15 | IO f -> f s1) 16 | 17 | debugErrLn :: [Char] -> IO () 18 | debugErrLn xs = IO (\s0 -> 19 | case mkMBA s0 xs of 20 | (# s1, mba #) -> 21 | case c_debugErrLn mba of 22 | IO f -> f s1) 23 | 24 | foreign import ccall unsafe "debugLn" 25 | c_debugLn :: MutableByteArray# RealWorld -> IO () 26 | 27 | foreign import ccall unsafe "debugErrLn" 28 | c_debugErrLn :: MutableByteArray# RealWorld -> IO () 29 | 30 | mkMBA :: State# RealWorld -> [Char] -> 31 | (# State# RealWorld, MutableByteArray# RealWorld #) 32 | mkMBA s0 xs = -- Start with 1 so that we have space to put in a \0 at 33 | -- the end 34 | case len 1# xs of 35 | l -> 36 | case newByteArray# l s0 of 37 | (# s1, mba #) -> 38 | case write mba 0# xs s1 of 39 | s2 -> (# s2, mba #) 40 | where len l [] = l 41 | len l (_ : xs') = len (l +# 1#) xs' 42 | 43 | write mba offset [] s = writeCharArray# mba offset '\0'# s 44 | write mba offset (C# x : xs') s 45 | = case writeCharArray# mba offset x s of 46 | s' -> 47 | write mba (offset +# 1#) xs' s' 48 | 49 | -------------------------------------------------------------------------------- /ghc-prim/LICENSE: -------------------------------------------------------------------------------- 1 | This library (libraries/ghc-prim) is derived from code from several 2 | sources: 3 | 4 | * Code from the GHC project which is largely (c) The University of 5 | Glasgow, and distributable under a BSD-style license (see below), 6 | 7 | * Code from the Haskell 98 Report which is (c) Simon Peyton Jones 8 | and freely redistributable (but see the full license for 9 | restrictions). 10 | 11 | The full text of these licenses is reproduced below. All of the 12 | licenses are BSD-style or compatible. 13 | 14 | ----------------------------------------------------------------------------- 15 | 16 | The Glasgow Haskell Compiler License 17 | 18 | Copyright 2004, The University Court of the University of Glasgow. 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are met: 23 | 24 | - Redistributions of source code must retain the above copyright notice, 25 | this list of conditions and the following disclaimer. 26 | 27 | - Redistributions in binary form must reproduce the above copyright notice, 28 | this list of conditions and the following disclaimer in the documentation 29 | and/or other materials provided with the distribution. 30 | 31 | - Neither name of the University nor the names of its contributors may be 32 | used to endorse or promote products derived from this software without 33 | specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF 36 | GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 37 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 38 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 39 | UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE 40 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 41 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 42 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 43 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 44 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 45 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 46 | DAMAGE. 47 | 48 | ----------------------------------------------------------------------------- 49 | 50 | Code derived from the document "Report on the Programming Language 51 | Haskell 98", is distributed under the following license: 52 | 53 | Copyright (c) 2002 Simon Peyton Jones 54 | 55 | The authors intend this Report to belong to the entire Haskell 56 | community, and so we grant permission to copy and distribute it for 57 | any purpose, provided that it is reproduced in its entirety, 58 | including this Notice. Modified versions of this Report may also be 59 | copied and distributed for any purpose, provided that the modified 60 | version is clearly presented as such, and that it does not claim to 61 | be a definition of the Haskell 98 Language. 62 | 63 | -------------------------------------------------------------------------------- /ghc-prim/cbits/bswap.c: -------------------------------------------------------------------------------- 1 | #include "Rts.h" 2 | 3 | extern StgWord16 hs_bswap16(StgWord16 x); 4 | StgWord16 5 | hs_bswap16(StgWord16 x) 6 | { 7 | return ((x >> 8) | (x << 8)); 8 | } 9 | 10 | extern StgWord32 hs_bswap32(StgWord32 x); 11 | StgWord32 12 | hs_bswap32(StgWord32 x) 13 | { 14 | return ((x >> 24) | ((x >> 8) & 0xff00) | 15 | (x << 24) | ((x & 0xff00) << 8)); 16 | } 17 | 18 | extern StgWord64 hs_bswap64(StgWord64 x); 19 | StgWord64 20 | hs_bswap64(StgWord64 x) 21 | { 22 | return ( (x >> 56) | (x << 56) 23 | | ((x >> 40) & 0xff00) | ((x & 0xff00) << 40) 24 | | ((x >> 24) & 0xff0000) | ((x & 0xff0000) << 24) 25 | | ((x >> 8) & 0xff000000) | ((x & 0xff000000) << 8) 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /ghc-prim/cbits/clz.c: -------------------------------------------------------------------------------- 1 | #include "MachDeps.h" 2 | #include "Rts.h" 3 | #include 4 | 5 | // Fall-back implementations for count-leading-zeros primop 6 | // 7 | // __builtin_clz*() is supported by GCC and Clang 8 | 9 | #if SIZEOF_UNSIGNED_INT == 4 10 | StgWord 11 | hs_clz8(StgWord x) 12 | { 13 | return (uint8_t)x ? __builtin_clz((uint8_t)x)-24 : 8; 14 | } 15 | 16 | StgWord 17 | hs_clz16(StgWord x) 18 | { 19 | return (uint16_t)x ? __builtin_clz((uint16_t)x)-16 : 16; 20 | } 21 | 22 | StgWord 23 | hs_clz32(StgWord x) 24 | { 25 | return (uint32_t)x ? __builtin_clz((uint32_t)x) : 32; 26 | } 27 | #else 28 | # error no suitable __builtin_clz() found 29 | #endif 30 | 31 | StgWord 32 | hs_clz64(StgWord64 x) 33 | { 34 | #if SIZEOF_UNSIGNED_LONG == 8 35 | return x ? __builtin_clzl(x) : 64; 36 | #elif SIZEOF_UNSIGNED_LONG_LONG == 8 37 | return x ? __builtin_clzll(x) : 64; 38 | #else 39 | # error no suitable __builtin_clz() found 40 | #endif 41 | } 42 | -------------------------------------------------------------------------------- /ghc-prim/cbits/ctz.c: -------------------------------------------------------------------------------- 1 | #include "MachDeps.h" 2 | #include "Rts.h" 3 | #include 4 | 5 | // Fall-back implementations for count-trailing-zeros primop 6 | // 7 | // __builtin_ctz*() is supported by GCC and Clang 8 | 9 | #if SIZEOF_UNSIGNED_INT == 4 10 | StgWord 11 | hs_ctz8(StgWord x) 12 | { 13 | return (uint8_t)x ? __builtin_ctz(x) : 8; 14 | } 15 | 16 | StgWord 17 | hs_ctz16(StgWord x) 18 | { 19 | return (uint16_t)x ? __builtin_ctz(x) : 16; 20 | } 21 | 22 | StgWord 23 | hs_ctz32(StgWord x) 24 | { 25 | return (uint32_t)x ? __builtin_ctz(x) : 32; 26 | } 27 | #else 28 | # error no suitable __builtin_ctz() found 29 | #endif 30 | 31 | StgWord 32 | hs_ctz64(StgWord64 x) 33 | { 34 | #if defined(__GNUC__) && (defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH)) 35 | /* On Linux/i386, the 64bit `__builtin_ctzll()` instrinsic doesn't 36 | get inlined by GCC but rather a short `__ctzdi2` runtime function 37 | is inserted when needed into compiled object files. 38 | 39 | This workaround forces GCC on 32bit x86 to to express `hs_ctz64` in 40 | terms of the 32bit `__builtin_ctz()` (this is no loss, as there's no 41 | 64bit BSF instruction on i686 anyway) and thus avoid the problematic 42 | out-of-line runtime function. 43 | */ 44 | 45 | if (!x) return 64; 46 | 47 | return ((uint32_t)x ? __builtin_ctz((uint32_t)x) 48 | : (__builtin_ctz(x >> 32) + 32)); 49 | 50 | #elif SIZEOF_UNSIGNED_LONG == 8 51 | return x ? __builtin_ctzl(x) : 64; 52 | #elif SIZEOF_UNSIGNED_LONG_LONG == 8 53 | return x ? __builtin_ctzll(x) : 64; 54 | #else 55 | # error no suitable __builtin_ctz() found 56 | #endif 57 | } 58 | -------------------------------------------------------------------------------- /ghc-prim/cbits/debug.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void debugLn(char *s) { 5 | printf("%s\n", s); 6 | } 7 | 8 | void debugErrLn(char *s) { 9 | fprintf(stderr, "%s\n", s); 10 | } 11 | -------------------------------------------------------------------------------- /ghc-prim/cbits/popcnt.c: -------------------------------------------------------------------------------- 1 | #include "Rts.h" 2 | #include "MachDeps.h" 3 | 4 | static const unsigned char popcount_tab[] = 5 | { 6 | 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 7 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 8 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 9 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 10 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 11 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 12 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 13 | 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8, 14 | }; 15 | 16 | extern StgWord hs_popcnt8(StgWord x); 17 | StgWord 18 | hs_popcnt8(StgWord x) 19 | { 20 | return popcount_tab[(unsigned char)x]; 21 | } 22 | 23 | extern StgWord hs_popcnt16(StgWord x); 24 | StgWord 25 | hs_popcnt16(StgWord x) 26 | { 27 | return popcount_tab[(unsigned char)x] + 28 | popcount_tab[(unsigned char)(x >> 8)]; 29 | } 30 | 31 | extern StgWord hs_popcnt32(StgWord x); 32 | StgWord 33 | hs_popcnt32(StgWord x) 34 | { 35 | return popcount_tab[(unsigned char)x] + 36 | popcount_tab[(unsigned char)(x >> 8)] + 37 | popcount_tab[(unsigned char)(x >> 16)] + 38 | popcount_tab[(unsigned char)(x >> 24)]; 39 | } 40 | 41 | extern StgWord hs_popcnt64(StgWord64 x); 42 | StgWord 43 | hs_popcnt64(StgWord64 x) 44 | { 45 | return popcount_tab[(unsigned char)x] + 46 | popcount_tab[(unsigned char)(x >> 8)] + 47 | popcount_tab[(unsigned char)(x >> 16)] + 48 | popcount_tab[(unsigned char)(x >> 24)] + 49 | popcount_tab[(unsigned char)(x >> 32)] + 50 | popcount_tab[(unsigned char)(x >> 40)] + 51 | popcount_tab[(unsigned char)(x >> 48)] + 52 | popcount_tab[(unsigned char)(x >> 56)]; 53 | } 54 | 55 | #if WORD_SIZE_IN_BITS == 32 56 | 57 | extern StgWord hs_popcnt(StgWord x); 58 | StgWord 59 | hs_popcnt(StgWord x) 60 | { 61 | return popcount_tab[(unsigned char)x] + 62 | popcount_tab[(unsigned char)(x >> 8)] + 63 | popcount_tab[(unsigned char)(x >> 16)] + 64 | popcount_tab[(unsigned char)(x >> 24)]; 65 | } 66 | 67 | #elif WORD_SIZE_IN_BITS == 64 68 | 69 | extern StgWord hs_popcnt(StgWord x); 70 | StgWord 71 | hs_popcnt(StgWord x) 72 | { 73 | return popcount_tab[(unsigned char)x] + 74 | popcount_tab[(unsigned char)(x >> 8)] + 75 | popcount_tab[(unsigned char)(x >> 16)] + 76 | popcount_tab[(unsigned char)(x >> 24)] + 77 | popcount_tab[(unsigned char)(x >> 32)] + 78 | popcount_tab[(unsigned char)(x >> 40)] + 79 | popcount_tab[(unsigned char)(x >> 48)] + 80 | popcount_tab[(unsigned char)(x >> 56)]; 81 | } 82 | 83 | #else 84 | 85 | #error Unknown machine word size 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /ghc-prim/cbits/word2float.c: -------------------------------------------------------------------------------- 1 | #include "Rts.h" 2 | 3 | extern StgFloat hs_word2float32(StgWord x); 4 | StgFloat 5 | hs_word2float32(StgWord x) 6 | { 7 | return x; 8 | } 9 | 10 | extern StgDouble hs_word2float64(StgWord x); 11 | StgDouble 12 | hs_word2float64(StgWord x) 13 | { 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /ghc-prim/ghc-prim.cabal: -------------------------------------------------------------------------------- 1 | name: ghc-prim 2 | version: 0.5.0.0 3 | license: BSD3 4 | license-file: LICENSE 5 | category: GHC 6 | maintainer: libraries@haskell.org 7 | bug-reports: http://ghc.haskell.org/trac/ghc/newticket?component=libraries%20%28other%29&keywords=ghc-prim 8 | synopsis: GHC primitives 9 | cabal-version: >=1.10 10 | build-type: Custom 11 | description: 12 | This package contains the primitive types and operations supplied by GHC. 13 | 14 | source-repository head 15 | type: git 16 | location: http://git.haskell.org/ghc.git 17 | subdir: libraries/ghc-prim 18 | 19 | flag include-ghc-prim 20 | Description: Include GHC.Prim in exposed-modules 21 | default: False 22 | 23 | custom-setup 24 | setup-depends: base >= 4 && < 5, Cabal >= 1.23 25 | 26 | Library 27 | default-language: Haskell2010 28 | other-extensions: 29 | BangPatterns 30 | CPP 31 | DeriveGeneric 32 | MagicHash 33 | MultiParamTypeClasses 34 | NoImplicitPrelude 35 | StandaloneDeriving 36 | Trustworthy 37 | TypeFamilies 38 | UnboxedTuples 39 | UnliftedFFITypes 40 | 41 | build-depends: rts == 1.0.* 42 | 43 | exposed-modules: 44 | GHC.CString 45 | GHC.Classes 46 | GHC.Debug 47 | GHC.IntWord64 48 | GHC.Magic 49 | -- GHC.PrimopWrappers 50 | GHC.Tuple 51 | GHC.Types 52 | 53 | -- OS Specific 54 | if os(windows) 55 | -- Windows requires some extra libraries for linking because the RTS 56 | -- is no longer re-exporting them (see #11223) 57 | -- msvcrt: standard C library. The RTS will automatically include this, 58 | -- but is added for completeness. 59 | -- mingwex: provides C99 compatibility. libm is a stub on MingW. 60 | -- mingw32: Unfortunately required because of a resource leak between 61 | -- mingwex and mingw32. the __math_err symbol is defined in 62 | -- mingw32 which is required by mingwex. 63 | -- user32: provides access to apis to modify user components (UI etc) 64 | -- on Windows. Required because of mingw32. 65 | extra-libraries: user32, mingw32, mingwex 66 | 67 | if flag(include-ghc-prim) 68 | exposed-modules: GHC.Prim 69 | 70 | -- c-sources: 71 | -- cbits/atomic.c 72 | -- cbits/bswap.c 73 | -- cbits/clz.c 74 | -- cbits/ctz.c 75 | -- cbits/debug.c 76 | -- cbits/longlong.c 77 | -- cbits/popcnt.c 78 | -- cbits/word2float.c 79 | 80 | -- We need to set the unit ID to ghc-prim (without a version number) 81 | -- as it's magic. 82 | ghc-options: -this-unit-id ghc-prim 83 | -------------------------------------------------------------------------------- /integer-gmp/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Herbert Valerio Riedel 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Herbert Valerio Riedel nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /integer-gmp/Setup.hs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import Distribution.Simple 4 | 5 | main :: IO () 6 | main = defaultMainWithHooks autoconfUserHooks 7 | -------------------------------------------------------------------------------- /integer-gmp/aclocal.m4: -------------------------------------------------------------------------------- 1 | 2 | dnl-------------------------------------------------------------------- 3 | dnl * Check whether this machine has gmp/gmp3 installed 4 | dnl-------------------------------------------------------------------- 5 | 6 | AC_DEFUN([LOOK_FOR_GMP_LIB],[ 7 | if test "$HaveFrameworkGMP" = "NO" 8 | then 9 | AC_CHECK_LIB([gmp], [__gmpz_powm], 10 | [HaveLibGmp=YES; GMP_LIBS=gmp]) 11 | if test "$HaveLibGmp" = "NO" 12 | then 13 | AC_CHECK_LIB([gmp3], [__gmpz_powm], 14 | [HaveLibGmp=YES; GMP_LIBS=gmp3]) 15 | fi 16 | if test "$HaveLibGmp" = "YES" 17 | then 18 | AC_CHECK_LIB([$GMP_LIBS], [__gmpz_powm_sec], 19 | [HaveSecurePowm=1]) 20 | fi 21 | fi 22 | ]) 23 | 24 | dnl-------------------------------------------------------------------- 25 | dnl * Mac OS X only: check for GMP.framework 26 | dnl-------------------------------------------------------------------- 27 | 28 | AC_DEFUN([LOOK_FOR_GMP_FRAMEWORK],[ 29 | if test "$HaveLibGmp" = "NO" 30 | then 31 | case $target_os in 32 | darwin*) 33 | AC_MSG_CHECKING([for GMP.framework]) 34 | save_libs="$LIBS" 35 | LIBS="-framework GMP" 36 | AC_TRY_LINK_FUNC(__gmpz_powm_sec, 37 | [HaveFrameworkGMP=YES; GMP_FRAMEWORK=GMP]) 38 | LIBS="$save_libs" 39 | AC_MSG_RESULT([$HaveFrameworkGMP]) 40 | ;; 41 | esac 42 | fi 43 | ]) 44 | 45 | -------------------------------------------------------------------------------- /integer-gmp/changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog for [`integer-gmp` package](http://hackage.haskell.org/package/integer-gmp) 2 | 3 | ## 1.0.0.1 *Feb 2016* 4 | 5 | * Bundled with GHC 8.0.1 6 | 7 | * Optimise `bitBigNat`/`bigInteger` 8 | 9 | * Fix minor issue in `eqBigNatWord#` 10 | 11 | * Various minor optimisations 12 | 13 | ## 1.0.0.0 *Mar 2015* 14 | 15 | * Bundled with GHC 7.10.1 16 | 17 | * Complete rewrite of `integer-gmp`. For more details, see 18 | https://ghc.haskell.org/trac/ghc/wiki/Design/IntegerGmp2 19 | 20 | ## 0.5.1.0 *Feb 2014* 21 | 22 | * Bundled with GHC 7.8.1 23 | 24 | * Improved Haddock documentation 25 | 26 | * New [PrimBool](https://ghc.haskell.org/trac/ghc/wiki/PrimBool) 27 | versions of comparison predicates in `GHC.Integer`: 28 | 29 | eqInteger# :: Integer -> Integer -> Int# 30 | geInteger# :: Integer -> Integer -> Int# 31 | gtInteger# :: Integer -> Integer -> Int# 32 | leInteger# :: Integer -> Integer -> Int# 33 | ltInteger# :: Integer -> Integer -> Int# 34 | neqInteger# :: Integer -> Integer -> Int# 35 | 36 | * New `GHC.Integer.testBitInteger` primitive for use with `Data.Bits` 37 | 38 | * Reduce short-lived heap allocation and try to demote `J#` back 39 | to `S#` more aggressively. See also 40 | [#8647](https://ghc.haskell.org/trac/ghc/ticket/8647) 41 | for more details. 42 | 43 | * New GMP-specific binary (de)serialization primitives added to 44 | `GHC.Integer.GMP.Internals`: 45 | 46 | importIntegerFromByteArray 47 | importIntegerFromAddr 48 | exportIntegerToAddr 49 | exportIntegerToMutableByteArray 50 | sizeInBaseInteger 51 | 52 | * New GMP-implemented number-theoretic operations added to 53 | `GHC.Integer.GMP.Internals`: 54 | 55 | gcdExtInteger 56 | nextPrimeInteger 57 | testPrimeInteger 58 | powInteger 59 | powModInteger 60 | powModSecInteger 61 | recipModInteger 62 | -------------------------------------------------------------------------------- /integer-gmp/gmp/config.mk.in: -------------------------------------------------------------------------------- 1 | ifeq "$(HaveLibGmp)" "" 2 | HaveLibGmp = @HaveLibGmp@ 3 | endif 4 | 5 | ifeq "$(HaveFrameworkGMP)" "" 6 | HaveFrameworkGMP = @HaveFrameworkGMP@ 7 | endif 8 | 9 | GMP_INCLUDE_DIRS = @GMP_INCLUDE_DIRS@ 10 | GMP_LIB_DIRS = @GMP_LIB_DIRS@ 11 | 12 | -------------------------------------------------------------------------------- /integer-gmp/gmp/ghc-gmp.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /integer-gmp/gmp/gmpsrc.patch: -------------------------------------------------------------------------------- 1 | --- gmp-5.0.3/configure 2012-02-03 16:52:49.000000000 +0100 2 | +++ gmpbuild/configure 2014-11-07 23:46:33.629758238 +0100 3 | @@ -3937,8 +3937,8 @@ 4 | # 5 | cclist="gcc cc" 6 | 7 | -gcc_cflags="-O2 -pedantic" 8 | -gcc_64_cflags="-O2 -pedantic" 9 | +gcc_cflags="-O2 -pedantic -fPIC" 10 | +gcc_64_cflags="-O2 -pedantic -fPIC" 11 | cc_cflags="-O" 12 | cc_64_cflags="-O" 13 | 14 | --- gmp-5.0.3/memory.c 2012-02-03 16:52:49.000000000 +0100 15 | +++ gmpbuild/memory.c 2014-11-07 23:54:20.734523242 +0100 16 | @@ -24,21 +24,10 @@ 17 | #include "gmp-impl.h" 18 | 19 | 20 | -/* Patched for GHC: */ 21 | -void * stgAllocForGMP (size_t size_in_bytes); 22 | -void * stgReallocForGMP (void *ptr, size_t old_size, size_t new_size); 23 | -void stgDeallocForGMP (void *ptr, size_t size); 24 | - 25 | -void * (*__gmp_allocate_func) __GMP_PROTO ((size_t)) = stgAllocForGMP; 26 | -void * (*__gmp_reallocate_func) __GMP_PROTO ((void *, size_t, size_t)) 27 | - = stgReallocForGMP; 28 | -void (*__gmp_free_func) __GMP_PROTO ((void *, size_t)) = stgDeallocForGMP; 29 | -/* 30 | void * (*__gmp_allocate_func) __GMP_PROTO ((size_t)) = __gmp_default_allocate; 31 | void * (*__gmp_reallocate_func) __GMP_PROTO ((void *, size_t, size_t)) 32 | = __gmp_default_reallocate; 33 | void (*__gmp_free_func) __GMP_PROTO ((void *, size_t)) = __gmp_default_free; 34 | -*/ 35 | 36 | 37 | /* Default allocation functions. In case of failure to allocate/reallocate 38 | -------------------------------------------------------------------------------- /integer-gmp/gmp/ln: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exit 1 3 | 4 | -------------------------------------------------------------------------------- /integer-gmp/gmp/tarball/README: -------------------------------------------------------------------------------- 1 | 2 | Download linked from http://gmplib.org/ 3 | 4 | Untar. 5 | Remove doc/ directory. 6 | Apply patch. 7 | Re-tar. 8 | 9 | -------------------------------------------------------------------------------- /integer-gmp/gmp/tarball/gmp-5.0.3-nodoc-patched.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomeata/veggies/7a910dd91b2b7443dd0ca983bc0eade7d969b054/integer-gmp/gmp/tarball/gmp-5.0.3-nodoc-patched.tar.bz2 -------------------------------------------------------------------------------- /integer-gmp/gmp/tarball/gmp-5.0.4.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomeata/veggies/7a910dd91b2b7443dd0ca983bc0eade7d969b054/integer-gmp/gmp/tarball/gmp-5.0.4.patch -------------------------------------------------------------------------------- /integer-gmp/include/HsIntegerGmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _HS_INTEGER_GMP_H_ 2 | #define _HS_INTEGER_GMP_H_ 3 | 4 | /* Whether GMP is embedded into integer-gmp */ 5 | #define GHC_GMP_INTREE 0 6 | 7 | /* The following values denote the GMP version used during GHC build-time */ 8 | #define GHC_GMP_VERSION_MJ 6 9 | #define GHC_GMP_VERSION_MI 1 10 | #define GHC_GMP_VERSION_PL 2 11 | #define GHC_GMP_VERSION \ 12 | (6 * 10000 + 1 * 100 + 2) 13 | 14 | #endif /* _HS_INTEGER_GMP_H_ */ 15 | -------------------------------------------------------------------------------- /integer-gmp/include/HsIntegerGmp.h.in: -------------------------------------------------------------------------------- 1 | #ifndef _HS_INTEGER_GMP_H_ 2 | #define _HS_INTEGER_GMP_H_ 3 | 4 | /* Whether GMP is embedded into integer-gmp */ 5 | #define GHC_GMP_INTREE @UseIntreeGmp@ 6 | 7 | /* The following values denote the GMP version used during GHC build-time */ 8 | #define GHC_GMP_VERSION_MJ @GhcGmpVerMj@ 9 | #define GHC_GMP_VERSION_MI @GhcGmpVerMi@ 10 | #define GHC_GMP_VERSION_PL @GhcGmpVerPl@ 11 | #define GHC_GMP_VERSION \ 12 | (@GhcGmpVerMj@ * 10000 + @GhcGmpVerMi@ * 100 + @GhcGmpVerPl@) 13 | 14 | #endif /* _HS_INTEGER_GMP_H_ */ 15 | -------------------------------------------------------------------------------- /integer-gmp/include/ghc-gmp.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /integer-gmp/integer-gmp.buildinfo.in: -------------------------------------------------------------------------------- 1 | include-dirs: @GMP_INCLUDE_DIRS@ 2 | extra-lib-dirs: @GMP_LIB_DIRS@ 3 | extra-libraries: @GMP_LIBS@ 4 | frameworks: @GMP_FRAMEWORK@ 5 | install-includes: HsIntegerGmp.h ghc-gmp.h 6 | -------------------------------------------------------------------------------- /integer-gmp/integer-gmp.cabal: -------------------------------------------------------------------------------- 1 | name: integer-gmp 2 | version: 1.0.0.1 3 | synopsis: Integer library based on GMP 4 | license: BSD3 5 | license-file: LICENSE 6 | author: Herbert Valerio Riedel 7 | maintainer: hvr@gnu.org 8 | category: Numeric, Algebra 9 | build-type: Configure 10 | cabal-version: >=1.10 11 | 12 | extra-source-files: 13 | aclocal.m4 14 | cbits/wrappers.c 15 | changelog.md 16 | config.guess 17 | config.sub 18 | configure 19 | configure.ac 20 | gmp/config.mk.in 21 | include/HsIntegerGmp.h.in 22 | install-sh 23 | integer-gmp.buildinfo.in 24 | 25 | extra-tmp-files: 26 | autom4te.cache 27 | config.log 28 | config.status 29 | gmp/config.mk 30 | integer-gmp.buildinfo 31 | include/HsIntegerGmp.h 32 | 33 | library 34 | default-language: Haskell2010 35 | other-extensions: 36 | BangPatterns 37 | CApiFFI 38 | CPP 39 | DeriveDataTypeable 40 | ExplicitForAll 41 | GHCForeignImportPrim 42 | MagicHash 43 | NegativeLiterals 44 | NoImplicitPrelude 45 | RebindableSyntax 46 | StandaloneDeriving 47 | UnboxedTuples 48 | UnliftedFFITypes 49 | build-depends: ghc-prim 50 | hs-source-dirs: src/ 51 | ghc-options: -this-unit-id integer-gmp -Wall 52 | cc-options: -std=c99 -Wall 53 | 54 | include-dirs: include 55 | c-sources: 56 | cbits/wrappers.c 57 | 58 | exposed-modules: 59 | GHC.Integer 60 | GHC.Integer.Logarithms 61 | GHC.Integer.Logarithms.Internals 62 | 63 | GHC.Integer.GMP.Internals 64 | 65 | other-modules: 66 | GHC.Integer.Type 67 | -------------------------------------------------------------------------------- /integer-gmp/src/GHC/Integer.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE MagicHash #-} 3 | {-# LANGUAGE NoImplicitPrelude #-} 4 | 5 | #include "MachDeps.h" 6 | 7 | -- | 8 | -- Module : GHC.Integer.Type 9 | -- Copyright : (c) Herbert Valerio Riedel 2014 10 | -- License : BSD3 11 | -- 12 | -- Maintainer : ghc-devs@haskell.org 13 | -- Stability : provisional 14 | -- Portability : non-portable (GHC Extensions) 15 | -- 16 | -- The 'Integer' type. 17 | -- 18 | -- This module exposes the /portable/ 'Integer' API. See 19 | -- "GHC.Integer.GMP.Internals" for the @integer-gmp@-specific internal 20 | -- representation of 'Integer' as well as optimized GMP-specific 21 | -- operations. 22 | 23 | module GHC.Integer ( 24 | Integer, 25 | 26 | -- * Construct 'Integer's 27 | mkInteger, smallInteger, wordToInteger, 28 | #if WORD_SIZE_IN_BITS < 64 29 | word64ToInteger, int64ToInteger, 30 | #endif 31 | -- * Conversion to other integral types 32 | integerToWord, integerToInt, 33 | #if WORD_SIZE_IN_BITS < 64 34 | integerToWord64, integerToInt64, 35 | #endif 36 | 37 | -- * Helpers for 'RealFloat' type-class operations 38 | encodeFloatInteger, floatFromInteger, 39 | encodeDoubleInteger, decodeDoubleInteger, doubleFromInteger, 40 | 41 | -- * Arithmetic operations 42 | plusInteger, minusInteger, timesInteger, negateInteger, 43 | absInteger, signumInteger, 44 | 45 | divModInteger, divInteger, modInteger, 46 | quotRemInteger, quotInteger, remInteger, 47 | 48 | -- * Comparison predicates 49 | eqInteger, neqInteger, leInteger, gtInteger, ltInteger, geInteger, 50 | compareInteger, 51 | 52 | -- ** 'Int#'-boolean valued versions of comparision predicates 53 | -- 54 | -- | These operations return @0#@ and @1#@ instead of 'False' and 55 | -- 'True' respectively. See 56 | -- 57 | -- for more details 58 | eqInteger#, neqInteger#, leInteger#, gtInteger#, ltInteger#, geInteger#, 59 | 60 | 61 | -- * Bit-operations 62 | andInteger, orInteger, xorInteger, 63 | 64 | complementInteger, 65 | shiftLInteger, shiftRInteger, testBitInteger, 66 | 67 | -- * Hashing 68 | hashInteger, 69 | ) where 70 | 71 | import GHC.Integer.Type 72 | 73 | default () 74 | -------------------------------------------------------------------------------- /integer-gmp/src/GHC/Integer/Logarithms.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | {-# LANGUAGE MagicHash #-} 3 | {-# LANGUAGE UnboxedTuples #-} 4 | {-# LANGUAGE UnliftedFFITypes #-} 5 | {-# LANGUAGE CPP #-} 6 | 7 | module GHC.Integer.Logarithms 8 | ( wordLog2# 9 | , integerLog2# 10 | , integerLogBase# 11 | ) where 12 | 13 | #include "MachDeps.h" 14 | 15 | #if WORD_SIZE_IN_BITS == 32 16 | # define LD_WORD_SIZE_IN_BITS 5 17 | #elif WORD_SIZE_IN_BITS == 64 18 | # define LD_WORD_SIZE_IN_BITS 6 19 | #else 20 | # error unsupported WORD_SIZE_IN_BITS 21 | #endif 22 | 23 | import GHC.Integer.Type 24 | 25 | import GHC.Prim 26 | 27 | default () 28 | 29 | -- | Calculate the integer logarithm for an arbitrary base. 30 | -- 31 | -- The base must be greater than @1@, the second argument, the number 32 | -- whose logarithm is sought, shall be positive, otherwise the 33 | -- result is meaningless. 34 | -- 35 | -- The following property holds 36 | -- 37 | -- @base ^ 'integerLogBase#' base m <= m < base ^('integerLogBase#' base m + 1)@ 38 | -- 39 | -- for @base > 1@ and @m > 0@. 40 | -- 41 | -- Note: Internally uses 'integerLog2#' for base 2 42 | integerLogBase# :: Integer -> Integer -> Int# 43 | integerLogBase# (S# 2#) m = integerLog2# m 44 | integerLogBase# b m = e' 45 | where 46 | (# _, e' #) = go b 47 | 48 | go pw | m `ltInteger` pw = (# m, 0# #) 49 | go pw = case go (sqrInteger pw) of 50 | (# q, e #) | q `ltInteger` pw -> (# q, 2# *# e #) 51 | (# q, e #) -> (# q `quotInteger` pw, 2# *# e +# 1# #) 52 | 53 | 54 | -- | Calculate the integer base 2 logarithm of an 'Integer'. The 55 | -- calculation is more efficient than for the general case, on 56 | -- platforms with 32- or 64-bit words much more efficient. 57 | -- 58 | -- The argument must be strictly positive, that condition is /not/ checked. 59 | integerLog2# :: Integer -> Int# 60 | integerLog2# (S# i#) = wordLog2# (int2Word# i#) 61 | integerLog2# (Jn# _) = -1# 62 | integerLog2# (Jp# bn) = go (s -# 1#) 63 | where 64 | s = sizeofBigNat# bn 65 | go i = case indexBigNat# bn i of 66 | 0## -> go (i -# 1#) 67 | w -> wordLog2# w +# (uncheckedIShiftL# i LD_WORD_SIZE_IN_BITS#) 68 | 69 | -- | Compute base-2 log of 'Word#' 70 | -- 71 | -- This is internally implemented as count-leading-zeros machine instruction. 72 | wordLog2# :: Word# -> Int# 73 | wordLog2# w# = (WORD_SIZE_IN_BITS# -# 1#) -# (word2Int# (clz# w#)) 74 | -------------------------------------------------------------------------------- /test/Empty.hs: -------------------------------------------------------------------------------- 1 | module Empty where 2 | -------------------------------------------------------------------------------- /test/Factorial.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE MagicHash #-} 2 | {-# LANGUAGE BangPatterns #-} 3 | {-# LANGUAGE UnboxedTuples #-} 4 | -- module Factorial where 5 | 6 | data Nat = Z | S Nat deriving Show 7 | 8 | pred Z = Z 9 | pred (S a) = a 10 | {-# NOINLINE pred #-} 11 | 12 | plus Z b = b 13 | plus (S a) b = S (plus a b) 14 | {-# NOINLINE plus #-} 15 | 16 | mul Z b = Z 17 | mul (S a) b = plus b (mul a b) 18 | {-# NOINLINE mul #-} 19 | 20 | fac Z = S Z 21 | fac (S n) = S n `mul` fac n 22 | {-# NOINLINE fac #-} 23 | 24 | sub :: Nat -> Nat -> Nat 25 | sub Z _ = Z 26 | sub (S n) Z = n 27 | sub (S n) (S m) = sub n m 28 | {-# NOINLINE sub #-} 29 | 30 | eq :: Nat -> Nat -> Nat 31 | eq Z Z = S Z 32 | eq Z _ = Z 33 | eq (S n) Z = Z 34 | eq (S n) (S m) = eq n m 35 | {-# NOINLINE eq #-} 36 | 37 | natToWord :: Nat -> Word 38 | natToWord Z = 0 39 | natToWord (S n) = 1 + natToWord n 40 | {-# NOINLINE natToWord #-} 41 | 42 | intToNat :: Word -> Nat 43 | intToNat 0 = Z 44 | intToNat n = S (intToNat (n-1)) 45 | {-# NOINLINE intToNat #-} 46 | 47 | fac' :: Word -> Word 48 | fac' = go 49 | where 50 | go 0 = 1 51 | go n = n * fac' (n-1) 52 | 53 | genFac :: (Word -> Word -> Word) -> Word -> Word 54 | genFac foo = go 55 | where 56 | go 0 = 1 57 | go n = foo n (fac' (n-1)) 58 | {-# NOINLINE genFac #-} 59 | 60 | returnLambda1 :: Word -> (Word -> Word -> Word) 61 | returnLambda1 n x | fac' n == 0 = (x*) 62 | returnLambda1 n x = \y -> x * n * y 63 | {-# NOINLINE returnLambda1 #-} 64 | 65 | returnLambda2 :: Word -> (Word -> Word -> Word) 66 | returnLambda2 n | fac' n == 0 = (*) 67 | returnLambda2 n = \x y -> x * n * y 68 | {-# NOINLINE returnLambda2 #-} 69 | 70 | 71 | main :: IO () 72 | main = do 73 | let n = 8 74 | let x = intToNat (genFac (returnLambda2 1) n) 75 | let y = fac (intToNat n) 76 | print (natToWord x) 77 | print (natToWord y) 78 | -------------------------------------------------------------------------------- /test/Test.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoImplicitPrelude #-} 2 | {-# LANGUAGE MagicHash #-} 3 | {-# LANGUAGE UnboxedTuples #-} 4 | module Main where 5 | import GHC.Types 6 | 7 | data Unit = Unit 8 | 9 | 10 | return :: a -> IO a 11 | return x = IO (\s -> (# s, x #)) 12 | 13 | main :: IO () 14 | main = return () 15 | -------------------------------------------------------------------------------- /test/Thunks.hs: -------------------------------------------------------------------------------- 1 | import Debug.Trace 2 | 3 | foo :: Int 4 | foo = trace "static thunk evaled" $ 1+1 5 | 6 | 7 | bar True thunk = thunk 8 | bar False _ = 1 9 | {-# NOINLINE bar #-} 10 | 11 | test i = do 12 | let n = trace "dynamic thunk evaled" $ bar True i 13 | print $ bar True foo 14 | print $ bar True foo 15 | print $ bar True foo 16 | print $ bar True n 17 | print $ bar True n 18 | print $ bar True n 19 | {-# NOINLINE test #-} 20 | 21 | 22 | main = test 1 23 | -------------------------------------------------------------------------------- /vellvm-ast-pp/Ast2Assembly.hs: -------------------------------------------------------------------------------- 1 | module Ast2Assembly where 2 | 3 | import LLVM.AST 4 | import LLVM.Module (withModuleFromAST, moduleLLVMAssembly ) 5 | import LLVM.Context (withContext) 6 | import Control.Monad.Trans.Except 7 | 8 | ast2Assembly :: Module -> IO String 9 | ast2Assembly m = 10 | (either error id) <$> 11 | withContext (\c -> 12 | runExceptT (withModuleFromAST c m ( moduleLLVMAssembly ))) 13 | 14 | ast2AssemblyFile :: Module -> FilePath -> IO () 15 | ast2AssemblyFile mod path = ast2Assembly mod >>= writeFile path 16 | -------------------------------------------------------------------------------- /vellvm-ast-pp/ShowAst.hs: -------------------------------------------------------------------------------- 1 | import LLVM.Module 2 | import LLVM.Context 3 | import Text.Groom 4 | import Control.Monad.Trans.Except 5 | 6 | main = do 7 | assembly <- getContents 8 | withContext $ \c -> 9 | fmap (either error id) $ 10 | runExceptT $ do 11 | ast <- withModuleFromLLVMAssembly c assembly $ \mod -> do 12 | ast <- moduleAST mod 13 | putStrLn $ groom ast 14 | return ast 15 | 16 | withModuleFromAST c ast $ \assembly2 -> 17 | moduleLLVMAssembly assembly2 >>= putStrLn 18 | return () 19 | --------------------------------------------------------------------------------