porffor 0.42.5 → 0.42.6
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 +51 -20
- package/compiler/wrap.js +1 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -3689,6 +3689,8 @@ const ifIdentifierErrors = (scope, decl) => {
|
|
3689
3689
|
const generateUnary = (scope, decl) => {
|
3690
3690
|
switch (decl.operator) {
|
3691
3691
|
case '+':
|
3692
|
+
// todo/opt: skip ToNumber if already known number type
|
3693
|
+
|
3692
3694
|
// 13.5.4 Unary + Operator, 13.5.4.1 Runtime Semantics: Evaluation
|
3693
3695
|
// https://tc39.es/ecma262/#sec-unary-plus-operator-runtime-semantics-evaluation
|
3694
3696
|
// 1. Let expr be ? Evaluation of UnaryExpression.
|
@@ -3821,33 +3823,62 @@ const generateUnary = (scope, decl) => {
|
|
3821
3823
|
|
3822
3824
|
const generateUpdate = (scope, decl, _global, _name, valueUnused = false) => {
|
3823
3825
|
const { name } = decl.argument;
|
3824
|
-
|
3825
3826
|
const [ local, isGlobal ] = lookupName(scope, name);
|
3827
|
+
if (local != null) {
|
3828
|
+
// fast path: just a local
|
3829
|
+
// todo: not as compliant as slow path (non numbers)
|
3830
|
+
const idx = local.idx;
|
3831
|
+
const out = [];
|
3832
|
+
|
3833
|
+
out.push([ isGlobal ? Opcodes.global_get : Opcodes.local_get, idx ]);
|
3834
|
+
if (!decl.prefix && !valueUnused) out.push([ isGlobal ? Opcodes.global_get : Opcodes.local_get, idx ]);
|
3835
|
+
|
3836
|
+
switch (decl.operator) {
|
3837
|
+
case '++':
|
3838
|
+
out.push(...number(1), [ Opcodes.add ]);
|
3839
|
+
break;
|
3826
3840
|
|
3827
|
-
|
3828
|
-
|
3829
|
-
|
3830
|
-
|
3831
|
-
const idx = local.idx;
|
3832
|
-
const out = [];
|
3833
|
-
|
3834
|
-
out.push([ isGlobal ? Opcodes.global_get : Opcodes.local_get, idx ]);
|
3835
|
-
if (!decl.prefix && !valueUnused) out.push([ isGlobal ? Opcodes.global_get : Opcodes.local_get, idx ]);
|
3841
|
+
case '--':
|
3842
|
+
out.push(...number(1), [ Opcodes.sub ]);
|
3843
|
+
break;
|
3844
|
+
}
|
3836
3845
|
|
3837
|
-
|
3838
|
-
|
3839
|
-
out.push(...number(1), [ Opcodes.add ]);
|
3840
|
-
break;
|
3846
|
+
out.push([ isGlobal ? Opcodes.global_set : Opcodes.local_set, idx ]);
|
3847
|
+
if (decl.prefix && !valueUnused) out.push([ isGlobal ? Opcodes.global_get : Opcodes.local_get, idx ]);
|
3841
3848
|
|
3842
|
-
|
3843
|
-
out.push(...number(1), [ Opcodes.sub ]);
|
3844
|
-
break;
|
3849
|
+
return out;
|
3845
3850
|
}
|
3846
3851
|
|
3847
|
-
|
3848
|
-
|
3852
|
+
// ++x: tmp = +x; x = tmp + 1
|
3853
|
+
// x++: tmp = +x; x = tmp + 1; tmp
|
3854
|
+
const tmp = localTmp(scope, '#updatetmp');
|
3855
|
+
addVarMetadata(scope, '#updatetmp', false, { type: TYPES.number });
|
3849
3856
|
|
3850
|
-
return
|
3857
|
+
return [
|
3858
|
+
// tmp = +x
|
3859
|
+
// if postfix, tee to keep on stack as return value
|
3860
|
+
...generate(scope, {
|
3861
|
+
type: 'UnaryExpression',
|
3862
|
+
operator: '+',
|
3863
|
+
prefix: true,
|
3864
|
+
argument: decl.argument
|
3865
|
+
}),
|
3866
|
+
[ decl.prefix ? Opcodes.local_set : Opcodes.local_tee, tmp ],
|
3867
|
+
|
3868
|
+
// x = tmp + 1
|
3869
|
+
...generate(scope, {
|
3870
|
+
type: 'AssignmentExpression',
|
3871
|
+
operator: '=',
|
3872
|
+
left: decl.argument,
|
3873
|
+
right: {
|
3874
|
+
type: 'BinaryExpression',
|
3875
|
+
operator: decl.operator[0],
|
3876
|
+
left: { type: 'Identifier', name: '#updatetmp' },
|
3877
|
+
right: { type: 'Literal', value: 1 }
|
3878
|
+
}
|
3879
|
+
}),
|
3880
|
+
...(decl.prefix ? [] : [ [ Opcodes.drop ] ])
|
3881
|
+
];
|
3851
3882
|
};
|
3852
3883
|
|
3853
3884
|
const generateIf = (scope, decl) => {
|
package/compiler/wrap.js
CHANGED
@@ -320,7 +320,7 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
320
320
|
const err = new (globalThis[TYPE_NAMES[type]] ?? Error)(obj.message);
|
321
321
|
|
322
322
|
err.name = obj.name;
|
323
|
-
err.stack = `${
|
323
|
+
err.stack = `${obj.name}: ${obj.message}`;
|
324
324
|
return err;
|
325
325
|
}
|
326
326
|
|
package/package.json
CHANGED