@wasmgroundup/emit 0.1.0 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type BytecodeFragment = (number | BytecodeFragment)[];
1
+ export type BytecodeFragment = (number | BytecodeFragment)[];
2
2
  declare enum valtype {
3
3
  i32 = 127,
4
4
  i64 = 126,
@@ -25,13 +25,34 @@ declare function module(sections: any): BytecodeFragment;
25
25
  declare const instr: {
26
26
  nop: number;
27
27
  end: number;
28
+ local: {
29
+ get: number;
30
+ set: number;
31
+ tee: number;
32
+ };
28
33
  i32: {
29
34
  const: number;
30
35
  add: number;
31
36
  sub: number;
37
+ mul: number;
32
38
  };
33
39
  i64: {
34
40
  const: number;
41
+ add: number;
42
+ sub: number;
43
+ mul: number;
44
+ };
45
+ f32: {
46
+ const: number;
47
+ add: number;
48
+ sub: number;
49
+ mul: number;
50
+ };
51
+ f64: {
52
+ const: number;
53
+ add: number;
54
+ sub: number;
55
+ mul: number;
35
56
  };
36
57
  };
37
58
  declare function u32(v: number | bigint): number[];
package/dist/index.js CHANGED
@@ -83,13 +83,34 @@ var numtype;
83
83
  const instr = {
84
84
  nop: 0x01,
85
85
  end: 0x0b,
86
+ local: {
87
+ get: 0x20,
88
+ set: 0x21,
89
+ tee: 0x22,
90
+ },
86
91
  i32: {
87
92
  const: 0x41,
88
93
  add: 0x6a,
89
94
  sub: 0x6b,
95
+ mul: 0x6c,
90
96
  },
91
97
  i64: {
92
98
  const: 0x42,
99
+ add: 0x7c,
100
+ sub: 0x7d,
101
+ mul: 0x7e,
102
+ },
103
+ f32: {
104
+ const: 0x43,
105
+ add: 0x92,
106
+ sub: 0x93,
107
+ mul: 0x94,
108
+ },
109
+ f64: {
110
+ const: 0x44,
111
+ add: 0xa0,
112
+ sub: 0xa1,
113
+ mul: 0xa2,
93
114
  },
94
115
  };
95
116
  const SEVEN_BIT_MASK_BIG_INT = 127n;
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wasmgroundup/emit",
3
3
  "description": "A library for creating binary-encoded WebAssembly modules",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "scripts": {
22
22
  "check": "tsc --noEmit",
23
23
  "format": "prettier --write .",
24
- "prepublish": "tsc"
24
+ "prepublishOnly": "tsc"
25
25
  },
26
26
  "dependencies": {
27
27
  "prettier": "^3.0.3"