porffor 0.55.2 → 0.55.3

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.
@@ -567,13 +567,8 @@ const generateReturn = (scope, decl) => {
567
567
  ...generate(scope, arg),
568
568
  ...getNodeType(scope, arg),
569
569
 
570
- [ Opcodes.call, includeBuiltin(scope, scope.async ? '__Porffor_AsyncGenerator_prototype_return' : '__Porffor_Generator_prototype_return').index ],
571
- [ Opcodes.drop ],
572
- [ Opcodes.drop ],
573
-
574
- // return generator
575
- [ Opcodes.local_get, scope.locals['#generator_out'].idx ],
576
- number(scope.async ? TYPES.__porffor_asyncgenerator : TYPES.__porffor_generator, Valtype.i32),
570
+ [ Opcodes.call, includeBuiltin(scope, scope.async ? '__Porffor_AsyncGenerator_return' : '__Porffor_Generator_return').index ],
571
+ // returns generator
577
572
  [ Opcodes.return ]
578
573
  ];
579
574
  }
@@ -1709,6 +1704,7 @@ const getNodeType = (scope, node) => {
1709
1704
  }
1710
1705
 
1711
1706
  if (node.type === 'ThisExpression') {
1707
+ if (scope.overrideThisType) return scope.overrideThisType;
1712
1708
  if (!scope.constr) return getType(scope, 'globalThis');
1713
1709
  return [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ];
1714
1710
  }
@@ -2717,18 +2713,18 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2717
2713
  };
2718
2714
 
2719
2715
  const generateThis = (scope, decl) => {
2716
+ if (scope.overrideThis) return scope.overrideThis;
2717
+
2720
2718
  if (!scope.constr) {
2721
2719
  // this in a non-constructor context is a reference to globalThis
2722
2720
  return [
2723
- ...generate(scope, { type: 'Identifier', name: 'globalThis' }),
2724
- ...setLastType(scope, getType(scope, 'globalThis'))
2721
+ ...generate(scope, { type: 'Identifier', name: 'globalThis' })
2725
2722
  ];
2726
2723
  }
2727
2724
 
2728
2725
  // opt: do not check for pure constructors or strict mode
2729
2726
  if ((!globalThis.precompile && scope.strict) || scope._onlyConstr || scope._onlyThisMethod || decl._noGlobalThis) return [
2730
- [ Opcodes.local_get, scope.locals['#this'].idx ],
2731
- ...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
2727
+ [ Opcodes.local_get, scope.locals['#this'].idx ]
2732
2728
  ];
2733
2729
 
2734
2730
  return [
@@ -2749,8 +2745,7 @@ const generateThis = (scope, decl) => {
2749
2745
  ];
2750
2746
  }, 0 ],
2751
2747
 
2752
- [ Opcodes.local_get, scope.locals['#this'].idx ],
2753
- ...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
2748
+ [ Opcodes.local_get, scope.locals['#this'].idx ]
2754
2749
  ];
2755
2750
  };
2756
2751
 
@@ -6190,12 +6185,25 @@ const generateClass = (scope, decl) => {
6190
6185
  );
6191
6186
  }
6192
6187
 
6188
+ scope.overrideThis = generate(scope, root);
6189
+ scope.overrideThisType = TYPES.function;
6190
+
6193
6191
  for (const x of body) {
6194
6192
  let { type, key, value, kind, static: _static, computed } = x;
6195
- if (type !== 'MethodDefinition' && type !== 'PropertyDefinition') return todo(scope, `class body type ${type} is not supported yet`, true);
6196
-
6197
6193
  if (kind === 'constructor') continue;
6198
6194
 
6195
+ if (type === 'StaticBlock') {
6196
+ // todo: make this more compliant
6197
+ out.push(
6198
+ ...generate(scope, {
6199
+ type: 'BlockStatement',
6200
+ body: x.body
6201
+ }),
6202
+ [ Opcodes.drop ]
6203
+ );
6204
+ continue;
6205
+ }
6206
+
6199
6207
  let object = _static ? root : proto;
6200
6208
 
6201
6209
  const k = getProperty(x, true);
@@ -6253,6 +6261,9 @@ const generateClass = (scope, decl) => {
6253
6261
  );
6254
6262
  }
6255
6263
 
6264
+ delete scope.overrideThis;
6265
+ delete scope.overrideThisType;
6266
+
6256
6267
  // error if not being constructed
6257
6268
  func.wasm.unshift(
6258
6269
  [ Opcodes.local_get, func.locals['#newtarget'].idx ],
@@ -6537,7 +6548,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
6537
6548
  addVarMetadata(func, name, false, typeAnno);
6538
6549
 
6539
6550
  // automatically add throws if unexpected this type to builtins
6540
- if (globalThis.precompile && i === 0 && func.name.includes('_prototype_')) {
6551
+ if (globalThis.precompile && i === 0 && func.name.includes('_prototype_') && !func.name.startsWith('__Porffor_')) {
6541
6552
  if (typeAnno.type === TYPES.array) {
6542
6553
  // Array.from
6543
6554
  wasm.push(
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.55.2",
4
+ "version": "0.55.3",
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.55.2';
3
+ globalThis.version = '0.55.3';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {