porffor 0.50.29 → 0.55.0

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.
@@ -492,6 +492,11 @@ const lookup = (scope, name, failEarly = false) => {
492
492
  if (parentLookup != null) return [ number(UNDEFINED) ];
493
493
  }
494
494
 
495
+ if (scope.name === name) {
496
+ // fallback for own func but with a different var/id name
497
+ return funcRef(funcByIndex(scope.index));
498
+ }
499
+
495
500
  if (failEarly) return null;
496
501
 
497
502
  return [ [ null, () => hoistLookup(scope, name), 1 ] ];
@@ -514,6 +519,18 @@ const generateIdent = (scope, decl) => {
514
519
  const generateYield = (scope, decl) => {
515
520
  const arg = decl.argument ?? DEFAULT_VALUE();
516
521
 
522
+ if (!scope.generator) {
523
+ // todo: access upper-scoped generator
524
+ return [
525
+ ...generate(scope, arg),
526
+ [ Opcodes.drop ],
527
+
528
+ // use undefined as yield expression value
529
+ number(0),
530
+ ...setLastType(scope, TYPES.undefined)
531
+ ];
532
+ }
533
+
517
534
  // just support a single yield like a return for now
518
535
  return [
519
536
  // return value in generator
@@ -2419,6 +2436,9 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2419
2436
  let idx;
2420
2437
  if (Object.hasOwn(funcIndex, name)) {
2421
2438
  idx = funcIndex[name];
2439
+ } else if (scope.name === name) {
2440
+ // fallback for own func but with a different var/id name
2441
+ idx = scope.index;
2422
2442
  } else if (Object.hasOwn(importedFuncs, name)) {
2423
2443
  idx = importedFuncs[name];
2424
2444
  scope.usesImports = true;
@@ -3234,18 +3254,23 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3234
3254
 
3235
3255
  const topLevel = scope.name === '#main';
3236
3256
  if (pattern.type === 'Identifier') {
3237
- let out = [];
3238
3257
  const name = pattern.name;
3239
3258
 
3240
3259
  hoist(scope, name, kind === 'var' ? 1 : 2, global);
3241
3260
 
3242
3261
  if (init && isFuncType(init.type)) {
3243
- // hack for let a = function () { ... }
3244
- if (!init.id) {
3245
- setDefaultFuncName(init, name);
3246
- generateFunc(scope, init, true);
3247
- return out;
3262
+ // opt: make decl with func expression like declaration
3263
+ setDefaultFuncName(init, name);
3264
+ const [ _func, out ] = generateFunc(scope, init, true);
3265
+
3266
+ const funcName = init.id?.name;
3267
+ if (name !== funcName) {
3268
+ funcIndex[name] = funcIndex[funcName];
3269
+ delete funcIndex[funcName];
3248
3270
  }
3271
+
3272
+ out.push([ Opcodes.drop ]);
3273
+ return out;
3249
3274
  }
3250
3275
 
3251
3276
  if (defaultValue && isFuncType(defaultValue.type)) {
@@ -3253,6 +3278,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3253
3278
  setDefaultFuncName(defaultValue, name);
3254
3279
  }
3255
3280
 
3281
+ let out = [];
3256
3282
  if (topLevel && Object.hasOwn(builtinVars, name)) {
3257
3283
  // cannot redeclare
3258
3284
  if (kind !== 'var') return internalThrow(scope, 'SyntaxError', `Identifier '${unhackName(name)}' has already been declared`);
@@ -3611,23 +3637,6 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3611
3637
  const { type, name } = decl.left;
3612
3638
  const [ local, isGlobal ] = lookupName(scope, name);
3613
3639
 
3614
- // if (isFuncType(decl.right.type)) {
3615
- // // hack for a = function () { ... }
3616
- // decl.right.id = { name };
3617
-
3618
- // const func = generateFunc(scope, decl.right);
3619
-
3620
- // return [
3621
- // number(func.index - importedFuncs.length),
3622
- // ...(local != null ? [
3623
- // [ isGlobal ? Opcodes.global_set : Opcodes.local_set, local.idx ],
3624
- // [ isGlobal ? Opcodes.global_get : Opcodes.local_get, local.idx ],
3625
-
3626
- // ...setType(scope, name, TYPES.function)
3627
- // ] : [])
3628
- // ];
3629
- // }
3630
-
3631
3640
  const op = decl.operator.slice(0, -1) || '=';
3632
3641
 
3633
3642
  // hack: .length setter
@@ -5299,7 +5308,7 @@ const generateMeta = (scope, decl) => {
5299
5308
  [ Opcodes.local_get, scope.locals['#newtarget'].idx ]
5300
5309
  ];
5301
5310
 
5302
- // not constructor so does not exist, return undefined
5311
+ // todo: access upper-scoped new.target
5303
5312
  return [ number(UNDEFINED) ];
5304
5313
  }
5305
5314
 
@@ -5679,6 +5688,9 @@ const generateMember = (scope, decl, _global, _name) => {
5679
5688
 
5680
5689
  // hack: .name
5681
5690
  if (decl.property.name === 'name' && hasFuncWithName(name) && !scope.noFastFuncMembers) {
5691
+ // function name can mismatch variable/access name
5692
+ name = funcByName(name)?.name ?? name;
5693
+
5682
5694
  // eg: __String_prototype_toLowerCase -> toLowerCase
5683
5695
  if (name.startsWith('__')) name = name.split('_').pop();
5684
5696
  if (name.startsWith('#')) name = '';
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.29",
4
+ "version": "0.55.0",
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.50.29';
3
+ globalThis.version = '0.55.0';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {