porffor 0.49.10 → 0.49.12

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.
@@ -50,6 +50,7 @@ const cacheAst = (decl, wasm) => {
50
50
  let indirectFuncs = [];
51
51
  const funcRef = func => {
52
52
  func.generate?.();
53
+ func.referenced = true;
53
54
 
54
55
  if (globalThis.precompile) return [
55
56
  [ Opcodes.const, 'funcref', func.name ]
@@ -2532,6 +2533,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2532
2533
 
2533
2534
  const func = funcByIndex(idx);
2534
2535
 
2536
+ if (func && !decl._new) func.onlyNew = false;
2537
+
2535
2538
  // generate func
2536
2539
  if (func) func.generate?.();
2537
2540
 
@@ -2664,16 +2667,22 @@ const generateThis = (scope, decl) => {
2664
2667
  ];
2665
2668
 
2666
2669
  return [
2667
- // default this to globalThis
2668
- [ Opcodes.local_get, scope.locals['#this#type'].idx ],
2669
- ...number(TYPES.undefined, Valtype.i32),
2670
- [ Opcodes.i32_eq ],
2671
- [ Opcodes.if, Blocktype.void ],
2672
- ...generate(scope, { type: 'Identifier', name: 'globalThis' }),
2673
- [ Opcodes.local_set, scope.locals['#this'].idx ],
2674
- ...getType(scope, 'globalThis'),
2675
- [ Opcodes.local_set, scope.locals['#this#type'].idx ],
2676
- [ Opcodes.end ],
2670
+ // default this to globalThis unless only new func
2671
+ [ null, () => {
2672
+ if (scope.onlyNew !== false && !scope.referenced) return [];
2673
+
2674
+ return [
2675
+ [ Opcodes.local_get, scope.locals['#this#type'].idx ],
2676
+ ...number(TYPES.undefined, Valtype.i32),
2677
+ [ Opcodes.i32_eq ],
2678
+ [ Opcodes.if, Blocktype.void ],
2679
+ ...generate(scope, { type: 'Identifier', name: 'globalThis' }),
2680
+ [ Opcodes.local_set, scope.locals['#this'].idx ],
2681
+ ...getType(scope, 'globalThis'),
2682
+ [ Opcodes.local_set, scope.locals['#this#type'].idx ],
2683
+ [ Opcodes.end ]
2684
+ ];
2685
+ }, 0 ],
2677
2686
 
2678
2687
  [ Opcodes.local_get, scope.locals['#this'].idx ],
2679
2688
  ...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
@@ -3355,6 +3364,21 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3355
3364
  return out;
3356
3365
  }
3357
3366
 
3367
+ if (pattern.type === 'MemberExpression') return [
3368
+ ...generate(scope, {
3369
+ type: 'AssignmentExpression',
3370
+ operator: '=',
3371
+ left: pattern,
3372
+ right: !defaultValue ? init : {
3373
+ type: 'LogicalExpression',
3374
+ operator: '??',
3375
+ left: init,
3376
+ right: defaultValue
3377
+ }
3378
+ }),
3379
+ [ Opcodes.drop ]
3380
+ ];
3381
+
3358
3382
  return todo(scope, `variable declarators of type ${pattern.type} are not supported yet`);
3359
3383
  }
3360
3384
 
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.49.10",
4
+ "version": "0.49.12",
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.49.10';
3
+ globalThis.version = '0.49.12';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {