porffor 0.37.31 → 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/builtins_precompiled.js +146 -146
- package/compiler/codegen.js +45 -23
- package/compiler/decompile.js +3 -3
- package/package.json +1 -1
- package/rhemyn/compile.js +5 -3
- 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]];
|
@@ -1733,7 +1734,7 @@ const aliasPrimObjsBC = bc => {
|
|
1733
1734
|
const createThisArg = (scope, decl) => {
|
1734
1735
|
const name = mapName(decl.callee?.name);
|
1735
1736
|
if (decl._new) {
|
1736
|
-
// if precompiling or builtin func, just make
|
1737
|
+
// if precompiling or builtin func, just make it null as unused
|
1737
1738
|
if (globalThis.precompile || Object.hasOwn(builtinFuncs, name)) return [
|
1738
1739
|
...number(NULL),
|
1739
1740
|
...number(TYPES.object, Valtype.i32)
|
@@ -1793,11 +1794,12 @@ const createThisArg = (scope, decl) => {
|
|
1793
1794
|
];
|
1794
1795
|
}
|
1795
1796
|
|
1796
|
-
// do not generate globalThis now,
|
1797
|
+
// undefined do not generate globalThis now,
|
1797
1798
|
// do it dynamically in generateThis in the func later
|
1799
|
+
// (or not for strict mode)
|
1798
1800
|
return [
|
1799
|
-
...number(
|
1800
|
-
...number(TYPES.
|
1801
|
+
...number(UNDEFINED),
|
1802
|
+
...number(TYPES.undefined, Valtype.i32)
|
1801
1803
|
];
|
1802
1804
|
}
|
1803
1805
|
};
|
@@ -2597,27 +2599,22 @@ const generateThis = (scope, decl) => {
|
|
2597
2599
|
];
|
2598
2600
|
}
|
2599
2601
|
|
2600
|
-
// opt: do not check for pure constructors
|
2601
|
-
if (scope._onlyConstr || scope._onlyThisMethod || decl._noGlobalThis) return [
|
2602
|
+
// opt: do not check for pure constructors or strict mode
|
2603
|
+
if ((!globalThis.precompile && scope.strict) || scope._onlyConstr || scope._onlyThisMethod || decl._noGlobalThis) return [
|
2602
2604
|
[ Opcodes.local_get, scope.locals['#this'].idx ],
|
2603
2605
|
...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
|
2604
2606
|
];
|
2605
2607
|
|
2606
2608
|
return [
|
2607
2609
|
// default this to globalThis
|
2608
|
-
[ Opcodes.local_get, scope.locals['#this'].idx ],
|
2609
|
-
|
2610
|
-
[ Opcodes.
|
2610
|
+
[ Opcodes.local_get, scope.locals['#this#type'].idx ],
|
2611
|
+
...number(TYPES.undefined, Valtype.i32),
|
2612
|
+
[ Opcodes.i32_eq ],
|
2611
2613
|
[ Opcodes.if, Blocktype.void ],
|
2612
|
-
|
2613
|
-
|
2614
|
-
|
2615
|
-
[ Opcodes.
|
2616
|
-
...generate(scope, { type: 'Identifier', name: 'globalThis' }),
|
2617
|
-
[ Opcodes.local_set, scope.locals['#this'].idx ],
|
2618
|
-
...getType(scope, 'globalThis'),
|
2619
|
-
[ Opcodes.local_set, scope.locals['#this#type'].idx ],
|
2620
|
-
[ Opcodes.end ],
|
2614
|
+
...generate(scope, { type: 'Identifier', name: 'globalThis' }),
|
2615
|
+
[ Opcodes.local_set, scope.locals['#this'].idx ],
|
2616
|
+
...getType(scope, 'globalThis'),
|
2617
|
+
[ Opcodes.local_set, scope.locals['#this#type'].idx ],
|
2621
2618
|
[ Opcodes.end ],
|
2622
2619
|
|
2623
2620
|
[ Opcodes.local_get, scope.locals['#this'].idx ],
|
@@ -4082,7 +4079,7 @@ const generateForOf = (scope, decl) => {
|
|
4082
4079
|
let setVar;
|
4083
4080
|
if (decl.left.type === 'Identifier') {
|
4084
4081
|
if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
|
4085
|
-
setVar = generateVarDstr(scope,
|
4082
|
+
setVar = generateVarDstr(scope, 'var', decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
|
4086
4083
|
} else {
|
4087
4084
|
// todo: verify this is correct
|
4088
4085
|
const global = scope.name === 'main' && decl.left.kind === 'var';
|
@@ -4440,7 +4437,7 @@ const generateForIn = (scope, decl) => {
|
|
4440
4437
|
let setVar;
|
4441
4438
|
if (decl.left.type === 'Identifier') {
|
4442
4439
|
if (scope.strict) return internalThrow(scope, 'ReferenceError', `${decl.left.name} is not defined`);
|
4443
|
-
setVar = generateVarDstr(scope,
|
4440
|
+
setVar = generateVarDstr(scope, 'var', decl.left, { type: 'Identifier', name: tmpName }, undefined, true);
|
4444
4441
|
} else {
|
4445
4442
|
// todo: verify this is correct
|
4446
4443
|
const global = scope.name === 'main' && decl.left.kind === 'var';
|
@@ -4772,9 +4769,34 @@ const generateTry = (scope, decl) => {
|
|
4772
4769
|
depth.pop();
|
4773
4770
|
depth.push('catch');
|
4774
4771
|
|
4775
|
-
|
4776
|
-
|
4777
|
-
|
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
|
+
);
|
4778
4800
|
}
|
4779
4801
|
|
4780
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
package/rhemyn/compile.js
CHANGED
@@ -12,15 +12,17 @@ const Length = 4;
|
|
12
12
|
const Tmp = 5;
|
13
13
|
const QuantifierTmp = 6; // the temporary variable used for quanitifers
|
14
14
|
|
15
|
-
const doesSucceedZero =
|
15
|
+
const doesSucceedZero = node => {
|
16
16
|
for (const n of node.body) {
|
17
|
-
if (n.type ===
|
18
|
-
if (!doesSucceedZero(
|
17
|
+
if (n.type === 'Group') {
|
18
|
+
if (!doesSucceedZero(n)) return false;
|
19
19
|
}
|
20
|
+
|
20
21
|
if (!n.quantifier || n.quantifier[0] > 0) {
|
21
22
|
return false;
|
22
23
|
}
|
23
24
|
}
|
25
|
+
|
24
26
|
return true;
|
25
27
|
}
|
26
28
|
|