porffor 0.37.32 → 0.39.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/compiler/codegen.js +31 -5
- package/compiler/decompile.js +3 -3
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -1523,6 +1523,7 @@ const countLeftover = wasm => {
|
|
1523
1523
|
else if ([Opcodes.i32_store, Opcodes.i64_store, Opcodes.f64_store, Opcodes.f32_store, Opcodes.i32_store16, Opcodes.i32_store8].includes(inst[0])) count -= 2;
|
1524
1524
|
else if (inst[0] === Opcodes.memory_copy[0] && (inst[1] === Opcodes.memory_copy[1] || inst[1] === Opcodes.memory_init[1])) count -= 3;
|
1525
1525
|
else if (inst[0] === Opcodes.return) count = 0;
|
1526
|
+
else if (inst[0] === Opcodes.catch) count += 2;
|
1526
1527
|
else if (inst[0] === Opcodes.call) {
|
1527
1528
|
if (inst[1] < importedFuncs.length) {
|
1528
1529
|
const func = importedFuncs[inst[1]];
|
@@ -4078,7 +4079,7 @@ const generateForOf = (scope, decl) => {
|
|
4078
4079
|
let setVar;
|
4079
4080
|
if (decl.left.type === 'Identifier') {
|
4080
4081
|
if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
|
4081
|
-
setVar = generateVarDstr(scope,
|
4082
|
+
setVar = generateVarDstr(scope, 'var', decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
|
4082
4083
|
} else {
|
4083
4084
|
// todo: verify this is correct
|
4084
4085
|
const global = scope.name === 'main' && decl.left.kind === 'var';
|
@@ -4436,7 +4437,7 @@ const generateForIn = (scope, decl) => {
|
|
4436
4437
|
let setVar;
|
4437
4438
|
if (decl.left.type === 'Identifier') {
|
4438
4439
|
if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
|
4439
|
-
setVar = generateVarDstr(scope,
|
4440
|
+
setVar = generateVarDstr(scope, 'var', decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
|
4440
4441
|
} else {
|
4441
4442
|
// todo: verify this is correct
|
4442
4443
|
const global = scope.name === 'main' && decl.left.kind === 'var';
|
@@ -4768,9 +4769,34 @@ const generateTry = (scope, decl) => {
|
|
4768
4769
|
depth.pop();
|
4769
4770
|
depth.push('catch');
|
4770
4771
|
|
4771
|
-
|
4772
|
-
|
4773
|
-
|
4772
|
+
const param = decl.handler.param;
|
4773
|
+
|
4774
|
+
if (param) {
|
4775
|
+
let count = 0;
|
4776
|
+
for (let i = 0; i < depth.length; i++) {
|
4777
|
+
if (depth[i] === 'catch') count++;
|
4778
|
+
}
|
4779
|
+
|
4780
|
+
const tmpName = '#catch_tmp' + count;
|
4781
|
+
const tmp = localTmp(scope, tmpName, valtypeBinary);
|
4782
|
+
localTmp(scope, tmpName + "#type", Valtype.i32);
|
4783
|
+
|
4784
|
+
// setup local for param
|
4785
|
+
out.push(
|
4786
|
+
[ Opcodes.catch, 0 ],
|
4787
|
+
...setType(scope, tmpName, []),
|
4788
|
+
[ Opcodes.local_set, tmp ],
|
4789
|
+
|
4790
|
+
...generateVarDstr(scope, 'let', param, { type: 'Identifier', name: tmpName }, undefined, false)
|
4791
|
+
);
|
4792
|
+
} else {
|
4793
|
+
out.push([ Opcodes.catch_all ]);
|
4794
|
+
}
|
4795
|
+
|
4796
|
+
out.push(
|
4797
|
+
...generate(scope, decl.handler.body),
|
4798
|
+
...finalizer
|
4799
|
+
);
|
4774
4800
|
}
|
4775
4801
|
|
4776
4802
|
out.push([ Opcodes.end ]);
|
package/compiler/decompile.js
CHANGED
@@ -43,7 +43,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
43
43
|
inst = [ [ inst[0], inst[1] ], ...inst.slice(2) ];
|
44
44
|
}
|
45
45
|
|
46
|
-
if (depth > 0 && (inst[0] === Opcodes.end || inst[0] === Opcodes.else || inst[0] === Opcodes.catch_all)) depth--;
|
46
|
+
if (depth > 0 && (inst[0] === Opcodes.end || inst[0] === Opcodes.else || inst[0] === Opcodes.catch_all || inst[0] === Opcodes.catch)) depth--;
|
47
47
|
|
48
48
|
out += ' '.repeat(Math.max(0, depth * 2));
|
49
49
|
|
@@ -70,7 +70,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
70
70
|
return true;
|
71
71
|
})
|
72
72
|
|
73
|
-
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.else || inst[0] === Opcodes.try || inst[0] === Opcodes.catch_all) depth++;
|
73
|
+
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.else || inst[0] === Opcodes.try || inst[0] === Opcodes.catch_all || inst[0] === Opcodes.catch) depth++;
|
74
74
|
|
75
75
|
if (inst[0] === Opcodes.f64_const) {
|
76
76
|
out += ` ${inst[1]}`;
|
@@ -89,7 +89,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
89
89
|
|
90
90
|
if (comments.length > 0) out += ` ;; ${comments.join(' ')}`;
|
91
91
|
|
92
|
-
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.else || inst[0] === Opcodes.try || inst[0] === Opcodes.catch_all) {
|
92
|
+
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.else || inst[0] === Opcodes.try || inst[0] === Opcodes.catch_all || inst[0] === Opcodes.catch) {
|
93
93
|
out += ` ;; label @${depth}`;
|
94
94
|
}
|
95
95
|
|
package/package.json
CHANGED