From 3a5b79dbaee3710fa1ae21742feb653564b899c1 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 | 10 ++-- .../compress/cbits/include/issue-398/dawa79.H | 55 ++++++++++--------- playground/haskell/compress/compress.cabal | 2 +- playground/haskell/compress/src/Lib.hs | 4 ++ 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/nix/overlays.nix b/nix/overlays.nix index e0f2da9d..349d0fef 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -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 }: @@ -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)); diff --git a/playground/haskell/compress/cbits/include/issue-398/dawa79.H b/playground/haskell/compress/cbits/include/issue-398/dawa79.H index 8989131b..67bc3b0a 100644 --- a/playground/haskell/compress/cbits/include/issue-398/dawa79.H +++ b/playground/haskell/compress/cbits/include/issue-398/dawa79.H @@ -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 : public compress {}; +} // namespace fregion +template <> struct lift { 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 -struct lift : public liftTestEnum {}; -template -struct lift : public liftTestEnum {}; +template <> struct lift : public lift {}; } // namespace hobbes -DEFINE_STRUCT(FixarrayS, (TestEnum, value), - (const hobbes::array *, body)); +DEFINE_STRUCT(Struct, (Test, test), (const hobbes::array *, 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 ss1(&c, &writer, "udata", 10000, - compressed ? hobbes::StoredSeries::Compressed - : hobbes::StoredSeries::Raw); + 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"); + std::cout << "------------start 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])")(); + // "print([(x.test, (unsafeCast(x.test)::{t:int}).t) | x<-f.udata])")(); + std::cout << "------------end testing -----------------" << std::endl; } diff --git a/playground/haskell/compress/compress.cabal b/playground/haskell/compress/compress.cabal index e4cc07ae..6e767c79 100644 --- a/playground/haskell/compress/compress.cabal +++ b/playground/haskell/compress/compress.cabal @@ -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 diff --git a/playground/haskell/compress/src/Lib.hs b/playground/haskell/compress/src/Lib.hs index c9493840..11c7bbff 100644 --- a/playground/haskell/compress/src/Lib.hs +++ b/playground/haskell/compress/src/Lib.hs @@ -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"