@thi.ng/wasm-api-bindgen 1.2.56 → 1.2.57
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/README.md +2 -2
- package/c11.js +5 -5
- package/cli.js +6 -6
- package/codegen.js +8 -8
- package/internal/utils.js +1 -1
- package/package.json +15 -15
- package/typescript.js +3 -3
- package/zig.js +4 -4
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 211 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -882,7 +882,7 @@ For Node.js REPL:
|
|
|
882
882
|
const wab = await import("@thi.ng/wasm-api-bindgen");
|
|
883
883
|
```
|
|
884
884
|
|
|
885
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 6.
|
|
885
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 6.27 KB
|
|
886
886
|
|
|
887
887
|
## Dependencies
|
|
888
888
|
|
package/c11.js
CHANGED
|
@@ -46,14 +46,14 @@ const C11 = (opts = {}) => {
|
|
|
46
46
|
""
|
|
47
47
|
];
|
|
48
48
|
const slices = sliceTypes(coll);
|
|
49
|
-
for (
|
|
49
|
+
for (const id of slices) {
|
|
50
50
|
const prim = PRIM_ALIASES[id];
|
|
51
51
|
if (!prim) continue;
|
|
52
52
|
res.push(
|
|
53
53
|
...__sliceDef(prim, typePrefix, capitalize(id), coll)
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
|
-
for (
|
|
56
|
+
for (const id of __declOrder(coll)) {
|
|
57
57
|
const type = coll[id];
|
|
58
58
|
const name = __prefixedName(typePrefix, type.name, coll);
|
|
59
59
|
if (type.type == "funcptr") {
|
|
@@ -99,7 +99,7 @@ typedef ${type.type} ${name} ${name};`);
|
|
|
99
99
|
const name = typePrefix + e.name;
|
|
100
100
|
const lines = [];
|
|
101
101
|
lines.push(`enum ${name} {`);
|
|
102
|
-
for (
|
|
102
|
+
for (const v of e.values) {
|
|
103
103
|
let line;
|
|
104
104
|
if (!isString(v)) {
|
|
105
105
|
v.doc && gen.doc(v.doc, lines, opts2);
|
|
@@ -155,7 +155,7 @@ const __generateFields = (gen, parent, coll, opts, typePrefix) => {
|
|
|
155
155
|
const isUnion2 = parent.type === "union";
|
|
156
156
|
const name = typePrefix + parent.name;
|
|
157
157
|
let padID = 0;
|
|
158
|
-
for (
|
|
158
|
+
for (const f of parent.fields) {
|
|
159
159
|
if (isPadding(f)) {
|
|
160
160
|
res.push(`uint8_t __pad${padID++}[${f.pad}];`);
|
|
161
161
|
continue;
|
|
@@ -181,7 +181,7 @@ const __generateFields = (gen, parent, coll, opts, typePrefix) => {
|
|
|
181
181
|
);
|
|
182
182
|
fn("align", `alignof(${name})`);
|
|
183
183
|
fn("size", `sizeof(${name})`);
|
|
184
|
-
for (
|
|
184
|
+
for (const f of parent.fields) {
|
|
185
185
|
if (isPadding(f)) continue;
|
|
186
186
|
fn(f.name + "_align", `alignof(${ftypes[f.name]})`);
|
|
187
187
|
!isUnion2 && fn(f.name + "_offset", `offsetof(${name}, ${f.name})`);
|
package/cli.js
CHANGED
|
@@ -45,7 +45,7 @@ const addTypeSpec = (ctx, path, coll, spec) => {
|
|
|
45
45
|
if (spec.body) {
|
|
46
46
|
if (!isPlainObject(spec.body))
|
|
47
47
|
invalidSpec(path, `${spec.name}.body must be an object`);
|
|
48
|
-
for (
|
|
48
|
+
for (const lang in spec.body) {
|
|
49
49
|
const src = spec.body[lang];
|
|
50
50
|
if (isString(src) && src[0] === "@") {
|
|
51
51
|
spec.body[lang] = readText(src.substring(1), ctx.logger);
|
|
@@ -57,9 +57,9 @@ const addTypeSpec = (ctx, path, coll, spec) => {
|
|
|
57
57
|
spec.__path = path;
|
|
58
58
|
};
|
|
59
59
|
const validateTypeRefs = (coll) => {
|
|
60
|
-
for (
|
|
60
|
+
for (const spec of Object.values(coll)) {
|
|
61
61
|
if (!["funcptr", "struct", "union"].includes(spec.type)) continue;
|
|
62
|
-
for (
|
|
62
|
+
for (const f of spec.fields || spec.args) {
|
|
63
63
|
if (!(isPadding(f) || isWasmPrim(f.type) || isSizeT(f.type) || isOpaque(f.type) || isWasmString(f.type) || isExternal(f.type, coll) || coll[f.type])) {
|
|
64
64
|
invalidSpec(
|
|
65
65
|
spec.__path,
|
|
@@ -71,11 +71,11 @@ const validateTypeRefs = (coll) => {
|
|
|
71
71
|
};
|
|
72
72
|
const parseTypeSpecs = (ctx, inputs) => {
|
|
73
73
|
const coll = {};
|
|
74
|
-
for (
|
|
74
|
+
for (const path of inputs) {
|
|
75
75
|
try {
|
|
76
76
|
const spec = readJSON(resolve(path), ctx.logger);
|
|
77
77
|
if (isArray(spec)) {
|
|
78
|
-
for (
|
|
78
|
+
for (const s of spec) addTypeSpec(ctx, path, coll, s);
|
|
79
79
|
} else if (isPlainObject(spec)) {
|
|
80
80
|
addTypeSpec(ctx, path, coll, spec);
|
|
81
81
|
} else {
|
|
@@ -136,7 +136,7 @@ const CMD = {
|
|
|
136
136
|
if (opts.config) {
|
|
137
137
|
opts.config = resolve(opts.config);
|
|
138
138
|
ctx.config = readJSON(opts.config, ctx.logger);
|
|
139
|
-
for (
|
|
139
|
+
for (const id in ctx.config) {
|
|
140
140
|
const conf = ctx.config[id];
|
|
141
141
|
resolveUserCode(ctx, conf, "pre");
|
|
142
142
|
resolveUserCode(ctx, conf, "post");
|
package/codegen.js
CHANGED
|
@@ -62,7 +62,7 @@ const __sizeOf = defmulti(
|
|
|
62
62
|
struct: (type, coll, align, opts) => {
|
|
63
63
|
if (type.__size) return type.__size;
|
|
64
64
|
let offset = 0;
|
|
65
|
-
for (
|
|
65
|
+
for (const f of type.fields) {
|
|
66
66
|
offset = align.offset(offset, f.__align);
|
|
67
67
|
f.__offset = offset;
|
|
68
68
|
offset += __sizeOf(f, coll, align, opts);
|
|
@@ -72,7 +72,7 @@ const __sizeOf = defmulti(
|
|
|
72
72
|
union: (type, coll, align, opts) => {
|
|
73
73
|
if (type.__size) return type.__size;
|
|
74
74
|
let maxSize = 0;
|
|
75
|
-
for (
|
|
75
|
+
for (const f of type.fields) {
|
|
76
76
|
f.__offset = 0;
|
|
77
77
|
maxSize = Math.max(maxSize, __sizeOf(f, coll, align, opts));
|
|
78
78
|
}
|
|
@@ -113,14 +113,14 @@ const __alignOf = defmulti(
|
|
|
113
113
|
},
|
|
114
114
|
struct: (type, coll, align, opts) => {
|
|
115
115
|
let maxAlign = 1;
|
|
116
|
-
for (
|
|
116
|
+
for (const f of type.fields) {
|
|
117
117
|
maxAlign = Math.max(maxAlign, __alignOf(f, coll, align, opts));
|
|
118
118
|
}
|
|
119
119
|
return type.__align = maxAlign;
|
|
120
120
|
},
|
|
121
121
|
union: (type, coll, align, opts) => {
|
|
122
122
|
let maxAlign = 1;
|
|
123
|
-
for (
|
|
123
|
+
for (const f of type.fields) {
|
|
124
124
|
maxAlign = Math.max(maxAlign, __alignOf(f, coll, align, opts));
|
|
125
125
|
}
|
|
126
126
|
return type.__align = maxAlign;
|
|
@@ -131,7 +131,7 @@ const __alignOf = defmulti(
|
|
|
131
131
|
if (ptr.rtype !== "void") {
|
|
132
132
|
__sizeOf(ptr.rtype, coll, align, opts);
|
|
133
133
|
}
|
|
134
|
-
for (
|
|
134
|
+
for (const a of ptr.args) {
|
|
135
135
|
__alignOf(a, coll, align, opts);
|
|
136
136
|
}
|
|
137
137
|
return type.__align = align.align({
|
|
@@ -158,7 +158,7 @@ const __prepareType = defmulti(
|
|
|
158
158
|
compareByKey("__align", compareNumDesc)
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
|
-
for (
|
|
161
|
+
for (const f of struct.fields) {
|
|
162
162
|
const type = coll[f.type];
|
|
163
163
|
if (type) {
|
|
164
164
|
__prepareType(type, coll, selectAlignment(type), opts);
|
|
@@ -169,7 +169,7 @@ const __prepareType = defmulti(
|
|
|
169
169
|
}
|
|
170
170
|
);
|
|
171
171
|
const prepareTypes = (coll, opts) => {
|
|
172
|
-
for (
|
|
172
|
+
for (const id in coll) {
|
|
173
173
|
__prepareType(coll[id], coll, selectAlignment(coll[id]), opts);
|
|
174
174
|
}
|
|
175
175
|
return coll;
|
|
@@ -198,7 +198,7 @@ const generateTypes = (coll, codegen, opts = {}) => {
|
|
|
198
198
|
pre && res.push(pre, "");
|
|
199
199
|
}
|
|
200
200
|
$opts.pre && res.push(...ensureStringArray($opts.pre), "");
|
|
201
|
-
for (
|
|
201
|
+
for (const id in coll) {
|
|
202
202
|
const type = coll[id];
|
|
203
203
|
if (type.skip?.includes(codegen.id)) continue;
|
|
204
204
|
type.doc && codegen.doc(type.doc, res, $opts);
|
package/internal/utils.js
CHANGED
|
@@ -36,7 +36,7 @@ const ensureLines = (src, key) => isString(src) ? split(src) : isArray(src) ? sr
|
|
|
36
36
|
const ensureStringArray = (src) => isString(src) ? [src] : src;
|
|
37
37
|
function* withIndentation(lines, indent, scopeStart, scopeEnd, level = 0) {
|
|
38
38
|
const stack = new Array(level).fill(indent);
|
|
39
|
-
for (
|
|
39
|
+
for (const l of lines) {
|
|
40
40
|
scopeEnd.test(l) && stack.pop();
|
|
41
41
|
const curr = stack.length ? stack[stack.length - 1] : "";
|
|
42
42
|
yield curr + l;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api-bindgen",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.57",
|
|
4
4
|
"description": "Polyglot bindings code generators (TS/JS, Zig, C11) for hybrid WebAssembly projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -41,19 +41,19 @@
|
|
|
41
41
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@thi.ng/api": "^8.12.
|
|
45
|
-
"@thi.ng/args": "^3.2.
|
|
46
|
-
"@thi.ng/arrays": "^2.14.
|
|
47
|
-
"@thi.ng/binary": "^3.4.
|
|
48
|
-
"@thi.ng/checks": "^3.
|
|
49
|
-
"@thi.ng/compare": "^2.4.
|
|
50
|
-
"@thi.ng/defmulti": "^3.0.
|
|
51
|
-
"@thi.ng/errors": "^2.5.
|
|
52
|
-
"@thi.ng/file-io": "^2.2.
|
|
53
|
-
"@thi.ng/logger": "^3.2.
|
|
54
|
-
"@thi.ng/paths": "^5.2.
|
|
55
|
-
"@thi.ng/strings": "^3.9.
|
|
56
|
-
"@thi.ng/wasm-api": "^2.4.
|
|
44
|
+
"@thi.ng/api": "^8.12.10",
|
|
45
|
+
"@thi.ng/args": "^3.2.5",
|
|
46
|
+
"@thi.ng/arrays": "^2.14.3",
|
|
47
|
+
"@thi.ng/binary": "^3.4.68",
|
|
48
|
+
"@thi.ng/checks": "^3.8.0",
|
|
49
|
+
"@thi.ng/compare": "^2.4.36",
|
|
50
|
+
"@thi.ng/defmulti": "^3.0.86",
|
|
51
|
+
"@thi.ng/errors": "^2.5.50",
|
|
52
|
+
"@thi.ng/file-io": "^2.2.20",
|
|
53
|
+
"@thi.ng/logger": "^3.2.9",
|
|
54
|
+
"@thi.ng/paths": "^5.2.29",
|
|
55
|
+
"@thi.ng/strings": "^3.9.31",
|
|
56
|
+
"@thi.ng/wasm-api": "^2.4.12"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^24.10.1",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
"tag": "wasm",
|
|
129
129
|
"year": 2022
|
|
130
130
|
},
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "824bf9047b5a10f777c5c5b4aeecf0c750a22c75\n"
|
|
132
132
|
}
|
package/typescript.js
CHANGED
|
@@ -67,7 +67,7 @@ const TYPESCRIPT = (opts = {}) => {
|
|
|
67
67
|
enum: (e, _, acc, opts2) => {
|
|
68
68
|
const res = [];
|
|
69
69
|
res.push(`export enum ${e.name} {`);
|
|
70
|
-
for (
|
|
70
|
+
for (const v of e.values) {
|
|
71
71
|
let line;
|
|
72
72
|
if (!isString(v)) {
|
|
73
73
|
v.doc && gen.doc(v.doc, res, opts2);
|
|
@@ -88,7 +88,7 @@ const TYPESCRIPT = (opts = {}) => {
|
|
|
88
88
|
lines.push(
|
|
89
89
|
`export interface ${struct.name} extends WasmTypeBase {`
|
|
90
90
|
);
|
|
91
|
-
for (
|
|
91
|
+
for (const f of fields) {
|
|
92
92
|
const doc = __docType(f.field, struct, coll, opts2);
|
|
93
93
|
doc && gen.doc(doc, lines, opts2);
|
|
94
94
|
const decl = `${f.field.name}: ${f.type};`;
|
|
@@ -109,7 +109,7 @@ const TYPESCRIPT = (opts = {}) => {
|
|
|
109
109
|
...stringDecls.length ? [`let ${stringDecls.join(", ")};`] : [],
|
|
110
110
|
`return {`
|
|
111
111
|
);
|
|
112
|
-
for (
|
|
112
|
+
for (const f of fields) {
|
|
113
113
|
if (!f) continue;
|
|
114
114
|
if (f.getter) {
|
|
115
115
|
lines.push(
|
package/zig.js
CHANGED
|
@@ -26,7 +26,7 @@ const ZIG = (opts = {}) => {
|
|
|
26
26
|
`const std = @import("std");`,
|
|
27
27
|
`const bindgen = @import("wasm-api-bindgen");`
|
|
28
28
|
];
|
|
29
|
-
for (
|
|
29
|
+
for (const type of sliceTypes(coll)) {
|
|
30
30
|
if (type !== "string" && type !== "opaque") {
|
|
31
31
|
const name = capitalize(type);
|
|
32
32
|
res.push(
|
|
@@ -54,7 +54,7 @@ pub const ${name}Slice = bindgen.Slice([]${type}, [*]${type});`,
|
|
|
54
54
|
enum: (e, _, acc, opts2) => {
|
|
55
55
|
const lines = [];
|
|
56
56
|
lines.push(`pub const ${e.name} = enum(${e.tag}) {`);
|
|
57
|
-
for (
|
|
57
|
+
for (const v of e.values) {
|
|
58
58
|
let line;
|
|
59
59
|
if (!isString(v)) {
|
|
60
60
|
v.doc && gen.doc(v.doc, lines, opts2);
|
|
@@ -102,7 +102,7 @@ const __generateFields = (gen, parent, coll, opts) => {
|
|
|
102
102
|
const ftypes = {};
|
|
103
103
|
const name = parent.name;
|
|
104
104
|
let padID = 0;
|
|
105
|
-
for (
|
|
105
|
+
for (const f of parent.fields) {
|
|
106
106
|
if (isPadding(f)) {
|
|
107
107
|
res.push(`__pad${padID}: [${f.pad}]u8,`);
|
|
108
108
|
padID++;
|
|
@@ -124,7 +124,7 @@ const __generateFields = (gen, parent, coll, opts) => {
|
|
|
124
124
|
);
|
|
125
125
|
fn("align", `@alignOf(${name})`);
|
|
126
126
|
fn("size", `@sizeOf(${name})`);
|
|
127
|
-
for (
|
|
127
|
+
for (const f of parent.fields) {
|
|
128
128
|
if (isPadding(f)) continue;
|
|
129
129
|
fn(f.name + "_align", `@alignOf(${ftypes[f.name]})`);
|
|
130
130
|
!isUnion(parent) && fn(f.name + "_offset", `@offsetOf(${name}, "${f.name}")`);
|