Skip to content

Commit 2f18e9d

Browse files
committed
WIP
0 parents  commit 2f18e9d

File tree

24 files changed

+924
-0
lines changed

24 files changed

+924
-0
lines changed

.ghcid

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--command "wasm32-wasi-cabal repl --enable-multi-repl"
2+
--restart cabal.project
3+
--restart canary.cabal

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: ci
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
workflow_dispatch:
10+
11+
jobs:
12+
ci:
13+
name: ci-${{ matrix.flavour }}
14+
runs-on: ubuntu-24.04
15+
continue-on-error: ${{ matrix.experimental }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
flavour:
20+
- "9.12"
21+
- "9.10"
22+
experimental:
23+
- false
24+
include:
25+
- flavour: "gmp"
26+
experimental: true
27+
steps:
28+
29+
- name: checkout
30+
uses: actions/checkout@v4
31+
32+
- name: ghc-wasm-meta
33+
run: |
34+
pushd "$(mktemp -d)"
35+
curl -f -L https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1
36+
PLAYWRIGHT=1 ./setup.sh
37+
~/.ghc-wasm/add_to_github_path.sh
38+
cp cabal.project.local ${{ github.workspace }}
39+
popd
40+
env:
41+
FLAVOUR: ${{ matrix.flavour }}
42+
43+
- name: gen-plan-json
44+
run: |
45+
wasm32-wasi-cabal build --dry-run
46+
47+
- name: cabal-cache
48+
uses: actions/cache@v4
49+
with:
50+
key: ${{ matrix.flavour }}-${{ hashFiles('dist-newstyle/cache/plan.json') }}
51+
restore-keys: ${{ matrix.flavour }}-
52+
path: |
53+
~/.ghc-wasm/.cabal/store
54+
dist-newstyle
55+
56+
- name: ci
57+
run: |
58+
./util/ci

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cabal.project.local
2+
ci.log
3+
dist-newstyle

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for canary
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright (c) 2025, Cheng Shao
2+
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above
11+
copyright notice, this list of conditions and the following
12+
disclaimer in the documentation and/or other materials provided
13+
with the distribution.
14+
15+
* Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived
17+
from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cabal.project

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
packages: .
2+
3+
tests: True
4+
5+
source-repository-package
6+
type: git
7+
location: https://github.com/amesgen/splitmix.git
8+
tag: cea9e31bdd849eb0c17611bb99e33d590e126164
9+
10+
package *
11+
optimization: 2
12+
ghc-options: -fdicts-cheap -fexpose-all-unfoldings -flate-dmd-anal -flate-specialise -fspecialise-aggressively
13+
14+
package tasty
15+
flags: -unix
16+
17+
package vector
18+
flags: -boundschecks

canary.cabal

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
cabal-version: 3.14
2+
name: canary
3+
version: 0.1.0.0
4+
license: BSD-3-Clause
5+
license-file: LICENSE
6+
author: Cheng Shao
7+
maintainer: [email protected]
8+
build-type: Simple
9+
extra-doc-files: CHANGELOG.md
10+
11+
common deps
12+
build-depends:
13+
aeson >=2.2.3.0,
14+
async >=2.2.5,
15+
base,
16+
ghc-experimental,
17+
text,
18+
vector >=0.13.2.0,
19+
vector-stream >=0.1.0.1,
20+
21+
default-language: GHC2024
22+
ghc-options:
23+
-Weverything
24+
-Wno-all-missed-specialisations
25+
-Wno-implicit-prelude
26+
-Wno-missing-export-lists
27+
-Wno-missing-import-lists
28+
-Wno-missing-kind-signatures
29+
-Wno-missing-local-signatures
30+
-Wno-missing-poly-kind-signatures
31+
-Wno-missing-role-annotations
32+
-Wno-missing-safe-haskell-mode
33+
-Wno-prepositive-qualified-module
34+
-Wno-unsafe
35+
36+
library
37+
import: deps
38+
exposed-modules:
39+
Control.Concurrent.Async.Extra
40+
Data.Stream.Monadic.Extra
41+
Data.Text.Extra
42+
GHC.Wasm.JS.Array
43+
GHC.Wasm.JS.AsyncIterator
44+
GHC.Wasm.JS.ESM
45+
GHC.Wasm.JS.Free
46+
GHC.Wasm.JS.JSON
47+
GHC.Wasm.JS.Promise
48+
GHC.Wasm.JS.ReadableStream
49+
GHC.Wasm.JS.RuntimeFFI
50+
GHC.Wasm.JS.String
51+
GHC.Wasm.JS.Uint8Array
52+
53+
hs-source-dirs: src
54+
build-depends:
55+
bytestring,
56+
primitive >=0.9.1.0,
57+
58+
test-suite canary-test
59+
import: deps
60+
type: exitcode-stdio-1.0
61+
hs-source-dirs: test
62+
main-is: Main.hs
63+
build-depends:
64+
canary,
65+
quickcheck-instances >=0.3.32,
66+
tasty >=1.5.3,
67+
tasty-hunit >=0.10.2,
68+
tasty-quickcheck >=0.11.1,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Control.Concurrent.Async.Extra
2+
( concurrentlyR,
3+
)
4+
where
5+
6+
import Control.Concurrent.Async
7+
8+
concurrentlyR :: IO a -> IO b -> IO b
9+
concurrentlyR l r = do
10+
(_, b) <- concurrently l r
11+
pure b

src/Data/Stream/Monadic/Extra.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Data.Stream.Monadic.Extra
2+
( toLazyList,
3+
toVector,
4+
)
5+
where
6+
7+
import Control.Monad
8+
import Control.Monad.Primitive
9+
import Data.Stream.Monadic qualified as VS
10+
import Data.Vector.Fusion.Bundle.Monadic qualified as VB
11+
import Data.Vector.Fusion.Bundle.Size qualified as VB
12+
import Data.Vector.Generic qualified as V
13+
import Data.Vector.Generic.Mutable qualified as MV
14+
15+
toLazyList :: (PrimBase m) => VS.Stream m a -> m [a]
16+
toLazyList (VS.Stream step s) = w s
17+
where
18+
w s0 = unsafeInterleave $ do
19+
r <- step s0
20+
case r of
21+
VS.Yield x s1 -> do
22+
xs <- w s1
23+
pure $ x : xs
24+
VS.Skip s1 -> w s1
25+
VS.Done -> pure []
26+
27+
toVector :: (PrimMonad m, V.Vector v a) => VS.Stream m a -> m (v a)
28+
toVector = V.unsafeFreeze <=< MV.munstream . flip VB.fromStream VB.Unknown

src/Data/Text/Extra.hs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{-# LANGUAGE MultiWayIf #-}
2+
3+
module Data.Text.Extra
4+
( unsafeCreate,
5+
unsafeCreateUpToN,
6+
unsafeUse,
7+
)
8+
where
9+
10+
import Data.Functor
11+
import Data.Primitive
12+
import Data.Text.Internal qualified as T
13+
import Foreign
14+
import System.IO.Unsafe
15+
16+
unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> T.Text
17+
unsafeCreate len k = unsafeCreateUpToN len $ \ptr -> k ptr $> len
18+
19+
unsafeCreateUpToN :: Int -> (Ptr Word8 -> IO Int) -> T.Text
20+
unsafeCreateUpToN max_len k
21+
| max_len <= 0 = T.empty
22+
| otherwise = unsafePerformIO $ do
23+
mba <- newPinnedByteArray max_len
24+
len <- k (mutableByteArrayContents mba)
25+
ba <- unsafeFreezeByteArray mba
26+
pure $ T.Text ba 0 len
27+
28+
unsafeUse :: T.Text -> (Ptr Word8 -> Int -> IO a) -> a
29+
unsafeUse (T.Text ba off len) k =
30+
unsafePerformIO $
31+
if
32+
| len <= 0 -> k nullPtr 0
33+
| isByteArrayPinned ba -> withByteArrayContents ba $
34+
\ptr -> k (ptr `plusPtr` off) len
35+
| otherwise -> do
36+
mba <- newPinnedByteArray len
37+
withMutableByteArrayContents mba $ \ptr -> do
38+
copyByteArray mba 0 ba off len
39+
k ptr len
40+

0 commit comments

Comments
 (0)