Skip to content

Redesign #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 131 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
53c7b23
ripping out untrue functionality of arraybuffers
athanclark Dec 4, 2018
97a49c6
rename to stay true to implementation
athanclark Dec 4, 2018
d650148
converting to Effect.Uncurried, using exception catching, naming
athanclark Dec 4, 2018
a4c7cd0
module documentation
athanclark Dec 4, 2018
addf664
preparing for major redesign of typed interface - supporting all
athanclark Dec 4, 2018
5200641
polyfill
athanclark Dec 4, 2018
5d49921
module doc
athanclark Dec 4, 2018
75a91e6
using `new` as binder - also, remainder function
athanclark Dec 4, 2018
827b29e
copyWithin
athanclark Dec 4, 2018
7a3435f
all, any ~ every, some
athanclark Dec 4, 2018
ba3f089
fill semantics
athanclark Dec 4, 2018
b203cd9
toString
athanclark Dec 4, 2018
e2b70aa
subarray
athanclark Dec 4, 2018
16f384c
in-place sort
athanclark Dec 4, 2018
95a79cb
slice
athanclark Dec 4, 2018
b281b9d
moving `set` around a little
athanclark Dec 4, 2018
f8ae9ad
reverse in-place
athanclark Dec 4, 2018
be5e28b
typed map
athanclark Dec 4, 2018
f2be9a4
joining an array
athanclark Dec 4, 2018
fa53dca
filter
athanclark Dec 4, 2018
a3da940
toArray typed properly
athanclark Dec 4, 2018
588284d
folds
athanclark Dec 4, 2018
3b246b9
elem, need to do find and indexing
athanclark Dec 4, 2018
4759fe4
better arraybuffer slice, more stuff
athanclark Dec 4, 2018
aa789b7
the uint library stores values greater than 2^31 as a negative integer -
athanclark Dec 4, 2018
d0c4038
index of
athanclark Dec 6, 2018
2ffbb00
more instances
athanclark Dec 6, 2018
3c7066e
honestly I forgot about floating points
athanclark Dec 6, 2018
fd29b0b
the binary serialization of javascript Numbers for TypedArrays follows
athanclark Dec 6, 2018
ea66b5f
Remove text encoding dependency
AlexaDeWit Dec 6, 2018
00d4a2e
Remove show and update readme
AlexaDeWit Dec 6, 2018
71b5b08
generation functions - need to generate a bona-fide float32
athanclark Dec 6, 2018
4a83a72
arbitrary floating point values
athanclark Dec 6, 2018
3adab9e
more correct
athanclark Dec 6, 2018
e84aec7
more generators
athanclark Dec 6, 2018
350c48f
simple byteLength / bytesPerValue === length test
athanclark Dec 6, 2018
b848ecb
fromArray <<< toArray iso
athanclark Dec 6, 2018
f7b256e
better docs
athanclark Dec 8, 2018
875662e
cosmetic
athanclark Dec 8, 2018
89da71d
using uint
athanclark Dec 8, 2018
f939172
fill y xs => all (== y) xs
athanclark Dec 10, 2018
3b0f0ab
generic instance of `WithOffset` structure
athanclark Dec 11, 2018
cb63506
cosmetic, with offset
athanclark Dec 12, 2018
fa8d1b6
removed funky show module
athanclark Dec 12, 2018
bb4f0f3
set singleton is eq
athanclark Dec 12, 2018
d73a98c
all implies any
athanclark Dec 13, 2018
e8324a1
filter, all / any
athanclark Dec 13, 2018
9f09755
elem with unsafeAt
athanclark Dec 13, 2018
2d7e141
any implies find
athanclark Dec 13, 2018
097e8ad
findIndex implies at
athanclark Dec 13, 2018
ab5d578
indexOf implies at
athanclark Dec 13, 2018
2764959
lastIndexOf imples at
athanclark Dec 13, 2018
24ff499
quickcheck combinators
athanclark Dec 13, 2018
7fb380c
cosmetic
athanclark Dec 13, 2018
9415877
sort is idempotent, reverse tests
Dec 13, 2018
22326b1
sort is correct
Dec 13, 2018
1031fd2
toString
Dec 13, 2018
7482f4d
dual subArray and slice references
Dec 13, 2018
44cc05d
really weird test results - subArray isn't mutable when supplied with…
Dec 13, 2018
d585392
peculiar behavior of subArray
Dec 13, 2018
2233a4d
verifying the mutability of whole subArrays
Dec 13, 2018
1919471
better docs
Dec 13, 2018
e892216
misimplementation
Dec 13, 2018
75d5c6c
copy within self
Dec 13, 2018
ca0b7d3
copyWithin verified
Dec 14, 2018
8bd3651
more verification for copyWithin
Dec 14, 2018
b3c0a1f
gen arraybuffer and dataview
Dec 14, 2018
1a65829
more qualified imports
Dec 14, 2018
daa72e0
using inline ternary op
Dec 14, 2018
c909bd4
different gen paradigm
Dec 14, 2018
bcd0877
moving classes around - safe dataView modification
Dec 15, 2018
7148150
generating a data view with an offset, for a particular value
athanclark Dec 15, 2018
4f455d3
properly using uint
athanclark Dec 15, 2018
1dcde72
runners
athanclark Dec 15, 2018
2776488
using type-declared value sizes
athanclark Dec 15, 2018
5ce319b
verified data views
athanclark Dec 15, 2018
2fe5c9a
cosmetic
athanclark Dec 15, 2018
e4aed3a
better docs, noting how subArray / new use Data.ArrayBuffer.ArrayBuff…
Dec 15, 2018
d00e77b
reformatting arguments
Dec 15, 2018
2e5bf9f
final touch-ups
Dec 15, 2018
95bf30e
removing obsolete tests
Dec 15, 2018
e1689db
removed generated docs
Dec 19, 2018
29a14f8
omitting `try` in DataView.js
athanclark Jan 3, 2019
70e864b
Merge branch 'redesign' of github.com:athanclark/purescript-arraybuff…
athanclark Jan 3, 2019
289a9e9
better code re-use
athanclark Jan 3, 2019
9e8b567
fixing implementation
Jan 6, 2019
c5a1af4
reorganized setter
Jan 6, 2019
7f4819e
better design
Jan 6, 2019
f9f9d2b
omitting Arbitrary constraint
Jan 9, 2019
b066a6c
cosmetic
Jan 9, 2019
03469ac
Merge v9-redesign2
jacereda Jan 17, 2019
fdccca3
Some cosmetic changes and fixes.
jacereda Jan 17, 2019
6576b17
Sort includes
jacereda Jan 17, 2019
970351c
Sort includes
jacereda Jan 17, 2019
a880ebb
Still not happy with the names, renamed generators
jacereda Jan 17, 2019
2a2795b
toNullable Nothing -> null
jacereda Jan 17, 2019
316f099
toNullable . Just - > notNull
jacereda Jan 17, 2019
cfd98c5
Typo
jacereda Jan 17, 2019
83370eb
pure functions for filtering & querying
Jan 17, 2019
1b4aad4
Cherry-pick 83370eb9f96aa1638f1c532d0d4c10bdad295d1c, Uint32 instance…
Jan 17, 2019
d17d6c7
Fix the tests
jacereda Jan 18, 2019
eac7856
These share the implementation...
jacereda Jan 18, 2019
8ae9e7c
... and don't need to be part of the type class
jacereda Jan 18, 2019
c11a9c0
These can also be removed from the type class
jacereda Jan 18, 2019
be68a82
Simplify slice
jacereda Jan 18, 2019
ab94c97
Simplify subArray
jacereda Jan 18, 2019
120a692
Merge branch 'v9' of git://github.com/jacereda/purescript-arraybuffer…
Jan 18, 2019
48cff7a
unsafeAt should be like unsafeIndex in arrays
jacereda Jan 18, 2019
48d5826
Simplify fill
jacereda Jan 18, 2019
e08e284
Better name
jacereda Jan 18, 2019
17cf881
Use notNull
jacereda Jan 18, 2019
2b7b502
WIP, generate arrays with the size provided by QC, split functions th…
jacereda Jan 18, 2019
b4a9b19
Cleanup
jacereda Jan 18, 2019
a30e602
Fix set/setTyped
jacereda Jan 18, 2019
42f588f
Cleanup
jacereda Jan 18, 2019
8ee1263
Fix allImpliesAnyTests
jacereda Jan 18, 2019
7cde026
Use unsigned
jacereda Jan 19, 2019
95c4abc
Disable DataView tests
jacereda Jan 19, 2019
01c657e
Simplifying
jacereda Jan 19, 2019
491c92e
Introduce overAll1 to test over non-empty arrays
jacereda Jan 19, 2019
fa85219
using external float32 library
Jan 19, 2019
58cd006
WIP, making API more consistent with foldable-traversable methods
jacereda Jan 20, 2019
436819b
Merge master
jacereda Jan 22, 2019
07a501f
Enabled DataView tests
jacereda Jan 24, 2019
fde881b
Saturate arguments for runEffectFnX
jacereda Jan 24, 2019
4968226
Saturate arguments for run(Effect)FnX
jacereda Jan 24, 2019
23c5135
Make empty effectful
jacereda Jan 25, 2019
86fd6e8
Restore specific setters/getters in the API, changed implementation
jacereda Jan 25, 2019
e06a9a2
Merge branch 'v10' of git://github.com/jacereda/purescript-arraybuffe…
athanclark Jan 25, 2019
0fa0d7a
fixing tests
athanclark Jan 25, 2019
45f310a
restricted imports
athanclark Jan 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules/
.psci_modules/
yarn-error.log
yarn.lock
generated-docs/
11 changes: 9 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
"purescript-arraybuffer-types": "^2.0.0",
"purescript-maybe": "^4.0.0",
"purescript-effect": "^2.0.0",
"purescript-uint": "^5.0.0"
"purescript-nullable": "^4.1.0",
"purescript-typelevel": "^4.0.0",
"purescript-parseint": "^1.1.0",
"purescript-uint": "^5.1.0",
"purescript-sized-vectors": "^3.1.0",
"purescript-float32": "^0.0.1"
},
"devDependencies": {
"purescript-debug": "^4.0.0",
"purescript-quickcheck": "^5.0.0"
"purescript-quickcheck": "^5.0.0",
"purescript-partial": "^2.0.0",
"purescript-quickcheck-combinators": "^0.1.0"
}
}
22 changes: 5 additions & 17 deletions src/Data/ArrayBuffer/ArrayBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@

// module Data.ArrayBuffer.ArrayBuffer

exports.create = function(s) {
return function () {
exports.emptyImpl = function empty (s) {
return new ArrayBuffer(s);
};
};

exports.byteLength = function(a) {
return a.byteLength;
exports.byteLength = function byteLength (a) {
return a.byteLength;
};

exports.sliceImpl = function(s, e, a) {
return function () {
return a.slice(s, e);
};
};

exports.fromArray = function(s) {
return (new Uint8Array(s)).buffer;
};

exports.fromIntArray = function(s) {
return (new Uint8Array(s)).buffer;
exports.sliceImpl = function sliceImpl (a, ms, me) {
return me === null ? (ms === null ? a.slice() : a.slice(ms)) : a.slice(ms,me);
};
40 changes: 24 additions & 16 deletions src/Data/ArrayBuffer/ArrayBuffer.purs
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
module Data.ArrayBuffer.ArrayBuffer ( create
, byteLength
, slice
, fromArray
, fromIntArray
) where
-- | This module represents the functional bindings to JavaScript's `ArrayBuffer`
-- | objects. See [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) for details.

module Data.ArrayBuffer.ArrayBuffer
( empty
, byteLength
, slice
) where

import Data.ArrayBuffer.Types (ArrayBuffer, ByteOffset, ByteLength)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, notNull, null)
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Uncurried (EffectFn1, runEffectFn1)


foreign import emptyImpl :: EffectFn1 ByteLength ArrayBuffer


-- | Create an `ArrayBuffer` with the given capacity.
foreign import create :: ByteLength -> Effect ArrayBuffer
empty :: ByteLength -> Effect ArrayBuffer
empty l = runEffectFn1 emptyImpl l

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

foreign import sliceImpl :: Fn3 ByteOffset ByteOffset ArrayBuffer (Effect ArrayBuffer)
foreign import sliceImpl :: Fn3 ArrayBuffer (Nullable ByteOffset) (Nullable ByteOffset) ArrayBuffer

-- | Returns a new `ArrayBuffer` whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive.
slice :: ByteOffset -> ByteOffset -> ArrayBuffer -> Effect ArrayBuffer
slice = runFn3 sliceImpl

-- | Convert an array into an `ArrayBuffer` representation.
foreign import fromArray :: Array Number -> ArrayBuffer

-- | Convert an array into an `ArrayBuffer` representation.
foreign import fromIntArray :: Array Int -> ArrayBuffer
slice :: ArrayBuffer -> Maybe (Tuple ByteOffset (Maybe ByteOffset)) -> ArrayBuffer
slice a mz = case mz of
Nothing -> runFn3 sliceImpl a null null
Just (Tuple s me) -> case me of
Nothing -> runFn3 sliceImpl a (notNull s) null
Just e -> runFn3 sliceImpl a (notNull s) (notNull e)
13 changes: 13 additions & 0 deletions src/Data/ArrayBuffer/ArrayBuffer/Gen.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Data.ArrayBuffer.ArrayBuffer.Gen where

import Control.Monad.Gen.Class (class MonadGen)
import Data.ArrayBuffer.Typed (buffer)
import Data.ArrayBuffer.Typed.Gen (genTypedArray, genUint8)
import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array)
import Prelude ((<$>))


genArrayBuffer :: forall m
. MonadGen m
=> m ArrayBuffer
genArrayBuffer = buffer <$> (genTypedArray genUint8 :: m Uint8Array)
78 changes: 38 additions & 40 deletions src/Data/ArrayBuffer/DataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,41 @@
// module Data.ArrayBuffer.DataView


exports.whole = function(b) {
return new DataView(b);
}

exports.sliceImpl = function(just, nothing, s, l, b) {
return ((s + l)>>>0) <= b.byteLength ? just(new DataView(b, s, l)) : nothing;
}

exports.buffer = function(v) {
return v.buffer;
}

exports.byteOffset = function(v) {
return v.byteOffset;
}

exports.byteLength = function(v) {
return v.byteLength;
}

exports.getterImpl = function(just, nothing, s, l, e, v, o) {
return function() {
return ((o + l)>>>0) <= v.byteLength? just(v[s].call(v,o,e)) : nothing;
};
}

exports.setter = function(s) {
return function(e) {
return function(v) {
var f = v[s];
return function(n) {
return function(o) {
return function() {
f.call(v,o,n,e);
};
};
};
};
};
}
exports.whole = function whole (b) {
return new DataView(b);
};

exports.remainderImpl = function remainderImpl (b,i) {
return new DataView(b,i);
};

exports.partImpl = function partImpl (b,i,j) {
return new DataView(b,i,j);
};

exports.buffer = function buffer (v) {
return v.buffer;
};

exports.byteOffset = function byteOffset (v) {
return v.byteOffset;
};

exports.byteLength = function byteLength (v) {
return v.byteLength;
};

exports.getterImpl = function getterImpl (data, v, o) {
return ((o + data.bytesPerValue) >>> 0) <= v.byteLength
? data.just (v[data.functionName].call(v,o,data.littleEndian))
: data.nothing;
};

exports.setterImpl = function setterImpl (data, v, o, n) {
if (((o + data.bytesPerValue) >>> 0) <= v.byteLength) {
v[data.functionName].call(v,o,n,data.littleEndian);
return true;
} else {
return false;
}
};
Loading