@thi.ng/wasm-api 0.18.0 → 0.18.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 +9 -1
- package/README.md +1 -1
- package/codegen/typescript.js +10 -6
- package/codegen/zig.js +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
3
|
+
- **Last updated**: 2022-11-01T12:32:51Z
|
|
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,14 @@ 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.18.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.18.1) (2022-11-01)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- fix TS code gen array mem mapping ([a0e7132](https://github.com/thi-ng/umbrella/commit/a0e7132))
|
|
17
|
+
- use correct type size for array mem mapping
|
|
18
|
+
- update test fixtures
|
|
19
|
+
|
|
12
20
|
## [0.18.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.18.0) (2022-10-31)
|
|
13
21
|
|
|
14
22
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -688,7 +688,7 @@ node --experimental-repl-await
|
|
|
688
688
|
> const wasmApi = await import("@thi.ng/wasm-api");
|
|
689
689
|
```
|
|
690
690
|
|
|
691
|
-
Package sizes (gzipped, pre-treeshake): ESM: 7.
|
|
691
|
+
Package sizes (gzipped, pre-treeshake): ESM: 7.14 KB
|
|
692
692
|
|
|
693
693
|
**IMPORTANT:** The package includes multiple language code generators which are
|
|
694
694
|
**not** required for normal use of the API bridge. Hence, the actual package
|
package/codegen/typescript.js
CHANGED
|
@@ -20,7 +20,7 @@ export const TYPESCRIPT = (opts = {}) => {
|
|
|
20
20
|
stringType: "slice",
|
|
21
21
|
...opts,
|
|
22
22
|
};
|
|
23
|
-
const SCOPES = [/\{$/,
|
|
23
|
+
const SCOPES = [/\{$/, /(?<!\{.*)\}\)?[;,]?$/];
|
|
24
24
|
const gen = {
|
|
25
25
|
pre: (opts) => `// @ts-ignore possibly includes unused imports
|
|
26
26
|
import { MemorySlice, Pointer, ${__stringImpl(opts)}, WasmTypeBase, WasmTypeConstructor } from "${PKG_NAME}";${opts.pre ? `\n${opts.pre}` : ""}`,
|
|
@@ -106,7 +106,11 @@ import { MemorySlice, Pointer, ${__stringImpl(opts)}, WasmTypeBase, WasmTypeCons
|
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
108
|
const fn = f.len
|
|
109
|
-
? [
|
|
109
|
+
? [
|
|
110
|
+
`(addr) => {`,
|
|
111
|
+
...__mapArray(f, types, f.len),
|
|
112
|
+
`}`,
|
|
113
|
+
]
|
|
110
114
|
: [`(addr) => new $${f.type}.instance(addr)`];
|
|
111
115
|
lines.push(`return $${f.name} || ($${f.name} = new ${ftype}(mem, ${__addr(offset)},`, ...fn, `));`);
|
|
112
116
|
}
|
|
@@ -120,7 +124,7 @@ import { MemorySlice, Pointer, ${__stringImpl(opts)}, WasmTypeBase, WasmTypeCons
|
|
|
120
124
|
lines.push(`const addr = ${__ptr(opts.target, offset)};`, ...__mapStringArray(opts.target, "buf", $stringImpl, "len", isConst));
|
|
121
125
|
}
|
|
122
126
|
else {
|
|
123
|
-
lines.push(`const addr = ${__ptr(opts.target, offset)};`, ...__mapArray(f));
|
|
127
|
+
lines.push(`const addr = ${__ptr(opts.target, offset)};`, ...__mapArray(f, types));
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
else if (f.tag === "array" || f.tag === "vec") {
|
|
@@ -131,7 +135,7 @@ import { MemorySlice, Pointer, ${__stringImpl(opts)}, WasmTypeBase, WasmTypeCons
|
|
|
131
135
|
lines.push(`if ($${f.name}) return $${f.name};`, `const addr = ${__addr(offset)};`, ...__mapStringArray(opts.target, f.name, $stringImpl, f.len, isConst));
|
|
132
136
|
}
|
|
133
137
|
else {
|
|
134
|
-
lines.push(`const addr = ${__addr(offset)};`, ...__mapArray(f, f.len));
|
|
138
|
+
lines.push(`const addr = ${__addr(offset)};`, ...__mapArray(f, types, f.len));
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
else {
|
|
@@ -217,10 +221,10 @@ const __ptr = (target, offset) => `mem.${target.usize}[${__addrShift(offset, tar
|
|
|
217
221
|
const __ptrShift = (target, offset, shift) => __ptr(target, offset) + " >>> " + __shift(shift);
|
|
218
222
|
const __mem = (type, offset) => `mem.${type}[${__addrShift(offset, type)}]`;
|
|
219
223
|
/** @internal */
|
|
220
|
-
const __mapArray = (f, len = "len") => [
|
|
224
|
+
const __mapArray = (f, types, len = "len") => [
|
|
221
225
|
`const inst = $${f.type}(mem);`,
|
|
222
226
|
`const slice: ${f.type}[] = [];`,
|
|
223
|
-
`for(let i = 0; i < ${len}; i++) slice.push(inst.instance(addr + i * ${f.__size}));`,
|
|
227
|
+
`for(let i = 0; i < ${len}; i++) slice.push(inst.instance(addr + i * ${types[f.type].__size}));`,
|
|
224
228
|
`return slice;`,
|
|
225
229
|
];
|
|
226
230
|
/** @internal */
|
package/codegen/zig.js
CHANGED
|
@@ -14,7 +14,7 @@ import { defaultValue, ensureLines, isPadding, isStringSlice, isWasmString, pref
|
|
|
14
14
|
*/
|
|
15
15
|
export const ZIG = (opts = {}) => {
|
|
16
16
|
const INDENT = " ";
|
|
17
|
-
const SCOPES = [/\{$/,
|
|
17
|
+
const SCOPES = [/\{$/, /(?<!\{.*)\}\)?[;,]?$/];
|
|
18
18
|
const gen = {
|
|
19
19
|
pre: () => `const std = @import("std");${opts.pre ? `\n${opts.pre}` : ""}`,
|
|
20
20
|
post: () => opts.post || "",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.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",
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
"test:build-zig": "zig build-lib -O ReleaseSmall -target wasm32-freestanding -dynamic --strip --pkg-begin wasmapi zig/wasmapi.zig --pkg-end test/custom.zig && wasm-dis -o custom.wast custom.wasm && cp custom.wasm test"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.4.
|
|
40
|
-
"@thi.ng/args": "^2.2.
|
|
41
|
-
"@thi.ng/arrays": "^2.4.
|
|
42
|
-
"@thi.ng/binary": "^3.3.
|
|
39
|
+
"@thi.ng/api": "^8.4.5",
|
|
40
|
+
"@thi.ng/args": "^2.2.8",
|
|
41
|
+
"@thi.ng/arrays": "^2.4.1",
|
|
42
|
+
"@thi.ng/binary": "^3.3.9",
|
|
43
43
|
"@thi.ng/checks": "^3.3.2",
|
|
44
|
-
"@thi.ng/compare": "^2.1.
|
|
45
|
-
"@thi.ng/defmulti": "^2.1.
|
|
44
|
+
"@thi.ng/compare": "^2.1.15",
|
|
45
|
+
"@thi.ng/defmulti": "^2.1.20",
|
|
46
46
|
"@thi.ng/errors": "^2.2.3",
|
|
47
|
-
"@thi.ng/file-io": "^0.3.
|
|
47
|
+
"@thi.ng/file-io": "^0.3.18",
|
|
48
48
|
"@thi.ng/hex": "^2.2.2",
|
|
49
|
-
"@thi.ng/idgen": "^2.1.
|
|
49
|
+
"@thi.ng/idgen": "^2.1.17",
|
|
50
50
|
"@thi.ng/logger": "^1.4.2",
|
|
51
|
-
"@thi.ng/paths": "^5.1.
|
|
52
|
-
"@thi.ng/strings": "^3.3.
|
|
51
|
+
"@thi.ng/paths": "^5.1.21",
|
|
52
|
+
"@thi.ng/strings": "^3.3.16"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@microsoft/api-extractor": "^7.33.5",
|
|
@@ -142,5 +142,5 @@
|
|
|
142
142
|
"status": "alpha",
|
|
143
143
|
"year": 2022
|
|
144
144
|
},
|
|
145
|
-
"gitHead": "
|
|
145
|
+
"gitHead": "a4b60163a8caddceed5ec1b6b3584d164f61e7b6\n"
|
|
146
146
|
}
|