porffor 0.33.0 → 0.33.1

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.
@@ -71,15 +71,8 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
71
71
 
72
72
  case 'ArrowFunctionExpression':
73
73
  case 'FunctionDeclaration':
74
- case 'FunctionExpression': {
75
- const func = generateFunc(scope, decl);
76
-
77
- if (decl.type.endsWith('Expression')) {
78
- return cacheAst(decl, funcRef(func.index, func.name));
79
- }
80
-
81
- return cacheAst(decl, []);
82
- }
74
+ case 'FunctionExpression':
75
+ return cacheAst(decl, generateFunc(scope, decl)[1]);
83
76
 
84
77
  case 'BlockStatement':
85
78
  return cacheAst(decl, generateCode(scope, decl));
@@ -2008,9 +2001,12 @@ const createThisArg = (scope, decl, knownThis = undefined) => {
2008
2001
  };
2009
2002
 
2010
2003
  const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2004
+ let out = [];
2011
2005
  let name = mapName(decl.callee.name);
2012
- if (isFuncType(decl.callee.type)) { // iife
2013
- const func = generateFunc(scope, decl.callee);
2006
+
2007
+ // opt: virtualize iifes
2008
+ if (isFuncType(decl.callee.type)) {
2009
+ const [ func ] = generateFunc(scope, decl.callee);
2014
2010
  name = func.name;
2015
2011
  }
2016
2012
 
@@ -2108,7 +2104,6 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2108
2104
  target = decl.callee.object;
2109
2105
  }
2110
2106
 
2111
- let out = [];
2112
2107
  if (protoName) {
2113
2108
  if (protoName === 'call') {
2114
2109
  const valTmp = localTmp(scope, '#call_val');
@@ -5775,7 +5770,7 @@ const generateClass = (scope, decl) => {
5775
5770
  const expr = decl.type === 'ClassExpression';
5776
5771
  if (decl.superClass) return todo(scope, 'class extends is not supported yet', expr);
5777
5772
 
5778
- const name = decl.id.name;
5773
+ const name = decl.id ? decl.id.name : `#anonymous${uniqId()}`;
5779
5774
  if (name == null) return todo(scope, 'unknown name for class', expr);
5780
5775
 
5781
5776
  const body = decl.body.body;
@@ -5794,14 +5789,12 @@ const generateClass = (scope, decl) => {
5794
5789
  }
5795
5790
  };
5796
5791
 
5797
- const func = generateFunc(scope, {
5792
+ const [ func, out ] = generateFunc(scope, {
5798
5793
  ...constr,
5799
5794
  _onlyConstr: `Class constructor ${name} requires 'new'`,
5800
5795
  type: expr ? 'FunctionExpression' : 'FunctionDeclaration'
5801
5796
  });
5802
5797
 
5803
- const out = [];
5804
-
5805
5798
  for (const x of body) {
5806
5799
  let { type, key, value, kind, static: _static, computed } = x;
5807
5800
  if (type !== 'MethodDefinition' && type !== 'PropertyDefinition') return todo(scope, `class body type ${type} is not supported yet`, expr);
@@ -5851,7 +5844,6 @@ const generateClass = (scope, decl) => {
5851
5844
  );
5852
5845
  }
5853
5846
 
5854
- if (expr) out.push(funcRef(func.index, func.name));
5855
5847
  return out;
5856
5848
  };
5857
5849
 
@@ -5906,6 +5898,16 @@ const objectHack = node => {
5906
5898
 
5907
5899
  const generateFunc = (scope, decl) => {
5908
5900
  const name = decl.id ? decl.id.name : `#anonymous${uniqId()}`;
5901
+ if (decl.type.startsWith('Class')) {
5902
+ const out = generateClass(scope, {
5903
+ ...decl,
5904
+ id: { name }
5905
+ });
5906
+
5907
+ const func = funcs.find(x => x.name === name);
5908
+ return [ func, out ];
5909
+ }
5910
+
5909
5911
  const params = decl.params ?? [];
5910
5912
 
5911
5913
  // TODO: share scope/locals between !!!
@@ -5927,6 +5929,8 @@ const generateFunc = (scope, decl) => {
5927
5929
  funcIndex[name] = func.index;
5928
5930
  funcs.push(func);
5929
5931
 
5932
+ const out = decl.type.endsWith('Expression') ? funcRef(func.index, func.name) : [];
5933
+
5930
5934
  let errorWasm = null;
5931
5935
  if (decl.generator) errorWasm = todo(scope, 'generator functions are not supported');
5932
5936
 
@@ -5937,7 +5941,7 @@ const generateFunc = (scope, decl) => {
5937
5941
  ]);
5938
5942
  func.params = [];
5939
5943
  func.constr = false;
5940
- return func;
5944
+ return [ func, out ];
5941
5945
  }
5942
5946
 
5943
5947
  if (typedInput && decl.returnType) {
@@ -6162,7 +6166,7 @@ const generateFunc = (scope, decl) => {
6162
6166
  }
6163
6167
  }
6164
6168
 
6165
- return func;
6169
+ return [ func, out ];
6166
6170
  };
6167
6171
 
6168
6172
  const generateCode = (scope, decl) => {
@@ -6378,7 +6382,7 @@ export default program => {
6378
6382
 
6379
6383
  if (Prefs.astLog) console.log(JSON.stringify(program.body.body, null, 2));
6380
6384
 
6381
- const main = generateFunc(scope, program);
6385
+ const [ main ] = generateFunc(scope, program);
6382
6386
 
6383
6387
  delete globals['#ind'];
6384
6388
 
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.33.0+0611169e7",
4
+ "version": "0.33.1+77ec3428e",
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.33.0+0611169e7';
3
+ globalThis.version = '0.33.1+77ec3428e';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {