Skip to content

Commit f073271

Browse files
committed
Updates for 0.7
1 parent a44dc73 commit f073271

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

src/Data/ArrayBuffer/ArrayBuffer.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
// module Data.ArrayBuffer.ArrayBuffer
4+
5+
exports.create = function(s) {
6+
return new ArrayBuffer(s);
7+
}
8+
9+
exports.byteLength = function(a) {
10+
return a.byteLength;
11+
}
12+
13+
exports.sliceImpl = function(s, e, a) {
14+
return a.slice(s,e);
15+
}
16+
17+
exports.fromArray = function(s) {
18+
return (new Uint8Array(s)).buffer;
19+
}
20+
21+
exports.fromString = function(s) {
22+
var l = s.length;
23+
var ab = new ArrayBuffer(l * 2);
24+
var a = new Uint16Array(ab);
25+
for (var i = 0; i < l; i++)
26+
a[i] = s.charCodeAt(i);
27+
return ab;
28+
}

src/Data/ArrayBuffer/DataView.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
3+
// module Data.ArrayBuffer.DataView
4+
5+
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 <= 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, v, o) {
27+
return function() {
28+
return (o + l) <= v.byteLength? just(v[s].call(v,o)) : nothing;
29+
};
30+
}
31+
32+
exports.setter = function(s) {
33+
return function(v) {
34+
var f = v[s];
35+
return function(n) {
36+
return function(o) {
37+
return function() {
38+
f.call(v,o,n);
39+
};
40+
};
41+
};
42+
};
43+
}

src/Data/ArrayBuffer/Show.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
// module Show
4+
5+
exports.showImpl = function(a) {
6+
return require('util').inspect(a);
7+
}

src/Data/ArrayBuffer/Typed.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use strict";
2+
3+
// module Data.ArrayBuffer.Typed
4+
5+
exports.asInt8Array = function(v) {
6+
return new Int8Array(v.buffer, v.byteOffset, v.byteLength);
7+
}
8+
9+
exports.asInt16Array = function(v) {
10+
return new Int16Array(v.buffer, v.byteOffset, v.byteLength >>> 1);
11+
}
12+
13+
exports.asInt32Array = function(v) {
14+
return new Int32Array(v.buffer, v.byteOffset, v.byteLength >>> 2);
15+
}
16+
17+
exports.asUint8Array = function(v) {
18+
return new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
19+
}
20+
21+
exports.asUint16Array = function(v) {
22+
return new Uint16Array(v.buffer, v.byteOffset, v.byteLength >>> 1);
23+
}
24+
25+
exports.asUint32Array = function(v) {
26+
return new Uint32Array(v.buffer, v.byteOffset, v.byteLength >>> 2);
27+
}
28+
29+
exports.asUint8ClampedArray = function(v) {
30+
return new Uint8ClampedArray(v.buffer, v.byteOffset, v.byteLength);
31+
}
32+
33+
exports.asFloat32Array = function(v) {
34+
return new Float32Array(v.buffer, v.byteOffset, v.byteLength >>> 2);
35+
}
36+
37+
exports.asFloat64Array = function(v) {
38+
return new Float64Array(v.buffer, v.byteOffset, v.byteLength >>> 3);
39+
}
40+
41+
exports.dataView = function(a) {
42+
return a;
43+
}
44+
45+
exports.setImpl = function(ra, off, a) {
46+
return function() {
47+
a.set(ra, off);
48+
};
49+
}
50+
51+
exports.unsafeAtImpl = function(a, i) {
52+
return a[i];
53+
}
54+
55+
exports.hasIndexImpl = function(a, i) {
56+
return i in a;
57+
}
58+
59+
exports.toArray = function(a) {
60+
var l = a.length;
61+
var ret = new Array(l);
62+
for (var i = 0; i < l; i++)
63+
ret[i] = a[i];
64+
return ret;
65+
}

0 commit comments

Comments
 (0)