@wasmgroundup/emit 0.1.0 → 0.2.0
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/index.test.ts +17 -0
- package/index.ts +22 -1
- package/package.json +1 -1
package/index.test.ts
CHANGED
|
@@ -32,11 +32,28 @@ test("simple modules", async () => {
|
|
|
32
32
|
return instance.exports.main(...args);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
// () => ()
|
|
35
36
|
expect(await runMain(makeModule([], [], [instr.end]), [])).toBe(undefined);
|
|
37
|
+
|
|
38
|
+
// () => i32
|
|
36
39
|
expect(
|
|
37
40
|
await runMain(
|
|
38
41
|
makeModule([], [valtype.i32], [instr.i32.const, 1, instr.end]),
|
|
39
42
|
[],
|
|
40
43
|
),
|
|
41
44
|
).toBe(1);
|
|
45
|
+
|
|
46
|
+
// (i32) => i32
|
|
47
|
+
expect(
|
|
48
|
+
await runMain(
|
|
49
|
+
makeModule([valtype.i32], [valtype.i32], [instr.local.get, 0, instr.end]),
|
|
50
|
+
[1],
|
|
51
|
+
),
|
|
52
|
+
).toBe(1);
|
|
53
|
+
expect(
|
|
54
|
+
await runMain(
|
|
55
|
+
makeModule([valtype.i32], [valtype.i32], [instr.local.get, 0, instr.end]),
|
|
56
|
+
[99],
|
|
57
|
+
),
|
|
58
|
+
).toBe(99);
|
|
42
59
|
});
|
package/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ const SECTION_ID_CODE = 10;
|
|
|
5
5
|
|
|
6
6
|
const TYPE_FUNCTION = 0x60;
|
|
7
7
|
|
|
8
|
-
type BytecodeFragment = (number | BytecodeFragment)[];
|
|
8
|
+
export type BytecodeFragment = (number | BytecodeFragment)[];
|
|
9
9
|
|
|
10
10
|
function stringToBytes(s: string): number[] {
|
|
11
11
|
const bytes = new TextEncoder().encode(s);
|
|
@@ -113,13 +113,34 @@ const instr = {
|
|
|
113
113
|
nop: 0x01,
|
|
114
114
|
end: 0x0b,
|
|
115
115
|
|
|
116
|
+
local: {
|
|
117
|
+
get: 0x20,
|
|
118
|
+
set: 0x21,
|
|
119
|
+
tee: 0x22,
|
|
120
|
+
},
|
|
116
121
|
i32: {
|
|
117
122
|
const: 0x41,
|
|
118
123
|
add: 0x6a,
|
|
119
124
|
sub: 0x6b,
|
|
125
|
+
mul: 0x6c,
|
|
120
126
|
},
|
|
121
127
|
i64: {
|
|
122
128
|
const: 0x42,
|
|
129
|
+
add: 0x7c,
|
|
130
|
+
sub: 0x7d,
|
|
131
|
+
mul: 0x7e,
|
|
132
|
+
},
|
|
133
|
+
f32: {
|
|
134
|
+
const: 0x43,
|
|
135
|
+
add: 0x92,
|
|
136
|
+
sub: 0x93,
|
|
137
|
+
mul: 0x94,
|
|
138
|
+
},
|
|
139
|
+
f64: {
|
|
140
|
+
const: 0x44,
|
|
141
|
+
add: 0xa0,
|
|
142
|
+
sub: 0xa1,
|
|
143
|
+
mul: 0xa2,
|
|
123
144
|
},
|
|
124
145
|
};
|
|
125
146
|
|