watr 2.1.0 → 2.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watr",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Ligth & fast WAT compiler",
5
5
  "main": "watr.js",
6
6
  "exports": {
package/readme.md CHANGED
@@ -8,7 +8,7 @@ Light & fast alternative for [wat2wasm](https://github.com/AssemblyScript/wabt.j
8
8
 
9
9
    | Size (gzipped) | Performance (op/s)
10
10
  ---|---|---
11
- watr | 3.8 kb | 5950
11
+ watr | 3.8 kb | 6250
12
12
  [wat-compiler](https://github.com/stagas/wat-compiler) | 6 kb | 348
13
13
  [wabt](https://github.com/AssemblyScript/wabt.js) | 300 kb | 574
14
14
 
package/src/compile.js CHANGED
@@ -161,32 +161,32 @@ const build = {
161
161
  immed = [0]
162
162
  }
163
163
 
164
- // (if ...), (block ...), (loop ...)
165
- else if (opCode > 1 && opCode < 5) {
164
+ // (block ...), (loop ...), (if ...)
165
+ else if (opCode === 2 || opCode === 3 || opCode === 4) {
166
166
  blocks.push(opCode)
167
167
 
168
168
  // (block $x) (loop $y)
169
169
  if (opCode < 4 && args[0]?.[0] === '$') (blocks[args.shift()] = blocks.length)
170
170
 
171
171
  // get type
172
- // (result i32)
173
- if (args[0]?.[0] === 'result') {
174
- if (args[0].length < 3) {
175
- let [, type] = args.shift()
176
- immed = [TYPE[type]]
177
- }
178
- // (result i32 i32)
179
- else {
180
- let [typeId] = consumeType(args, ctx)
181
- immed = [typeId]
182
- }
172
+ // (result i32) - doesn't require registering type
173
+ if (args[0]?.[0] === 'result' && args[0].length < 3) {
174
+ let [, type] = args.shift()
175
+ immed = [TYPE[type]]
176
+ }
177
+ // (result i32 i32)
178
+ else if (args[0]?.[0] === 'result' || args[0]?.[0] === 'param') {
179
+ let [typeId] = consumeType(args, ctx)
180
+ immed = [typeId]
181
+ }
182
+ else {
183
+ immed = [TYPE.void]
183
184
  }
184
- else immed = [TYPE.void]
185
185
 
186
186
  if (group) {
187
+ // (block xxx) -> block xxx end
187
188
  nodes.unshift('end')
188
189
 
189
- // (block xxx) -> block xxx end
190
190
  if (opCode < 4) while (args.length) nodes.unshift(args.pop())
191
191
 
192
192
  // (if cond a) -> cond if a end