Skip to content

Commit e7508aa

Browse files
committed
feat: add a WIP wasm/module-wrapper package
1 parent 33c18e1 commit e7508aa

File tree

10 files changed

+973
-0
lines changed

10 files changed

+973
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Module
22+
23+
> WebAssembly module wrapper.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var Module = require( '@stdlib/wasm/module-wrapper' );
41+
```
42+
43+
#### Module( binary, memory\[, imports] )
44+
45+
Returns a new WebAssembly module wrapper instance.
46+
47+
```javascript
48+
// TO-DO: example
49+
```
50+
51+
The function accepts the following arguments:
52+
53+
- **binary**: WebAssembly binary code.
54+
- **memory**: WebAssembly [memory][@stdlib/wasm/memory] instance.
55+
- **imports**: WebAssembly module imports object.
56+
57+
* * *
58+
59+
<a name="prop-buffer"></a>
60+
61+
#### Module.prototype.buffer
62+
63+
**Read-only** property which returns a WebAssembly memory buffer as a `Uint8Array`.
64+
65+
```javascript
66+
// TO-DO: example
67+
```
68+
69+
* * *
70+
71+
### Methods
72+
73+
<a name="method-is-view"></a>
74+
75+
#### Module.prototype.isView( arr )
76+
77+
Returns a boolean indicating whether a provided list of values is a view of the underlying memory of the WebAssembly module.
78+
79+
```javascript
80+
// TO-DO: example
81+
```
82+
83+
</section>
84+
85+
<!-- /.usage -->
86+
87+
* * *
88+
89+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
90+
91+
<section class="notes">
92+
93+
</section>
94+
95+
<!-- /.notes -->
96+
97+
<!-- Package usage examples. -->
98+
99+
<section class="examples">
100+
101+
## Examples
102+
103+
<!-- eslint no-undef: "error" -->
104+
105+
```javascript
106+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
107+
var Module = require( '@stdlib/wasm/module-wrapper' );
108+
109+
function main() {
110+
if ( !hasWebAssemblySupport() ) {
111+
console.error( 'Environment does not support WebAssembly.' );
112+
return;
113+
}
114+
console.log( typeof Module ); // TO-DO: write example
115+
}
116+
117+
main();
118+
```
119+
120+
</section>
121+
122+
<!-- /.examples -->
123+
124+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
125+
126+
<section class="references">
127+
128+
</section>
129+
130+
<!-- /.references -->
131+
132+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
133+
134+
<section class="related">
135+
136+
</section>
137+
138+
<!-- /.related -->
139+
140+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
141+
142+
<section class="links">
143+
144+
[@stdlib/wasm/memory]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/memory
145+
146+
</section>
147+
148+
<!-- /.links -->
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pkg = require( './../package.json' ).name;
25+
var Module = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+'::constructor', function benchmark( b ) {
31+
var out;
32+
var i;
33+
34+
b.tic();
35+
for ( i = 0; i < b.iterations; i++ ) {
36+
// TODO: write benchmark
37+
if ( out !== void 0 || typeof Module !== 'function' ) { // TODO: update
38+
b.fail( 'TODO: fixme' );
39+
}
40+
}
41+
b.toc();
42+
if ( out !== void 0 || typeof Module !== 'function' ) { // TODO: update
43+
b.fail( 'TODO: fixme' );
44+
}
45+
b.pass( 'benchmark finished' );
46+
b.end();
47+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( binary, memory[, imports] )
3+
WebAssembly module wrapper constructor.
4+
5+
TODO: document methods and properties
6+
7+
Parameters
8+
----------
9+
binary: Uint8Array|ArrayBuffer
10+
WebAssembly binary code.
11+
12+
memory: Memory
13+
WebAssembly memory instance.
14+
15+
imports: Object (optional)
16+
WebAssembly module import object.
17+
18+
Returns
19+
-------
20+
out: Object
21+
WebAssembly module wrapper instance.
22+
23+
Examples
24+
--------
25+
> var m = new {{alias}}();
26+
27+
See Also
28+
--------
29+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Class for creating a WebAssembly module wrapper.
23+
*/
24+
declare class Module { // eslint-disable-line @typescript-eslint/no-extraneous-class
25+
/**
26+
* WebAssembly module wrapper constructor.
27+
*
28+
* @returns module wrapper instance
29+
*
30+
* @example
31+
* var mod = new Module();
32+
*
33+
* // TODO: add example and docs
34+
*/
35+
constructor();
36+
}
37+
38+
39+
// EXPORTS //
40+
41+
export = Module;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable @typescript-eslint/no-unused-expressions */
20+
21+
import Module = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The function returns a module wrapper instance...
27+
{
28+
new Module(); // $ExpectType Module
29+
}
30+
31+
// TODO: add tests
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
22+
var Module = require( './../lib' );
23+
24+
function main() {
25+
if ( !hasWebAssemblySupport() ) {
26+
console.error( 'Environment does not support WebAssembly.' );
27+
return;
28+
}
29+
console.log( typeof Module ); // TODO: write example
30+
}
31+
32+
main();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* WebAssembly module wrapper.
23+
*
24+
* @module @stdlib/wasm/module-wrapper
25+
*
26+
* @example
27+
* var Module = require( '@stdlib/wasm/module-wrapper' );
28+
*
29+
* // TODO
30+
*/
31+
32+
// MODULES //
33+
34+
var main = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = main;

0 commit comments

Comments
 (0)