From 6e615bf05606fc6028ea317bcbd7363de4a83439 Mon Sep 17 00:00:00 2001 From: Providence Salumu Date: Thu, 25 Feb 2021 06:37:34 -0500 Subject: [PATCH] #398, add files --- nix/overlays.nix | 29 ++++--- playground/haskell/compress/ChangeLog.md | 3 + playground/haskell/compress/LICENSE | 30 ++++++++ playground/haskell/compress/README.md | 1 + playground/haskell/compress/Setup.hs | 2 + playground/haskell/compress/app/Main.hs | 6 ++ .../compress/cbits/include/issue-398/dawa79.H | 50 ++++++++++++ playground/haskell/compress/compress.cabal | 76 +++++++++++++++++++ playground/haskell/compress/src/Lib.hs | 53 +++++++++++++ playground/haskell/compress/test/Spec.hs | 2 + playground/haskell/hie.yaml | 12 +++ 11 files changed, 253 insertions(+), 11 deletions(-) create mode 100644 playground/haskell/compress/ChangeLog.md create mode 100644 playground/haskell/compress/LICENSE create mode 100644 playground/haskell/compress/README.md create mode 100644 playground/haskell/compress/Setup.hs create mode 100644 playground/haskell/compress/app/Main.hs create mode 100644 playground/haskell/compress/cbits/include/issue-398/dawa79.H create mode 100644 playground/haskell/compress/compress.cabal create mode 100644 playground/haskell/compress/src/Lib.hs create mode 100644 playground/haskell/compress/test/Spec.hs diff --git a/nix/overlays.nix b/nix/overlays.nix index aa14e8e6f..e0f2da9db 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -40,7 +40,7 @@ let when = c: m: if c then m else {}; - withMCMove = { llvmVersion, gccVersion, hobbes-dyn }: + withPlayground = { cname, cpath, llvmVersion, gccVersion, hobbes-dyn }: # with haskellPackages; # breaks with: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2556 with haskell.packages.ghc884; # with haskell.packages.ghc8103; # breaks with: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2556 @@ -48,12 +48,8 @@ let let gccEnv = final."gcc${toString gccVersion}Stdenv"; llvmEnv = final."llvmPackages_${toString llvmVersion}"; in - overrideCabal (callCabal2nix "mcmove" ../playground/haskell/mcmove { inherit hobbes-dyn; }) (drv: { + overrideCabal (callCabal2nix cname cpath { inherit hobbes-dyn; }) (drv: { librarySystemDepends = (drv.librarySystemDepends or []) ++ [ llvmEnv.llvm ]; - postPatch = '' - substituteInPlace mcmove.cabal --replace "__ghc_options_pgmc__" "${gccEnv.cc}/bin/g++" - cat mcmove.cabal - ''; }); withGCC = { gccVersion ? 10 }: @@ -89,11 +85,22 @@ in { hobbesPackages = when stdenv.isLinux (recurseIntoAttrs (builtins.listToAttr name = "llvm-" + toString llvmVersion; value = recurseIntoAttrs (rec { hobbes = dbg (callPackage (withGCC { inherit (gccConstraint) gccVersion; }) { inherit llvmVersion; }); - mcmove = withMCMove { - inherit llvmVersion; - inherit (gccConstraint) gccVersion; - hobbes-dyn = inputs.morganstanley.packages.${system}.${"hobbesPackages/gcc-" + toString gccConstraint.gccVersion + "/llvm-" + toString llvmVersion + "/hobbes"}; - }; + playground = recurseIntoAttrs (rec { + mcmove = withPlayground { + inherit llvmVersion; + inherit (gccConstraint) gccVersion; + hobbes-dyn = inputs.morganstanley.packages.${system}.${"hobbesPackages/gcc-" + toString gccConstraint.gccVersion + "/llvm-" + toString llvmVersion + "/hobbes"}; + cname = "mcmove"; + cpath = ../playground/haskell/mcmove; + }; + compress = withPlayground { + inherit llvmVersion; + inherit (gccConstraint) gccVersion; + hobbes-dyn = inputs.morganstanley.packages.${system}.${"hobbesPackages/gcc-" + toString gccConstraint.gccVersion + "/llvm-" + toString llvmVersion + "/hobbes"}; + cname = "compress"; + cpath = ../playground/haskell/compress; + }; + }); }); }) gccConstraint.llvmVersions)); }) gccConstraints))) diff --git a/playground/haskell/compress/ChangeLog.md b/playground/haskell/compress/ChangeLog.md new file mode 100644 index 000000000..afbe853d2 --- /dev/null +++ b/playground/haskell/compress/ChangeLog.md @@ -0,0 +1,3 @@ +# Changelog for compress + +## Unreleased changes diff --git a/playground/haskell/compress/LICENSE b/playground/haskell/compress/LICENSE new file mode 100644 index 000000000..30e2bc07a --- /dev/null +++ b/playground/haskell/compress/LICENSE @@ -0,0 +1,30 @@ +Copyright Providence Salumu (c) 2021 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Providence Salumu nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/playground/haskell/compress/README.md b/playground/haskell/compress/README.md new file mode 100644 index 000000000..345da295b --- /dev/null +++ b/playground/haskell/compress/README.md @@ -0,0 +1 @@ +# compress diff --git a/playground/haskell/compress/Setup.hs b/playground/haskell/compress/Setup.hs new file mode 100644 index 000000000..9a994af67 --- /dev/null +++ b/playground/haskell/compress/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/playground/haskell/compress/app/Main.hs b/playground/haskell/compress/app/Main.hs new file mode 100644 index 000000000..de1c1ab35 --- /dev/null +++ b/playground/haskell/compress/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = someFunc diff --git a/playground/haskell/compress/cbits/include/issue-398/dawa79.H b/playground/haskell/compress/cbits/include/issue-398/dawa79.H new file mode 100644 index 000000000..2ad15bda1 --- /dev/null +++ b/playground/haskell/compress/cbits/include/issue-398/dawa79.H @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include +#include + +const int option = 100; + +struct TestEnum { + enum Enum : uint32_t { Invalid = 0, Option = option }; + Enum _value; + using is_enum = void; +}; + +namespace hobbes { +template struct liftTestEnum { + static MonoTypePtr type(typedb &) { + Variant::Members vms; + auto i = 0; + vms.push_back(Variant::Member("Invalid", primty("unit"), 0)); + vms.push_back(Variant::Member("Option", primty("unit"), option)); + return MonoTypePtr(Variant::make(vms)); + } +}; +template struct lift : public liftTestEnum {}; +template struct lift : public liftTestEnum {}; +} // namespace hobbes + +DEFINE_STRUCT(FixarrayS, (TestEnum, value), (const hobbes::array *, body)); + +void run(const std::string &fname, bool compressed) { + hobbes::cc c; + FixarrayS v1; + v1.body = hobbes::makeString("Hello world!"); + v1.value._value = TestEnum::Option; + + hobbes::writer writer{fname}; + hobbes::series ss1(&c, &writer, "udata", 10000, + compressed ? hobbes::StoredSeries::Compressed + : hobbes::StoredSeries::Raw); + ss1(v1); + std::cout << "------------testing -----------------" << std::endl; + // c.define("f", "inputFile :: (LoadFile " + // " + fname + " + // " w) => w"); + // c.compileFn( + // "print([(x.value, (unsafeCast(x.value)::{t:int}).t) | x<-f.udata])")(); +} diff --git a/playground/haskell/compress/compress.cabal b/playground/haskell/compress/compress.cabal new file mode 100644 index 000000000..e4cc07ae5 --- /dev/null +++ b/playground/haskell/compress/compress.cabal @@ -0,0 +1,76 @@ +cabal-version: 3.0 +name: compress +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/smunix/compress#readme +bug-reports: https://github.com/smunix/compress/issues +author: Providence Salumu +maintainer: Providence.Salumu@smunix.com +copyright: BSD3 +license: BSD-3-Clause +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/smunix/compress + +common common-stanzas + default-extensions: BlockArguments + BangPatterns + GADTs + MultiParamTypeClasses + OverloadedStrings + RankNTypes + ScopedTypeVariables + TupleSections + TypeApplications + ViewPatterns + default-language: Haskell2010 + cxx-options: -std=c++14 -g -O2 + ghc-options: -pgmc=g++ -ddump-splices -ddump-simpl + extra-libraries: hobbes-dyn + include-dirs: cbits/include + build-depends: base + , bytestring + , text + , inline-c + , inline-c-cpp + , microlens-platform + +library + import: common-stanzas + exposed-modules: + Lib + other-modules: + Paths_compress + hs-source-dirs: + src + +executable compress-exe + import: common-stanzas + main-is: Main.hs + other-modules: + Paths_compress + hs-source-dirs: + app + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + compress + default-language: Haskell2010 + +test-suite compress-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_compress + hs-source-dirs: + test + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 + , compress + default-language: Haskell2010 diff --git a/playground/haskell/compress/src/Lib.hs b/playground/haskell/compress/src/Lib.hs new file mode 100644 index 000000000..c9493840c --- /dev/null +++ b/playground/haskell/compress/src/Lib.hs @@ -0,0 +1,53 @@ +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE TemplateHaskell #-} + +module Lib + ( someFunc, + ) +where + +import Foreign.Concurrent (newForeignPtr) +import Foreign.ForeignPtr hiding (newForeignPtr) +import Foreign.Ptr +import qualified Language.C.Inline as C +import qualified Language.C.Inline.Cpp as C +import Lens.Micro.Platform + +newtype Cc where + Cc :: {_compiler :: ForeignPtr Cc} -> Cc + +makeLenses ''Cc + +C.context $ + C.baseCtx + <> C.bsCtx + <> C.cppCtx + <> C.fptrCtx + <> C.funCtx + <> C.bsCtx + <> C.cppTypePairs + [ ("Cc", [t|Cc|]) + ] + +C.include "" +C.include "" +C.include "" + +C.using "Cc = hobbes::cc" + +class New a where + new :: IO a + +instance New Cc where + new = + [C.exp|Cc* {new Cc{}}|] + >>= \cc -> + newForeignPtr cc ([C.block|void { delete $(Cc* cc); }|]) + >>= return . Cc + +withCc :: (Cc -> IO ()) -> IO () +withCc fn = new >>= fn + +someFunc :: IO () +someFunc = withCc \_ -> do + putStrLn "Cc initialized" diff --git a/playground/haskell/compress/test/Spec.hs b/playground/haskell/compress/test/Spec.hs new file mode 100644 index 000000000..cd4753fc9 --- /dev/null +++ b/playground/haskell/compress/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented" diff --git a/playground/haskell/hie.yaml b/playground/haskell/hie.yaml index b4bded01a..a46e9fa31 100644 --- a/playground/haskell/hie.yaml +++ b/playground/haskell/hie.yaml @@ -1,4 +1,16 @@ cradle: cabal: + - path: "compress/src" + component: "lib:compress" + + - path: "compress/app/Main.hs" + component: "compress:exe:compress-exe" + + - path: "compress/app/Paths_compress.hs" + component: "compress:exe:compress-exe" + + - path: "compress/test" + component: "compress:test:compress-test" + - path: "mcmove/src/Main.hs" component: "mcmove:exe:mcmove"