From cf62d712253bb8999f691b0bf3846f514c6aa2fd Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sun, 23 Mar 2008 18:31:15 +0000 Subject: [PATCH] Initial commit; code copied from the base package --- GHC/Bool.hs | 11 ++++++++++ GHC/Generics.hs | 13 ++++++++++++ LICENSE | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Setup.hs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ ghc-prim.cabal | 21 +++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 GHC/Bool.hs create mode 100644 GHC/Generics.hs create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 ghc-prim.cabal diff --git a/GHC/Bool.hs b/GHC/Bool.hs new file mode 100644 index 0000000..f0b004f --- /dev/null +++ b/GHC/Bool.hs @@ -0,0 +1,11 @@ + +{-# OPTIONS_GHC -fno-implicit-prelude #-} + +module GHC.Bool where + +-- We need Inl etc behind the scenes for the Bool definition +import GHC.Generics + +default () + +data Bool = False | True diff --git a/GHC/Generics.hs b/GHC/Generics.hs new file mode 100644 index 0000000..906c02c --- /dev/null +++ b/GHC/Generics.hs @@ -0,0 +1,13 @@ + +{-# OPTIONS_GHC -fno-implicit-prelude #-} + +module GHC.Generics where + +default () + +data Unit = Unit +#ifndef __HADDOCK__ +data (:+:) a b = Inl a | Inr b +data (:*:) a b = a :*: b +#endif + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fe00a83 --- /dev/null +++ b/LICENSE @@ -0,0 +1,62 @@ +This library (libraries/ghc-prim) is derived from code from several +sources: + + * Code from the GHC project which is largely (c) The University of + Glasgow, and distributable under a BSD-style license (see below), + + * Code from the Haskell 98 Report which is (c) Simon Peyton Jones + and freely redistributable (but see the full license for + restrictions). + +The full text of these licenses is reproduced below. All of the +licenses are BSD-style or compatible. + +----------------------------------------------------------------------------- + +The Glasgow Haskell Compiler License + +Copyright 2004, The University Court of the University of Glasgow. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +- Neither name of the University nor the names of its contributors may be +used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF +GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +DAMAGE. + +----------------------------------------------------------------------------- + +Code derived from the document "Report on the Programming Language +Haskell 98", is distributed under the following license: + + Copyright (c) 2002 Simon Peyton Jones + + The authors intend this Report to belong to the entire Haskell + community, and so we grant permission to copy and distribute it for + any purpose, provided that it is reproduced in its entirety, + including this Notice. Modified versions of this Report may also be + copied and distributed for any purpose, provided that the modified + version is clearly presented as such, and that it does not claim to + be a definition of the Haskell 98 Language. + diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..d6836e4 --- /dev/null +++ b/Setup.hs @@ -0,0 +1,57 @@ + +-- We need to do some ugly hacks here because of GHC magic + +module Main (main) where + +import Control.Monad +import Data.List +import Distribution.PackageDescription +import Distribution.Simple +import Distribution.Simple.LocalBuildInfo +import Distribution.Simple.Utils +import System.Cmd +import System.FilePath +import System.Exit +import System.Directory +import Control.Exception (try) + +main :: IO () +main = do let hooks = defaultUserHooks { + buildHook = build_primitive_sources + $ buildHook defaultUserHooks, + makefileHook = build_primitive_sources + $ makefileHook defaultUserHooks, + haddockHook = build_primitive_sources + $ haddockHook defaultUserHooks } + defaultMainWithHooks hooks + +type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO () + +build_primitive_sources :: Hook a -> Hook a +build_primitive_sources f pd lbi uhs x + = do when (compilerFlavor (compiler lbi) == GHC) $ do + let genprimopcode = joinPath ["..", "..", "utils", + "genprimopcode", "genprimopcode"] + primops = joinPath ["..", "..", "compiler", "prelude", + "primops.txt"] + primhs = joinPath ["GHC", "Prim.hs"] + primopwrappers = joinPath ["GHC", "PrimopWrappers.hs"] + primhs_tmp = addExtension primhs "tmp" + primopwrappers_tmp = addExtension primopwrappers "tmp" + maybeExit $ system (genprimopcode ++ " --make-haskell-source < " + ++ primops ++ " > " ++ primhs_tmp) + maybeUpdateFile primhs_tmp primhs + maybeExit $ system (genprimopcode ++ " --make-haskell-wrappers < " + ++ primops ++ " > " ++ primopwrappers_tmp) + maybeUpdateFile primopwrappers_tmp primopwrappers + f pd lbi uhs x + +-- Replace a file only if the new version is different from the old. +-- This prevents make from doing unnecessary work after we run 'setup makefile' +maybeUpdateFile :: FilePath -> FilePath -> IO () +maybeUpdateFile source target = do + r <- rawSystem "cmp" ["-s" {-quiet-}, source, target] + case r of + ExitSuccess -> removeFile source + ExitFailure _ -> do try (removeFile target); renameFile source target + diff --git a/ghc-prim.cabal b/ghc-prim.cabal new file mode 100644 index 0000000..7bec732 --- /dev/null +++ b/ghc-prim.cabal @@ -0,0 +1,21 @@ +name: ghc-prim +version: 0.1 +license: BSD3 +license-file: LICENSE +maintainer: libraries@haskell.org +synopsis: GHC primitives +description: + GHC primitives. +cabal-version: >=1.2 +build-type: Custom + +Library { + exposed-modules: + GHC.Bool + GHC.Generics + GHC.PrimopWrappers + extensions: CPP, MagicHash + -- We need to set the package name to ghc-prim (without a version number) + -- as it's magic. + ghc-options: -package-name ghc-prim +} -- 1.7.10.4