porffor 0.49.9 → 0.49.11

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 ]
@@ -1507,7 +1508,7 @@ const getNodeType = (scope, node) => {
1507
1508
  }
1508
1509
 
1509
1510
  if (Object.hasOwn(builtinFuncs, name) && !builtinFuncs[name].typedReturns) return builtinFuncs[name].returnType ?? TYPES.number;
1510
- if (Object.hasOwn(internalConstrs, name)) return internalConstrs[name].type;
1511
+ if (Object.hasOwn(internalConstrs, name) && internalConstrs[name].type != null) return internalConstrs[name].type;
1511
1512
 
1512
1513
  // check if this is a prototype function
1513
1514
  // if so and there is only one impl (eg charCodeAt)
@@ -1929,7 +1930,7 @@ const createThisArg = (scope, decl) => {
1929
1930
  const name = decl.callee?.name;
1930
1931
  if (decl._new) {
1931
1932
  // if precompiling or builtin func, just make it null as unused
1932
- if (globalThis.precompile || Object.hasOwn(builtinFuncs, name)) return [
1933
+ if (!decl._forceCreateThis && (globalThis.precompile || Object.hasOwn(builtinFuncs, name))) return [
1933
1934
  ...number(NULL),
1934
1935
  ...number(TYPES.object, Valtype.i32)
1935
1936
  ];
@@ -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 ] ])
@@ -6094,7 +6103,7 @@ const objectHack = node => {
6094
6103
  if (node.computed || node.optional) return;
6095
6104
 
6096
6105
  // hack: block these properties as they can be accessed on functions
6097
- if (node.property.name === 'length' || node.property.name === 'name' || node.property.name === 'call') return abortOut;
6106
+ if (node.object.name !== 'Porffor' && (node.property.name === 'length' || node.property.name === 'name' || node.property.name === 'call')) return abortOut;
6098
6107
 
6099
6108
  if (node.property.name === '__proto__') return abortOut;
6100
6109
 
@@ -6605,6 +6614,30 @@ const internalConstrs = {
6605
6614
  type: TYPES.bytestring,
6606
6615
  notConstr: true,
6607
6616
  length: 1
6617
+ },
6618
+
6619
+ __Porffor_call: {
6620
+ // Porffor.call(func, argArray, this, newTarget)
6621
+ generate: (scope, decl) => generate(scope, {
6622
+ type: 'CallExpression',
6623
+ callee: decl.arguments[0],
6624
+ arguments: [ {
6625
+ type: 'SpreadElement',
6626
+ argument: decl.arguments[1],
6627
+ } ],
6628
+ _thisWasm: decl.arguments[2].value === null ? null : [
6629
+ ...generate(scope, decl.arguments[2]),
6630
+ ...getNodeType(scope, decl.arguments[2])
6631
+ ],
6632
+ _newTargetWasm: decl.arguments[3].value === null ? null : [
6633
+ ...generate(scope, decl.arguments[3]),
6634
+ ...getNodeType(scope, decl.arguments[3])
6635
+ ],
6636
+ _new: decl.arguments[3].value !== null,
6637
+ _forceCreateThis: true
6638
+ }),
6639
+ notConstr: true,
6640
+ length: 1
6608
6641
  }
6609
6642
  };
6610
6643
 
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.9",
4
+ "version": "0.49.11",
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.9';
3
+ globalThis.version = '0.49.11';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {