From bae93c3368828195fe8bd44add0e1a665e793eb6 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:34:51 +0900 Subject: [PATCH 1/5] New module: Data.ArrayBuffer.Cast (#46) * Upgrade packages.dhall * New module: Data.ArrayBuffer.Cast --- CHANGELOG.md | 2 ++ packages.dhall | 3 +- spago-test.dhall | 1 - src/Data/ArrayBuffer/Cast.purs | 46 ++++++++++++++++++++++++++ src/Data/ArrayBuffer/ValueMapping.purs | 7 ++-- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/Data/ArrayBuffer/Cast.purs diff --git a/CHANGELOG.md b/CHANGELOG.md index ad44db1..7d83901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Breaking changes: New features: +- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) + Bugfixes: Other improvements: diff --git a/packages.dhall b/packages.dhall index 582d6d3..2ffa9a7 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,4 +1,5 @@ let upstream = - https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221102/packages.dhall + sha256:8628e413718876ce26983db1d0ce9d9e1588129117fa3bb8ed9f618db6914127 in upstream diff --git a/spago-test.dhall b/spago-test.dhall index ab1a012..7037d90 100644 --- a/spago-test.dhall +++ b/spago-test.dhall @@ -5,7 +5,6 @@ in conf // { , "foldable-traversable" , "partial" , "refs" - , "typelevel-prelude" , "tuples" , "quickcheck" , "quickcheck-laws" diff --git a/src/Data/ArrayBuffer/Cast.purs b/src/Data/ArrayBuffer/Cast.purs new file mode 100644 index 0000000..10e5b0a --- /dev/null +++ b/src/Data/ArrayBuffer/Cast.purs @@ -0,0 +1,46 @@ +-- | `DataView` represents unaligned memory of unknown endianness. +-- | +-- | `ArrayView` represents arrays of aligned elements of +-- | local-machine endianness. +-- | For the cases of `Int8Array`, `Uint8Array`, `Uint8ClampedArray`, +-- | the elements +-- | are single bytes, so they are always aligned and they have no +-- | endianness. Therefore in those cases we can freely cast back and forth +-- | to `DataView`. +module Data.ArrayBuffer.Cast + ( fromInt8Array + , fromUint8Array + , fromUint8ClampedArray + , toInt8Array + , toUint8Array + , toUint8ClampedArray + ) where + +import Data.ArrayBuffer.DataView as DV +import Data.ArrayBuffer.Typed as AT +import Data.ArrayBuffer.Types (DataView, Uint8Array, Uint8ClampedArray, Int8Array) +import Effect (Effect) + +-- | Cast an `Int8Array` to a `DataView`. +fromInt8Array :: Int8Array -> Effect DataView +fromInt8Array x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to an `Int8Array`. +toInt8Array :: DataView -> Effect Int8Array +toInt8Array x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) + +-- | Cast a `UInt8Array` to a `DataView`. +fromUint8Array :: Uint8Array -> Effect DataView +fromUint8Array x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to a `Uint8Array`. +toUint8Array :: DataView -> Effect Uint8Array +toUint8Array x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) + +-- | Cast a `UInt8ClampedArray` to a `DataView`. +fromUint8ClampedArray :: Uint8ClampedArray -> Effect DataView +fromUint8ClampedArray x = DV.part (AT.buffer x) (AT.byteOffset x) (AT.byteLength x) + +-- | Cast a `DataView` to a `Uint8ClampedArray`. +toUint8ClampedArray :: DataView -> Effect Uint8ClampedArray +toUint8ClampedArray x = AT.part (DV.buffer x) (DV.byteOffset x) (DV.byteLength x) diff --git a/src/Data/ArrayBuffer/ValueMapping.purs b/src/Data/ArrayBuffer/ValueMapping.purs index 70ac4f7..8694a19 100644 --- a/src/Data/ArrayBuffer/ValueMapping.purs +++ b/src/Data/ArrayBuffer/ValueMapping.purs @@ -12,7 +12,8 @@ import Data.Float32 (Float32) as F import Data.UInt (UInt) import Type.Proxy (Proxy) --- | Map of each `ArrayViewType` to the number of bytes of storage it requires. +-- | Type-level map of each `ArrayViewType` to the number of bytes of storage +-- | it requires. class BytesPerType (a :: ArrayViewType) where byteWidth :: (Proxy a) -> Int @@ -43,7 +44,8 @@ instance bytesPerTypeFloat32 :: BytesPerType Float32 where instance bytesPerTypeFloat64 :: BytesPerType Float64 where byteWidth _ = 8 --- | Maps a `TypedArray`’s binary casted value to its computable representation in JavaScript. +-- | Type-level map of `TypedArray`’s binary casted value to its +-- | representation in JavaScript. class BinaryValue (a :: ArrayViewType) (t :: Type) | a -> t instance binaryValueUint8Clamped :: BinaryValue Uint8Clamped UInt @@ -56,6 +58,7 @@ instance binaryValueInt8 :: BinaryValue Int8 Int instance binaryValueFloat32 :: BinaryValue Float32 F.Float32 instance binaryValueFloat64 :: BinaryValue Float64 Number +-- | Type-level map of `TypedArray` to its element type name. class ShowArrayViewType (a :: ArrayViewType) (name :: Symbol) | a -> name instance showArrayViewTypeUint8Clamped :: ShowArrayViewType Uint8Clamped "Uint8Clamped" From 42073e2b36742a8f0f10ccfe8237853746501cba Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:38:15 +0900 Subject: [PATCH 2/5] Prep for v13.1.0 --- CHANGELOG.md | 8 +++++-- bower.json | 59 +++++++++++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d83901..7e1187c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,16 @@ Breaking changes: New features: -- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) - Bugfixes: Other improvements: +## [v13.1.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.1.0) - 2022-12-01 + +New features: + +- `Data.ArrayBuffer.Cast` (#46 by @jamesdbrock) + ## [v13.0.0](https://github.com/purescript-contrib/purescript-arraybuffer/releases/tag/v13.0.0) - 2022-04-27 Breaking Changes: diff --git a/bower.json b/bower.json index 74106e6..d7d9ae7 100644 --- a/bower.json +++ b/bower.json @@ -1,33 +1,30 @@ { - "name": "purescript-arraybuffer", - "license": [ - "MIT" - ], - "repository": { - "type": "git", - "url": "https://github.com/purescript-contrib/purescript-arraybuffer" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-arraybuffer-types": "^3.0.2", - "purescript-arrays": "^7.0.0", - "purescript-effect": "^4.0.0", - "purescript-float32": "^2.0.0", - "purescript-functions": "^6.0.0", - "purescript-gen": "^4.0.0", - "purescript-maybe": "^6.0.0", - "purescript-nullable": "^6.0.0", - "purescript-prelude": "^6.0.0", - "purescript-tailrec": "^6.0.0", - "purescript-uint": "^7.0.0", - "purescript-unfoldable": "^6.0.0" - }, - "devDependencies": { - "purescript-quickcheck-laws": "^7.0.0" - } + "name": "purescript-arraybuffer", + "license": [ + "MIT" + ], + "repository": { + "type": "git", + "url": "https://github.com/purescript-contrib/purescript-arraybuffer" + }, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-arraybuffer-types": "^v3.0.2", + "purescript-arrays": "^v7.1.0", + "purescript-effect": "^v4.0.0", + "purescript-float32": "^v2.0.0", + "purescript-functions": "^v6.0.0", + "purescript-gen": "^v4.0.0", + "purescript-maybe": "^v6.0.0", + "purescript-nullable": "^v6.0.0", + "purescript-prelude": "^v6.0.1", + "purescript-tailrec": "^v6.1.0", + "purescript-uint": "^v7.0.0", + "purescript-unfoldable": "^v6.0.0" + } } From 374df82368b9b43cae6b71515c0a21de0e0c3592 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:48:03 +0900 Subject: [PATCH 3/5] =?UTF-8?q?v13.0.0=20=E2=86=92=20v13.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 1b5d3fb046e97547c54e9ffe1d7081c7e7457620 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 17:57:45 +0900 Subject: [PATCH 4/5] Remove npx pulp test from CI (#47) --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9d110d..28243e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,3 @@ jobs: npm install bower pulp@16.0.0-0 npx bower install npx pulp build -- --censor-lib --strict - if [ -d "test" ]; then - npx pulp test - fi From 6cc31540ad2bd3ba717f084717e5210938308498 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 18:00:13 +0900 Subject: [PATCH 5/5] =?UTF-8?q?v13.1.0=20=E2=86=92=20v13.1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit