@thi.ng/wasm-api 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/bridge.js +9 -9
- package/codegen/c11.js +5 -1
- package/package.json +11 -11
- package/string.d.ts +7 -0
- package/string.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-10-
|
|
3
|
+
- **Last updated**: 2022-10-04T17:35:45Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,18 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.13.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.13.0) (2022-10-04)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update C11 code gen ([ff8037f](https://github.com/thi-ng/umbrella/commit/ff8037f))
|
|
17
|
+
- add `#ifdef __cplusplus` guards to pre/post
|
|
18
|
+
- add WasmStringSlice.setSlice() ([50cc798](https://github.com/thi-ng/umbrella/commit/50cc798))
|
|
19
|
+
|
|
20
|
+
#### ⏱ Performance improvements
|
|
21
|
+
|
|
22
|
+
- lazy eval log message args ([3e13397](https://github.com/thi-ng/umbrella/commit/3e13397))
|
|
23
|
+
|
|
12
24
|
## [0.12.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.12.0) (2022-10-03)
|
|
13
25
|
|
|
14
26
|
#### 🚀 Features
|
package/bridge.js
CHANGED
|
@@ -30,7 +30,7 @@ let WasmBridge = class WasmBridge {
|
|
|
30
30
|
this.utf8Decoder = new TextDecoder();
|
|
31
31
|
this.utf8Encoder = new TextEncoder();
|
|
32
32
|
const logN = (x) => this.logger.debug(x);
|
|
33
|
-
const logA = (method) => (addr, len) => this.logger.debug(method(addr, len).join(", "));
|
|
33
|
+
const logA = (method) => (addr, len) => this.logger.debug(() => method(addr, len).join(", "));
|
|
34
34
|
this.api = {
|
|
35
35
|
printI8: logN,
|
|
36
36
|
printU8: logN,
|
|
@@ -42,10 +42,10 @@ let WasmBridge = class WasmBridge {
|
|
|
42
42
|
printU64: (x) => this.logger.debug(x),
|
|
43
43
|
printF32: logN,
|
|
44
44
|
printF64: logN,
|
|
45
|
-
printU8Hex: (x) => this.logger.debug(`0x${U8(x)}`),
|
|
46
|
-
printU16Hex: (x) => this.logger.debug(`0x${U16(x)}`),
|
|
47
|
-
printU32Hex: (x) => this.logger.debug(`0x${U32(x)}`),
|
|
48
|
-
printU64Hex: (x) => this.logger.debug(`0x${U64BIG(x)}`),
|
|
45
|
+
printU8Hex: (x) => this.logger.debug(() => `0x${U8(x)}`),
|
|
46
|
+
printU16Hex: (x) => this.logger.debug(() => `0x${U16(x)}`),
|
|
47
|
+
printU32Hex: (x) => this.logger.debug(() => `0x${U32(x)}`),
|
|
48
|
+
printU64Hex: (x) => this.logger.debug(() => `0x${U64BIG(x)}`),
|
|
49
49
|
_printI8Array: logA(this.getI8Array.bind(this)),
|
|
50
50
|
_printU8Array: logA(this.getU8Array.bind(this)),
|
|
51
51
|
_printI16Array: logA(this.getI16Array.bind(this)),
|
|
@@ -56,8 +56,8 @@ let WasmBridge = class WasmBridge {
|
|
|
56
56
|
_printU64Array: logA(this.getU64Array.bind(this)),
|
|
57
57
|
_printF32Array: logA(this.getF32Array.bind(this)),
|
|
58
58
|
_printF64Array: logA(this.getF64Array.bind(this)),
|
|
59
|
-
_printStr0: (addr) => this.logger.debug(this.getString(addr, 0)),
|
|
60
|
-
_printStr: (addr, len) => this.logger.debug(this.getString(addr, len)),
|
|
59
|
+
_printStr0: (addr) => this.logger.debug(() => this.getString(addr, 0)),
|
|
60
|
+
_printStr: (addr, len) => this.logger.debug(() => this.getString(addr, len)),
|
|
61
61
|
debug: () => {
|
|
62
62
|
debugger;
|
|
63
63
|
},
|
|
@@ -215,7 +215,7 @@ let WasmBridge = class WasmBridge {
|
|
|
215
215
|
const addr = this.exports._wasm_allocate(numBytes);
|
|
216
216
|
if (!addr)
|
|
217
217
|
throw new OutOfMemoryError(`unable to allocate: ${numBytes}`);
|
|
218
|
-
this.logger.fine(`allocated ${numBytes} bytes @ 0x${U32(addr)} .. 0x${U32(addr + numBytes - 1)}`);
|
|
218
|
+
this.logger.fine(() => `allocated ${numBytes} bytes @ 0x${U32(addr)} .. 0x${U32(addr + numBytes - 1)}`);
|
|
219
219
|
this.ensureMemory();
|
|
220
220
|
clear && this.u8.fill(0, addr, addr + numBytes);
|
|
221
221
|
return addr;
|
|
@@ -234,7 +234,7 @@ let WasmBridge = class WasmBridge {
|
|
|
234
234
|
* @param numBytes
|
|
235
235
|
*/
|
|
236
236
|
free(addr, numBytes) {
|
|
237
|
-
this.logger.fine(`freeing memory @ 0x${U32(addr)} .. 0x${U32(addr + numBytes - 1)}`);
|
|
237
|
+
this.logger.fine(() => `freeing memory @ 0x${U32(addr)} .. 0x${U32(addr + numBytes - 1)}`);
|
|
238
238
|
this.exports._wasm_free(addr, numBytes);
|
|
239
239
|
}
|
|
240
240
|
getI8(addr) {
|
package/codegen/c11.js
CHANGED
|
@@ -32,10 +32,14 @@ export const C11 = (opts = {}) => {
|
|
|
32
32
|
const SCOPES = [/\{$/, /^\}[ A-Za-z0-9_]*[;,]?$/];
|
|
33
33
|
const gen = {
|
|
34
34
|
pre: (opts) => `#pragma once
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
extern "C" {
|
|
38
|
+
#endif
|
|
35
39
|
${opts.debug ? "\n#include <stdalign.h>" : ""}
|
|
36
40
|
#include <stddef.h>
|
|
37
41
|
#include <stdint.h>${opts.pre ? `\n${opts.pre}` : ""}`,
|
|
38
|
-
post: () => opts.post
|
|
42
|
+
post: () => `${opts.post ? `${opts.post}\n` : ""}#ifdef __cplusplus\n}\n#endif\n`,
|
|
39
43
|
doc: (doc, acc, opts) => {
|
|
40
44
|
acc.push(...prefixLines("// ", doc, opts.lineWidth));
|
|
41
45
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Generic, modular, extensible API bridge, polyglot glue code and bindings code generators for hybrid JS & WebAssembly projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,22 +37,22 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@thi.ng/api": "^8.4.3",
|
|
40
|
-
"@thi.ng/args": "^2.2.
|
|
40
|
+
"@thi.ng/args": "^2.2.4",
|
|
41
41
|
"@thi.ng/binary": "^3.3.6",
|
|
42
42
|
"@thi.ng/checks": "^3.2.6",
|
|
43
43
|
"@thi.ng/compare": "^2.1.13",
|
|
44
|
-
"@thi.ng/defmulti": "^2.1.
|
|
45
|
-
"@thi.ng/errors": "^2.2.
|
|
46
|
-
"@thi.ng/file-io": "^0.3.
|
|
44
|
+
"@thi.ng/defmulti": "^2.1.17",
|
|
45
|
+
"@thi.ng/errors": "^2.2.2",
|
|
46
|
+
"@thi.ng/file-io": "^0.3.14",
|
|
47
47
|
"@thi.ng/hex": "^2.2.1",
|
|
48
|
-
"@thi.ng/idgen": "^2.1.
|
|
49
|
-
"@thi.ng/logger": "^1.
|
|
50
|
-
"@thi.ng/paths": "^5.1.
|
|
51
|
-
"@thi.ng/strings": "^3.3.
|
|
48
|
+
"@thi.ng/idgen": "^2.1.15",
|
|
49
|
+
"@thi.ng/logger": "^1.4.0",
|
|
50
|
+
"@thi.ng/paths": "^5.1.17",
|
|
51
|
+
"@thi.ng/strings": "^3.3.14"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@microsoft/api-extractor": "^7.31.1",
|
|
55
|
-
"@thi.ng/testament": "^0.3.
|
|
55
|
+
"@thi.ng/testament": "^0.3.2",
|
|
56
56
|
"rimraf": "^3.0.2",
|
|
57
57
|
"tools": "^0.0.1",
|
|
58
58
|
"typedoc": "^0.22.17",
|
|
@@ -136,5 +136,5 @@
|
|
|
136
136
|
"status": "alpha",
|
|
137
137
|
"year": 2022
|
|
138
138
|
},
|
|
139
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "c3f7d6598c7d7d0c61ba87150a56deac12649d7b\n"
|
|
140
140
|
}
|
package/string.d.ts
CHANGED
|
@@ -41,6 +41,13 @@ export declare class WasmStringSlice implements ReadonlyWasmString {
|
|
|
41
41
|
* @param str
|
|
42
42
|
*/
|
|
43
43
|
set(str: string | WasmStringSlice): void;
|
|
44
|
+
/**
|
|
45
|
+
* Sets the slice itself to the new values provided.
|
|
46
|
+
*
|
|
47
|
+
* @param addr
|
|
48
|
+
* @param len
|
|
49
|
+
*/
|
|
50
|
+
setSlice(addr: number, len: number): void;
|
|
44
51
|
toJSON(): string;
|
|
45
52
|
toString(): string;
|
|
46
53
|
valueOf(): string;
|
package/string.js
CHANGED
|
@@ -58,6 +58,16 @@ export class WasmStringSlice {
|
|
|
58
58
|
this.mem.u32[(this.base + 4) >>> 2] = str.length;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets the slice itself to the new values provided.
|
|
63
|
+
*
|
|
64
|
+
* @param addr
|
|
65
|
+
* @param len
|
|
66
|
+
*/
|
|
67
|
+
setSlice(addr, len) {
|
|
68
|
+
this.mem.u32[this.base >>> 2] = addr;
|
|
69
|
+
this.mem.u32[(this.base + 4) >>> 2] = len;
|
|
70
|
+
}
|
|
61
71
|
toJSON() {
|
|
62
72
|
return this.deref();
|
|
63
73
|
}
|