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.
@@ -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
- if (local === undefined) {
3828
- return todo(scope, `update expression with undefined variable`, true);
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
- switch (decl.operator) {
3838
- case '++':
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
- case '--':
3843
- out.push(...number(1), [ Opcodes.sub ]);
3844
- break;
3849
+ return out;
3845
3850
  }
3846
3851
 
3847
- out.push([ isGlobal ? Opcodes.global_set : Opcodes.local_set, idx ]);
3848
- if (decl.prefix && !valueUnused) out.push([ isGlobal ? Opcodes.global_get : Opcodes.local_get, idx ]);
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 out;
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 = `${TYPE_NAMES[type]}: ${obj.message}`;
323
+ err.stack = `${obj.name}: ${obj.message}`;
324
324
  return err;
325
325
  }
326
326
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.42.5+a3af054f9",
4
+ "version": "0.42.6+d8f9d3f11",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.42.5+a3af054f9';
3
+ globalThis.version = '0.42.6+d8f9d3f11';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {