Skip to content

Commit 1d1e709

Browse files
authored
Merge pull request #24 from jacereda/v10
V10
2 parents cbeffc5 + 87e3d4f commit 1d1e709

File tree

20 files changed

+2069
-394
lines changed

20 files changed

+2069
-394
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules/
66
.psci_modules/
77
yarn-error.log
88
yarn.lock
9+
generated-docs/

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
sudo: required
3+
dist: trusty
4+
node_js: 8
5+
install:
6+
- npm install -g purescript pulp bower
7+
script:
8+
- bower install
9+
- pulp test

bower.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616
"purescript-arraybuffer-types": "^2.0.0",
1717
"purescript-maybe": "^4.0.0",
1818
"purescript-effect": "^2.0.0",
19-
"purescript-uint": "^5.0.0"
19+
"purescript-nullable": "^4.1.0",
20+
"purescript-typelevel": "^4.0.0",
21+
"purescript-uint": "^5.1.0",
22+
"purescript-sized-vectors": "^3.1.0",
23+
"purescript-partial": "^2.0.0",
24+
"purescript-float32": "~0.1.1"
2025
},
2126
"devDependencies": {
2227
"purescript-debug": "^4.0.0",
23-
"purescript-quickcheck": "^5.0.0"
28+
"purescript-quickcheck": "^5.0.0",
29+
"purescript-quickcheck-combinators": "~0.1.0",
30+
"purescript-quickcheck-laws": "^4.0.0"
2431
}
2532
}

src/Data/ArrayBuffer/ArrayBuffer.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,14 @@
22

33
// module Data.ArrayBuffer.ArrayBuffer
44

5-
exports.create = function(s) {
6-
return function () {
5+
exports.emptyImpl = function empty (s) {
76
return new ArrayBuffer(s);
8-
};
97
};
108

11-
exports.byteLength = function(a) {
12-
return a.byteLength;
9+
exports.byteLength = function byteLength (a) {
10+
return a.byteLength;
1311
};
1412

15-
exports.sliceImpl = function(s, e, a) {
16-
return function () {
13+
exports.sliceImpl = function sliceImpl (a, s, e) {
1714
return a.slice(s, e);
18-
};
19-
};
20-
21-
exports.fromArray = function(s) {
22-
return (new Uint8Array(s)).buffer;
23-
};
24-
25-
exports.fromIntArray = function(s) {
26-
return (new Uint8Array(s)).buffer;
2715
};
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
module Data.ArrayBuffer.ArrayBuffer ( create
2-
, byteLength
3-
, slice
4-
, fromArray
5-
, fromIntArray
6-
) where
1+
-- | This module represents the functional bindings to JavaScript's `ArrayBuffer`
2+
-- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) for details.
3+
4+
module Data.ArrayBuffer.ArrayBuffer
5+
( empty
6+
, byteLength
7+
, slice
8+
) where
79

810
import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength)
911
import Data.Function.Uncurried (Fn3, runFn3)
1012
import Effect (Effect)
11-
13+
import Effect.Uncurried (EffectFn1, runEffectFn1)
1214

1315
-- | Create an `ArrayBuffer` with the given capacity.
14-
foreign import create :: ByteLength -> Effect ArrayBuffer
16+
empty :: ByteLength -> Effect ArrayBuffer
17+
empty l = runEffectFn1 emptyImpl l
18+
foreign import emptyImpl :: EffectFn1 ByteLength ArrayBuffer
1519

1620
-- | Represents the length of an `ArrayBuffer` in bytes.
1721
foreign import byteLength :: ArrayBuffer -> ByteLength
1822

19-
foreign import sliceImpl :: Fn3 ByteOffset ByteOffset ArrayBuffer (Effect ArrayBuffer)
20-
2123
-- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive.
22-
slice :: ByteOffset -> ByteOffset -> ArrayBuffer -> Effect ArrayBuffer
23-
slice = runFn3 sliceImpl
24-
25-
-- | Convert an array into an `ArrayBuffer` representation.
26-
foreign import fromArray :: Array Number -> ArrayBuffer
27-
28-
-- | Convert an array into an `ArrayBuffer` representation.
29-
foreign import fromIntArray :: Array Int -> ArrayBuffer
24+
slice :: ByteOffset -> ByteOffset -> ArrayBuffer -> ArrayBuffer
25+
slice s e a = runFn3 sliceImpl a s e
26+
foreign import sliceImpl :: Fn3 ArrayBuffer ByteOffset ByteOffset ArrayBuffer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Data.ArrayBuffer.ArrayBuffer.Gen where
2+
3+
import Control.Monad.Gen.Class (class MonadGen)
4+
import Data.ArrayBuffer.Typed (buffer)
5+
import Data.ArrayBuffer.Typed.Gen (genTypedArray, genUint8)
6+
import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array)
7+
import Prelude ((<$>))
8+
9+
10+
genArrayBuffer :: forall m
11+
. MonadGen m
12+
=> m ArrayBuffer
13+
genArrayBuffer = buffer <$> (genTypedArray genUint8 :: m Uint8Array)

src/Data/ArrayBuffer/DataView.js

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,41 @@
33
// module Data.ArrayBuffer.DataView
44

55

6-
exports.whole = function(b) {
7-
return new DataView(b);
8-
}
9-
10-
exports.sliceImpl = function(just, nothing, s, l, b) {
11-
return ((s + l)>>>0) <= b.byteLength ? just(new DataView(b, s, l)) : nothing;
12-
}
13-
14-
exports.buffer = function(v) {
15-
return v.buffer;
16-
}
17-
18-
exports.byteOffset = function(v) {
19-
return v.byteOffset;
20-
}
21-
22-
exports.byteLength = function(v) {
23-
return v.byteLength;
24-
}
25-
26-
exports.getterImpl = function(just, nothing, s, l, e, v, o) {
27-
return function() {
28-
return ((o + l)>>>0) <= v.byteLength? just(v[s].call(v,o,e)) : nothing;
29-
};
30-
}
31-
32-
exports.setter = function(s) {
33-
return function(e) {
34-
return function(v) {
35-
var f = v[s];
36-
return function(n) {
37-
return function(o) {
38-
return function() {
39-
f.call(v,o,n,e);
40-
};
41-
};
42-
};
43-
};
44-
};
45-
}
6+
exports.whole = function whole (b) {
7+
return new DataView(b);
8+
};
9+
10+
exports.remainderImpl = function remainderImpl (b,i) {
11+
return new DataView(b,i);
12+
};
13+
14+
exports.partImpl = function partImpl (b,i,j) {
15+
return new DataView(b,i,j);
16+
};
17+
18+
exports.buffer = function buffer (v) {
19+
return v.buffer;
20+
};
21+
22+
exports.byteOffset = function byteOffset (v) {
23+
return v.byteOffset;
24+
};
25+
26+
exports.byteLength = function byteLength (v) {
27+
return v.byteLength;
28+
};
29+
30+
exports.getterImpl = function getterImpl (data, v, o) {
31+
return ((o + data.bytesPerValue) >>> 0) <= v.byteLength
32+
? v[data.functionName].call(v,o,data.littleEndian)
33+
: null;
34+
};
35+
36+
exports.setterImpl = function setterImpl (data, v, o, n) {
37+
if (((o + data.bytesPerValue) >>> 0) <= v.byteLength) {
38+
v[data.functionName].call(v,o,n,data.littleEndian);
39+
return true;
40+
} else {
41+
return false;
42+
}
43+
};

0 commit comments

Comments
 (0)