Skip to content

Commit 375104a

Browse files
committed
feat: add wasm/types
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 6dff3f6 commit 375104a

File tree

10 files changed

+582
-0
lines changed

10 files changed

+582
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# Type Declarations
22+
23+
> WebAssembly TypeScript type declarations.
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+
```typescript
40+
/// <reference types="@stdlib/wasm/types"/>
41+
42+
import { Memory } from '@stdlib/wasm/types';
43+
44+
// TODO: more extensive example
45+
```
46+
47+
For the complete list of declared types, see the `index.d.ts` type declaration file.
48+
49+
TODO: explicitly document exported types
50+
51+
</section>
52+
53+
<!-- /.usage -->
54+
55+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
56+
57+
<section class="notes">
58+
59+
## Notes
60+
61+
- In order to use included TypeScript declarations, configure your `tsconfig.json` file accordingly. For example,
62+
63+
```text
64+
{
65+
"compilerOptions": {
66+
...
67+
"typeRoots": [ "./path/to/@stdlib/wasm/types" ],
68+
...
69+
},
70+
...
71+
}
72+
```
73+
74+
</section>
75+
76+
<!-- /.notes -->
77+
78+
<!-- Package usage examples. -->
79+
80+
<section class="examples">
81+
82+
</section>
83+
84+
<!-- /.examples -->
85+
86+
<!-- 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. -->
87+
88+
<section class="references">
89+
90+
</section>
91+
92+
<!-- /.references -->
93+
94+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
95+
96+
<section class="related">
97+
98+
</section>
99+
100+
<!-- /.related -->
101+
102+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
103+
104+
<section class="links">
105+
106+
</section>
107+
108+
<!-- /.links -->
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 dir = require( './../lib' );
22+
23+
console.log( dir );
24+
// => <string>
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/// <reference types="@stdlib/types"/>
22+
23+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* WebAssembly memory interface.
27+
*/
28+
export interface Memory {
29+
/**
30+
* Underlying `ArrayBuffer` (or `SharedArrayBuffer`) associated with a memory instance.
31+
*/
32+
buffer: ArrayBuffer;
33+
34+
/**
35+
* Increases the size of the memory instance by a specified number of WebAssembly pages (i.e., 64KiB).
36+
*
37+
* ## Notes
38+
*
39+
* - Upon increasing the size, the previous `ArrayBuffer` is detached, thus invalidating any typed arrays which were views over the previous `ArrayBuffer`.
40+
* - Detachment means that the previous `ArrayBuffer` byte length becomes zero, and it no longer has bytes accessible to JavaScript.
41+
* - `ArrayBuffer` detachment applies even when `delta` is zero.
42+
* - Detachment only applies for non-shared memory instances. For a shared memory instance, the initial buffer (which is a `SharedArrayBuffer`) will not become detached and, instead, its length will not be updated.
43+
* - Accesses to the `buffer` property after growing a `SharedArrayBuffer` will yield a larger `SharedArrayBuffer` which may access a larger span of memory than the buffer before growing memory.
44+
* - Every `SharedArrayBuffer` accessed via the `buffer` property will always refer to the start of the same memory address range and thus manipulate the same data.
45+
*
46+
* @param delta - number of WebAssembly pages (i.e., 64KiB) by which to grow the underlying memory
47+
* @returns size of the previous `ArrayBuffer` (or `SharedArrayBuffer`)
48+
*/
49+
grow( delta: number ): number;
50+
}
51+
52+
/**
53+
* WebAssembly module wrapper interface.
54+
*/
55+
export interface ModuleWrapper {
56+
/**
57+
* WebAssembly binary code.
58+
*/
59+
binary: Uint8Array;
60+
61+
/**
62+
* WebAssembly memory.
63+
*/
64+
memory: Memory | null;
65+
66+
/**
67+
* WebAssembly memory buffer as a Uint8Array.
68+
*/
69+
buffer: Uint8Array | null;
70+
71+
/**
72+
* WebAssembly memory buffer as a DataView.
73+
*/
74+
view: DataView | null;
75+
76+
/**
77+
* "Raw" WebAssembly module exports.
78+
*/
79+
exports: Object | null;
80+
81+
/**
82+
* Asynchronously initializes a WebAssembly module instance.
83+
*
84+
* @returns promise which resolves upon initializing a WebAssembly module instance
85+
*/
86+
initialize(): Promise<ModuleWrapper>;
87+
88+
/**
89+
* Asynchronously initializes a WebAssembly module instance.
90+
*
91+
* @param clbk - callback to invoke upon initializing a WebAssembly module
92+
*/
93+
initializeAsync( clbk: ( error: Error | null, mod?: ModuleWrapper ) => void ): void;
94+
95+
/**
96+
* Synchronously initializes a WebAssembly module instance.
97+
*
98+
* @returns module wrapper instance
99+
*/
100+
initializeSync(): ModuleWrapper;
101+
102+
/**
103+
* Reallocates the underlying WebAssembly memory instance to a specified number of bytes.
104+
*
105+
* ## Notes
106+
*
107+
* - WebAssembly memory can only **grow**, not shrink. Hence, if provided a number of bytes which is less than or equal to the size of the current memory, the function does nothing.
108+
* - When non-shared memory is resized, the underlying the `ArrayBuffer` is detached, consequently invalidating any associated typed array views. Before resizing non-shared memory, ensure that associated typed array views no longer need byte access and can be garbage collected.
109+
*
110+
* @param nbytes - memory size (in bytes)
111+
* @returns boolean indicating whether the resize operation was successful
112+
*/
113+
realloc( nbytes: number ): boolean;
114+
115+
/**
116+
* Returns a boolean indicating whether the underlying WebAssembly memory instance has the capacity to store a provided list of values starting from a specified byte offset.
117+
*
118+
* @param byteOffset - byte offset at which to start writing values
119+
* @param values - input array containing values to write
120+
* @returns boolean indicating whether the underlying WebAssembly memory instance has enough capacity
121+
*/
122+
hasCapacity( byteOffset: number, values: Collection | AccessorArrayLike<any> ): boolean;
123+
124+
/**
125+
* Returns a boolean indicating whether a provided list of values is a view of the underlying memory of the WebAssembly module.
126+
*
127+
* @param values - input array
128+
* @returns boolean indicating whether the list is a memory view
129+
*/
130+
isView( values: Collection | AccessorArrayLike<any> ): boolean;
131+
132+
/**
133+
* Writes values to the underlying WebAssembly memory instance.
134+
*
135+
* ## Notes
136+
*
137+
* - The function infers element size (i.e., number of bytes per element) from the data type of the input array. For example, if provided a `Float32Array`, the function writes each element as a single-precision floating-point number to the underlying WebAssembly memory instance.
138+
* - In order to write elements as a different data type, you need to perform an explicit cast **before** calling this method. For example, in order to write single-precision floating-point numbers contained in a `Float32Array` as signed 32-bit integers, you must first convert the `Float32Array` to an `Int32Array` before passing the values to this method.
139+
* - If provided an array having an unknown or "generic" data type, elements are written as double-precision floating-point numbers.
140+
*
141+
* @param byteOffset - byte offset at which to start writing values
142+
* @param values - input array containing values to write
143+
* @returns module wrapper instance
144+
*/
145+
write( byteOffset: number, values: Collection | AccessorArrayLike<any> ): ModuleWrapper;
146+
147+
/**
148+
* Reads values from the underlying WebAssembly memory instance.
149+
*
150+
* ## Notes
151+
*
152+
* - The function infers element size (i.e., number of bytes per element) from the data type of the output array. For example, if provided a `Float32Array`, the function reads each element as a single-precision floating-point number from the underlying WebAssembly memory instance.
153+
* - In order to read elements as a different data type, you need to perform an explicit cast **after** calling this method. For example, in order to read single-precision floating-point numbers contained in a `Float32Array` as signed 32-bit integers, you must convert the `Float32Array` to an `Int32Array` after reading memory values using this method.
154+
* - If provided an output array having an unknown or "generic" data type, elements are read as double-precision floating-point numbers.
155+
*
156+
* @param byteOffset - byte offset at which to start reading values
157+
* @param out - output array
158+
* @returns module wrapper instance
159+
*/
160+
read( byteOffset: number, out: Collection | AccessorArrayLike<any> ): ModuleWrapper;
161+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
// MAIN //
22+
23+
var dir = null;
24+
25+
26+
// EXPORTS //
27+
28+
module.exports = dir;
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) 2025 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+
* Absolute file path for the directory containing TypeScript declarations.
23+
*
24+
* @module @stdlib/wasm/types
25+
*
26+
* @example
27+
* var dir = require( '@stdlib/wasm/types' );
28+
*
29+
* console.log( dir );
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)