Skip to content

Commit

Permalink
#398, add files
Browse files Browse the repository at this point in the history
  • Loading branch information
smunix committed Feb 25, 2021
1 parent f3a3836 commit 6e615bf
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 11 deletions.
29 changes: 18 additions & 11 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@ 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
with haskell.lib;
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 }:
Expand Down Expand Up @@ -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)))
Expand Down
3 changes: 3 additions & 0 deletions playground/haskell/compress/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog for compress

## Unreleased changes
30 changes: 30 additions & 0 deletions playground/haskell/compress/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions playground/haskell/compress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# compress
2 changes: 2 additions & 0 deletions playground/haskell/compress/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
6 changes: 6 additions & 0 deletions playground/haskell/compress/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = someFunc
50 changes: 50 additions & 0 deletions playground/haskell/compress/cbits/include/issue-398/dawa79.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include <hobbes/db/file.H>
#include <hobbes/db/series.H>
#include <hobbes/hobbes.H>
#include <hobbes/lang/tylift.H>
#include <hobbes/storage.H>

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<T *, false, typename T::is_enum> : public liftTestEnum {};
template struct lift<T, true, typename T::is_enum> : 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<void()>(
// "print([(x.value, (unsafeCast(x.value)::{t:int}).t) | x<-f.udata])")();
}
76 changes: 76 additions & 0 deletions playground/haskell/compress/compress.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cabal-version: 3.0
name: compress
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/smunix/compress#readme>
homepage: https://github.com/smunix/compress#readme
bug-reports: https://github.com/smunix/compress/issues
author: Providence Salumu
maintainer: [email protected]
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
53 changes: 53 additions & 0 deletions playground/haskell/compress/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -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 "<hobbes/hobbes.H>"
C.include "<issue-398/dawa79.H>"
C.include "<iostream>"

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"
2 changes: 2 additions & 0 deletions playground/haskell/compress/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
12 changes: 12 additions & 0 deletions playground/haskell/hie.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 6e615bf

Please sign in to comment.