@wasmgroundup/emit 0.2.3 → 0.2.4
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/dist/index.d.ts +2 -1
- package/dist/index.js +6 -2
- package/index.test.ts +23 -0
- package/index.ts +7 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -60,10 +60,11 @@ declare const instr: {
|
|
|
60
60
|
};
|
|
61
61
|
declare function u32(v: number | bigint): number[];
|
|
62
62
|
declare function i32(v: number | bigint): number[];
|
|
63
|
+
declare function f64(v: number): number[];
|
|
63
64
|
declare function locals(n: number, type: valtype): BytecodeFragment;
|
|
64
65
|
declare function import_(mod: string, nm: string, d: BytecodeFragment): BytecodeFragment;
|
|
65
66
|
declare function importsec(ims: BytecodeFragment): BytecodeFragment;
|
|
66
67
|
declare const importdesc: {
|
|
67
68
|
func(x: number): BytecodeFragment;
|
|
68
69
|
};
|
|
69
|
-
export { BytecodeFragment, code, codesec, export_, exportdesc, exportsec, func, funcidx, funcsec, functype, i32, import_, importdesc, importsec, instr, locals, module, name, section, typeidx, typesec, valtype, vec, };
|
|
70
|
+
export { BytecodeFragment, code, codesec, export_, exportdesc, exportsec, f64, func, funcidx, funcsec, functype, i32, import_, importdesc, importsec, instr, locals, module, name, section, typeidx, typesec, valtype, vec, };
|
package/dist/index.js
CHANGED
|
@@ -136,7 +136,6 @@ function u32(v) {
|
|
|
136
136
|
}
|
|
137
137
|
return r;
|
|
138
138
|
}
|
|
139
|
-
///! START i32-v1 #priv #api #dedent
|
|
140
139
|
function i32(v) {
|
|
141
140
|
let val = BigInt(v);
|
|
142
141
|
const r = [];
|
|
@@ -155,6 +154,11 @@ function i32(v) {
|
|
|
155
154
|
}
|
|
156
155
|
return r;
|
|
157
156
|
}
|
|
157
|
+
function f64(v) {
|
|
158
|
+
var buf = new ArrayBuffer(8);
|
|
159
|
+
new Float64Array(buf)[0] = v;
|
|
160
|
+
return Array.from(new Uint8Array(buf));
|
|
161
|
+
}
|
|
158
162
|
function locals(n, type) {
|
|
159
163
|
return [u32(n), type];
|
|
160
164
|
}
|
|
@@ -172,4 +176,4 @@ const importdesc = {
|
|
|
172
176
|
return [0x00, funcidx(x)];
|
|
173
177
|
},
|
|
174
178
|
};
|
|
175
|
-
export { code, codesec, export_, exportdesc, exportsec, func, funcidx, funcsec, functype, i32, import_, importdesc, importsec, instr, locals, module, name, section, typeidx, typesec, valtype, vec, };
|
|
179
|
+
export { code, codesec, export_, exportdesc, exportsec, f64, func, funcidx, funcsec, functype, i32, import_, importdesc, importsec, instr, locals, module, name, section, typeidx, typesec, valtype, vec, };
|
package/index.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
export_,
|
|
8
8
|
exportdesc,
|
|
9
9
|
exportsec,
|
|
10
|
+
f64,
|
|
10
11
|
func,
|
|
11
12
|
funcidx,
|
|
12
13
|
funcsec,
|
|
@@ -87,3 +88,25 @@ test("imports", async () => {
|
|
|
87
88
|
expect(instance.exports.main(1)).toBe(2);
|
|
88
89
|
expect(instance.exports.main(2)).toBe(3);
|
|
89
90
|
});
|
|
91
|
+
|
|
92
|
+
test("f64", async () => {
|
|
93
|
+
const PI = 3.141592653589793115997963468544185161590576171875;
|
|
94
|
+
const makeModule = () => {
|
|
95
|
+
const mod = module([
|
|
96
|
+
typesec([functype([], [valtype.f64])]),
|
|
97
|
+
funcsec([typeidx(0), typeidx(0)]),
|
|
98
|
+
exportsec([
|
|
99
|
+
export_("pi", exportdesc.func(0)),
|
|
100
|
+
export_("nan", exportdesc.func(1)),
|
|
101
|
+
]),
|
|
102
|
+
codesec([
|
|
103
|
+
code(func([], [instr.f64.const, f64(PI), instr.end])),
|
|
104
|
+
code(func([], [instr.f64.const, f64(Number.NaN), instr.end])),
|
|
105
|
+
]),
|
|
106
|
+
]);
|
|
107
|
+
return Uint8Array.from(mod.flat(Infinity));
|
|
108
|
+
};
|
|
109
|
+
const { instance } = await WebAssembly.instantiate(makeModule());
|
|
110
|
+
expect(instance.exports.pi()).toBe(PI);
|
|
111
|
+
expect(instance.exports.nan()).toBe(Number.NaN);
|
|
112
|
+
});
|
package/index.ts
CHANGED
|
@@ -169,7 +169,6 @@ function u32(v: number | bigint): number[] {
|
|
|
169
169
|
return r;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
///! START i32-v1 #priv #api #dedent
|
|
173
172
|
function i32(v: number | bigint): number[] {
|
|
174
173
|
let val = BigInt(v);
|
|
175
174
|
const r = [];
|
|
@@ -192,6 +191,12 @@ function i32(v: number | bigint): number[] {
|
|
|
192
191
|
return r;
|
|
193
192
|
}
|
|
194
193
|
|
|
194
|
+
function f64(v: number): number[] {
|
|
195
|
+
var buf = new ArrayBuffer(8);
|
|
196
|
+
new Float64Array(buf)[0] = v;
|
|
197
|
+
return Array.from(new Uint8Array(buf));
|
|
198
|
+
}
|
|
199
|
+
|
|
195
200
|
function locals(n: number, type: valtype): BytecodeFragment {
|
|
196
201
|
return [u32(n), type];
|
|
197
202
|
}
|
|
@@ -224,6 +229,7 @@ export {
|
|
|
224
229
|
export_,
|
|
225
230
|
exportdesc,
|
|
226
231
|
exportsec,
|
|
232
|
+
f64,
|
|
227
233
|
func,
|
|
228
234
|
funcidx,
|
|
229
235
|
funcsec,
|