porffor 0.50.10 → 0.50.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.
@@ -48,14 +48,16 @@ const cacheAst = (decl, wasm) => {
48
48
  };
49
49
 
50
50
  let indirectFuncs = [];
51
+ let doNotMarkFuncRef = false;
51
52
  const funcRef = func => {
52
- func.generate?.();
53
- func.referenced = true;
53
+ if (!doNotMarkFuncRef) func.referenced = true;
54
54
 
55
55
  if (globalThis.precompile) return [
56
56
  [ Opcodes.const, 'funcref', func.name ]
57
57
  ];
58
58
 
59
+ func.generate?.();
60
+
59
61
  const wrapperArgc = Prefs.indirectWrapperArgc ?? 10;
60
62
  if (!func.wrapperFunc) {
61
63
  const locals = {}, params = [];
@@ -3723,6 +3725,9 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3723
3725
  const useCoctc = Prefs.coctc && !decl.left.computed && !decl.left.optional && !['prototype', 'size', 'description', 'byteLength', 'byteOffset', 'buffer', 'detached', 'resizable', 'growable', 'maxByteLength', 'length', '__proto__'].includes(decl.left.property.name) && coctcOffset(decl.left.property.name) > 0;
3724
3726
  if (useCoctc) valueUnused = false;
3725
3727
 
3728
+ // opt: do not mark prototype funcs as referenced to optimize this in them
3729
+ if (object?.property?.name === 'prototype' && isFuncType(decl.right.type)) decl.right._doNotMarkFuncRef = true;
3730
+
3726
3731
  const out = [
3727
3732
  ...generate(scope, object),
3728
3733
  [ Opcodes.local_set, objectTmp ],
@@ -5641,9 +5646,13 @@ const generateMember = (scope, decl, _global, _name) => {
5641
5646
 
5642
5647
  let chainCount = scope.chainMembers != null ? ++scope.chainMembers : 0;
5643
5648
 
5649
+ doNotMarkFuncRef = true;
5650
+
5644
5651
  // generate now so type is gotten correctly later (it gets cached)
5645
5652
  generate(scope, object);
5646
5653
 
5654
+ doNotMarkFuncRef = false;
5655
+
5647
5656
  // hack: .length
5648
5657
  if (decl.property.name === 'length') {
5649
5658
  // todo: support optional
@@ -6381,6 +6390,8 @@ const funcByIndex = idx => {
6381
6390
  const funcByName = name => funcByIndex(funcIndex[name]);
6382
6391
 
6383
6392
  const generateFunc = (scope, decl, forceNoExpr = false) => {
6393
+ doNotMarkFuncRef = false;
6394
+
6384
6395
  const name = decl.id ? decl.id.name : `#anonymous${uniqId()}`;
6385
6396
  if (decl.type.startsWith('Class')) {
6386
6397
  const out = generateClass(scope, {
@@ -6400,6 +6411,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
6400
6411
  // TODO: share scope/locals between !!!
6401
6412
  const arrow = decl.type === 'ArrowFunctionExpression' || decl.type === 'Program';
6402
6413
  const func = {
6414
+ start: decl.start,
6403
6415
  locals: {},
6404
6416
  localInd: 0,
6405
6417
  // value, type
@@ -6716,7 +6728,10 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
6716
6728
  // force generate all for precompile
6717
6729
  if (globalThis.precompile) func.generate();
6718
6730
 
6731
+ if (decl._doNotMarkFuncRef) doNotMarkFuncRef = true;
6719
6732
  const out = decl.type.endsWith('Expression') && !forceNoExpr ? funcRef(func) : [];
6733
+ doNotMarkFuncRef = false;
6734
+
6720
6735
  astCache.set(decl, out);
6721
6736
  return [ func, out ];
6722
6737
  };
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.50.10",
4
+ "version": "0.50.12",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/porf CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/bin/sh
2
- node runner/index.js "$@"
2
+ node "$(dirname "$0")/runner/index.js" "$@"
3
3
  # deno run -A runner/index.js "$@"
4
4
  # bun runner/index.js "$@"
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.50.10';
3
+ globalThis.version = '0.50.12';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {