Skip to content

Commit

Permalink
W.I.p
Browse files Browse the repository at this point in the history
  • Loading branch information
Dong Han committed Aug 24, 2023
1 parent 5944ae9 commit 0cf1afb
Show file tree
Hide file tree
Showing 77 changed files with 12,404 additions and 11,589 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[submodule "third_party/utf8rewind"]
path = third_party/utf8rewind
url = https://github.com/ZHaskell/utf8rewind.git
[submodule "third_party/re2"]
path = third_party/re2
url = https://github.com/google/re2.git
[submodule "third_party/fastbase64"]
path = third_party/fastbase64
url = https://github.com/ZHaskell/fastbase64.git
[submodule "third_party/botan"]
path = third_party/botan
url = https://github.com/randombit/botan.git
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
lib:
cabal build

clean:
cabal clean

doctest:
cabal repl --with-ghc=doctest

doctest_verbose:
cabal repl --with-ghc=doctest --repl-options=--verbose

doc:
cabal haddock \
--haddock-options="--mathjax=https://z.haskell.world/haddock.inject.utterances.via.mathjax.js?repo=ZHaskell/z-data"\
--haddock-hyperlink-sources --haddock-css=doc-assets/z.haddock.css \
--haddock-html-location='https://hackage.haskell.org/package/$$pkg-$$version/docs'

cndoc:
cabal -fbuild-chinese-doc haddock \
--haddock-options="--mathjax=https://z.haskell.world/haddock.inject.utterances.via.mathjax.js?repo=ZHaskell/z-data"\
--haddock-hyperlink-sources --haddock-css=doc-assets/z.haddock.css \
--haddock-html-location='https://hackage.haskell.org/package/$$pkg-$$version/docs'

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,10 @@ cabal install
# generate document
cabal haddock
```

## TODO

fix array prim ops
fix all slice length -> end
fix encoder
fix decoder
110 changes: 99 additions & 11 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,102 @@
{-# LANGUAGE CPP #-}
import Distribution.Simple
import System.Environment
module Main (main) where

import Control.Monad
import Distribution.Pretty
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.Verbosity
import Distribution.Simple.Utils
import Distribution.Simple.Program
import Distribution.Simple.Program.Db
import Distribution.System
import Distribution.Utils.NubList
import Distribution.Types.BuildInfo
import Distribution.Types.HookedBuildInfo
import Distribution.Types.Library
import Distribution.Types.LocalBuildInfo
import Distribution.Types.PackageDescription
import Data.Maybe
import Data.List
import System.Directory
import System.FilePath
import qualified System.Environment as System

main :: IO ()
main = do
#if __GLASGOW_HASKELL__ < 810
defaultMain
#else
args <- getArgs
if head args == "configure"
then defaultMainArgs $ [ "--ghc-options", "-optcxx-std=c++11"
] ++ args
else defaultMain
#endif
defaultMainWithHooks simpleUserHooks {
preConf = zPreConf,
confHook = \ pd flags -> do
lbi <- confHook simpleUserHooks pd flags
baseDir <- getCurrentDirectory
let verbosity = fromFlag (configVerbosity flags)
configFile = baseDir </> "third_party" </> "botan" </> "configure.py"
configFolder = baseDir </> "third_party" </> "botan"
headerFile = baseDir </> "third_party" </> "botan" </> "botan_all.h"
placeholder = "build" </> "include" </> "external" </> "cabal.placeholder"
headerFileExists <- doesFileExist headerFile
unless headerFileExists $ do
confExists <- doesFileExist configFile
if confExists
then do
runConfigureScript configFolder configFile verbosity flags lbi
runTouch configFolder placeholder verbosity flags
else die' verbosity "botan configure script not found."

return lbi
, regHook = \ _ _ _ _ -> return ()
}

zPreConf :: Args -> ConfigFlags -> IO HookedBuildInfo
zPreConf args flags = do
preConf simpleUserHooks args flags

runConfigureScript :: FilePath -> FilePath -> Verbosity -> ConfigFlags -> LocalBuildInfo -> IO ()
runConfigureScript configFolder configFile verbosity flags lbi = do
env <- System.getEnvironment
configureFile <- makeAbsolute configFile

let extraPath = fromNubList $ configProgramPathExtra flags
spSep = [searchPathSeparator]
pathEnv = maybe (intercalate spSep extraPath)
((intercalate spSep extraPath ++ spSep)++) $ lookup "PATH" env
pyProgs = simpleProgram <$> ["python", "python2", "python3"]
progDb = modifyProgramSearchPath
(\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb
overEnv = [("PATH", Just pathEnv) | not (null extraPath)]
hp@(Platform arch os) = hostPlatform lbi
-- use gcc/mingw bunlded with GHC
osStr = if os == Windows then "mingw" else (show (pretty os))
hostFlag = [ "--cpu=" ++ show (pretty arch), "--os=" ++ osStr]
-- pass amalgamation to produce botan_all.cpp
args = configureFile:"--amalgamation":"--disable-shared":hostFlag

pyConfiguredProg <- forM pyProgs $ \ pyProg ->
lookupProgram pyProg <$> configureProgram verbosity pyProg progDb

case msum (pyConfiguredProg) of
Just py -> runProgramInvocation verbosity $
(programInvocation (py {programOverrideEnv = overEnv}) args)
{ progInvokeCwd = Just configFolder }
Nothing -> die' verbosity notFoundMsg
where
notFoundMsg = "The package's dep(botan) has a 'configure.py' script. "
++ "This requires python is discoverable in your path."


runTouch :: FilePath -> FilePath -> Verbosity -> ConfigFlags -> IO ()
runTouch configFolder placeholder verbosity flags = do
let extraPath = fromNubList $ configProgramPathExtra flags
progDb = modifyProgramSearchPath
(\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb
touchPG = simpleProgram "touch"
touch <- lookupProgram touchPG <$> configureProgram verbosity touchPG progDb
case touch of
Just touch' ->
runProgramInvocation verbosity $
(programInvocation touch' [placeholder])
{ progInvokeCwd = Just configFolder }
Nothing -> warn verbosity notFoundMsg
where
notFoundMsg = "touch is required to keep a cabal placeholder file, otherwise cabal sdist may produce an unbuildable tarball"
Empty file added Z/Botan/Hash.hs
Empty file.
File renamed without changes.
25 changes: 6 additions & 19 deletions Z/Data/ASCII.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Maintainer : [email protected]
Stability : experimental
Portability : non-portable
ASCII Chars utility.
ASCII Chars utility, all funcions works on <https://en.wikipedia.org/wiki/ASCII US-ASCII> chars.
-}

Expand Down Expand Up @@ -57,24 +57,6 @@ toUpper w
| 97 <= w && w <= 122 = w - 32
| otherwise = w

-- | @A ~ Z@ => @a ~ z@, @À ~ Ö@ => @à ~ ö@, @Ø ~ Þ@ => @ø ~ þ@
toLowerLatin :: Word8 -> Word8
{-# INLINE toLowerLatin #-}
toLowerLatin w
| 65 <= w && w <= 90 ||
192 <= w && w <= 214 ||
216 <= w && w <= 222 = w + 32
| otherwise = w

-- | @a ~ z@ => @A ~ Z@, @à ~ ö@ => @À ~ Ö@, @ø ~ þ@ => @Ø ~ Þ@
toUpperLatin :: Word8 -> Word8
{-# INLINE toUpperLatin #-}
toUpperLatin w
| 97 <= w && w <= 122 ||
224 <= w && w <= 246 ||
248 <= w && w <= 254 = w - 32
| otherwise = w

-- | @ISO-8859-1@ control letter.
isControl :: Word8 -> Bool
{-# INLINE isControl #-}
Expand All @@ -90,6 +72,11 @@ isDigit :: Word8 -> Bool
{-# INLINE isDigit #-}
isDigit w = w - DIGIT_0 <= 9

-- | @a-z A-Z@
isLetter :: Word8 -> Bool
{-# INLINE isLetter #-}
isLetter w = isLower w || isUpper w

-- | @0 ~ 7@
isOctDigit :: Word8 -> Bool
{-# INLINE isOctDigit #-}
Expand Down
Loading

0 comments on commit 0cf1afb

Please sign in to comment.