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 2dc2367 commit 3a5b79d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
10 changes: 6 additions & 4 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ let
let gccEnv = final."gcc${toString gccVersion}Stdenv";
llvmEnv = final."llvmPackages_${toString llvmVersion}";
in
overrideCabal (callCabal2nix cname cpath { inherit hobbes-dyn; }) (drv: {
librarySystemDepends = (drv.librarySystemDepends or []) ++ [ llvmEnv.llvm ];
overrideCabal (callCabal2nix cname cpath { inherit hobbes-dyn; }) (drv: {
doHaddock = false;
doCheck = false;
librarySystemDepends = (drv.librarySystemDepends or []) ++ [ llvmEnv.llvm ];
});

withGCC = { gccVersion ? 10 }:
Expand Down Expand Up @@ -93,13 +95,13 @@ in { hobbesPackages = when stdenv.isLinux (recurseIntoAttrs (builtins.listToAttr
cname = "mcmove";
cpath = ../playground/haskell/mcmove;
};
compress = withPlayground {
compress = enableDebugging (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));
Expand Down
55 changes: 29 additions & 26 deletions playground/haskell/compress/cbits/include/issue-398/dawa79.H
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,49 @@

const int option = 100;

struct TestEnum {
struct Test {
enum Enum : uint32_t { Invalid = 0, Option = option };
Enum _value;
using is_enum = void;
Enum _enum;
};

namespace hobbes {
struct liftTestEnum {
namespace fregion {
template <> struct compress<Test> : public compress<uint32_t> {};
} // namespace fregion
template <> struct lift<Test, true> {
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));
auto variantTy = [&]() -> MonoTypePtr {
Variant::Members vms;
auto testTy = primty("Test", tabs(str::strings("x"), primty("unit")));
vms.push_back(
Variant::Member("invalid", tapp(testTy, list(tlong(0))), 0));
vms.push_back(
Variant::Member("option", tapp(testTy, list(tlong(option))), 1));
return MonoTypePtr(Variant::make(vms));
};
return tapp(primty("test", tabs(str::strings("x"), primty("int"))),
list(variantTy()));
}
};
template <class T>
struct lift<T *, false, typename T::is_enum> : public liftTestEnum {};
template <class T>
struct lift<T, true, typename T::is_enum> : public liftTestEnum {};
template <> struct lift<Test *, false> : public lift<Test, true> {};
} // namespace hobbes

DEFINE_STRUCT(FixarrayS, (TestEnum, value),
(const hobbes::array<char> *, body));
DEFINE_STRUCT(Struct, (Test, test), (const hobbes::array<char> *, string));

void run(const std::string &fname, bool compressed) {
hobbes::cc c;
FixarrayS v1;
v1.body = hobbes::makeString("Hello world!");
v1.value._value = TestEnum::Option;
Struct v1;
v1.string = hobbes::makeString("Hello world!");
v1.test._enum = Test::Option;

hobbes::writer writer{fname};
hobbes::series<FixarrayS> ss1(&c, &writer, "udata", 10000,
compressed ? hobbes::StoredSeries::Compressed
: hobbes::StoredSeries::Raw);
hobbes::series<Struct> 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");
std::cout << "------------start 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])")();
// "print([(x.test, (unsafeCast(x.test)::{t:int}).t) | x<-f.udata])")();
std::cout << "------------end testing -----------------" << std::endl;
}
2 changes: 1 addition & 1 deletion playground/haskell/compress/compress.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ common common-stanzas
TypeApplications
ViewPatterns
default-language: Haskell2010
cxx-options: -std=c++14 -g -O2
cxx-options: -std=c++14 -g
ghc-options: -pgmc=g++ -ddump-splices -ddump-simpl
extra-libraries: hobbes-dyn
include-dirs: cbits/include
Expand Down
4 changes: 4 additions & 0 deletions playground/haskell/compress/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ withCc fn = new >>= fn
someFunc :: IO ()
someFunc = withCc \_ -> do
putStrLn "Cc initialized"
[C.block|void {
run("/home/smunix/Programming/compilers/hobbes/issue-398.db", true);
}|]
putStrLn "Cc ended"

0 comments on commit 3a5b79d

Please sign in to comment.