porffor 0.24.13 → 0.24.14

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.
@@ -359,7 +359,6 @@ const generateReturn = (scope, decl) => {
359
359
  const out = [];
360
360
  if (
361
361
  scope.constr && // only do this in constructors
362
- scope.newTarget && scope.usesThis && // sanity check
363
362
  !globalThis.precompile // skip in precompiled built-ins, we should not require this and handle it ourselves
364
363
  ) {
365
364
  // ignore return value and return this if being constructed
@@ -1242,7 +1241,7 @@ const asmFuncToAsm = (scope, func) => {
1242
1241
  });
1243
1242
  };
1244
1243
 
1245
- const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globals: globalTypes = [], globalInits = [], returns = [], returnType, localNames = [], globalNames = [], data: _data = [], table = false, constr = false, newTarget = false, usesThis = false, hasRestArgument = false } = {}) => {
1244
+ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globals: globalTypes = [], globalInits = [], returns = [], returnType, localNames = [], globalNames = [], data: _data = [], table = false, constr = false, hasRestArgument = false } = {}) => {
1246
1245
  if (wasm == null) { // called with no builtin
1247
1246
  log.warning('codegen', `${name} has no built-in!`);
1248
1247
  wasm = [];
@@ -1279,8 +1278,6 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
1279
1278
  index: currentFuncIndex++,
1280
1279
  table,
1281
1280
  constr,
1282
- newTarget,
1283
- usesThis,
1284
1281
  globalInits
1285
1282
  };
1286
1283
 
@@ -1787,7 +1784,7 @@ const createNewTarget = (scope, decl, idx) => {
1787
1784
  ...number(UNDEFINED),
1788
1785
  ...number(TYPES.undefined, Valtype.i32)
1789
1786
  ];
1790
- }
1787
+ };
1791
1788
 
1792
1789
  const createThisArg = (scope, decl, getFunc, knownThis = undefined) => {
1793
1790
  if (knownThis) {
@@ -2274,71 +2271,36 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2274
2271
  // todo: i'm sure this could be made better somehow, probably only with #96?
2275
2272
  return checkFlag(0b1,
2276
2273
  // no type return
2277
- checkFlag(0b1000,
2278
- // no type return & this
2279
- checkFlag(0b100, [
2280
- // no type return & this & new.target
2281
- ...createNewTarget(scope, decl),
2282
- ...createThisArg(scope, decl, [], knownThis),
2283
- ...argsOut,
2284
- [ Opcodes.local_get, funcLocal ],
2285
- [ Opcodes.call_indirect, argc + 2, 0, 'no_type_return' ],
2286
- ], [
2287
- // no type return & this
2288
- ...createThisArg(scope, decl),
2289
- ...argsOut,
2290
- [ Opcodes.local_get, funcLocal ],
2291
- [ Opcodes.call_indirect, argc + 1, 0, 'no_type_return' ]
2292
- ]),
2293
- // no type return
2294
- checkFlag(0b100, [
2295
- // no type return & new.target
2296
- ...createNewTarget(scope, decl),
2297
- ...argsOut,
2298
- [ Opcodes.local_get, funcLocal ],
2299
- [ Opcodes.call_indirect, argc + 1, 0, 'no_type_return' ],
2300
- ], [
2301
- // no type return
2302
- ...argsOut,
2303
- [ Opcodes.local_get, funcLocal ],
2304
- [ Opcodes.call_indirect, argc, 0, 'no_type_return' ]
2305
- ]),
2306
- ),
2274
+ checkFlag(0b10, [
2275
+ // no type return & constr
2276
+ ...createNewTarget(scope, decl),
2277
+ ...createThisArg(scope, decl, [], knownThis),
2278
+ ...argsOut,
2279
+ [ Opcodes.local_get, funcLocal ],
2280
+ [ Opcodes.call_indirect, argc + 2, 0, 'no_type_return' ],
2281
+ ], [
2282
+ // no type return & not constr
2283
+ ...argsOut,
2284
+ [ Opcodes.local_get, funcLocal ],
2285
+ [ Opcodes.call_indirect, argc, 0, 'no_type_return' ]
2286
+ ]),
2287
+
2307
2288
  // type return
2308
- checkFlag(0b1000,
2309
- // type return & this
2310
- checkFlag(0b100, [
2311
- // type return & this & new.target
2312
- ...createNewTarget(scope, decl),
2313
- ...createThisArg(scope, decl, [], knownThis),
2314
- ...argsOut,
2315
- [ Opcodes.local_get, funcLocal ],
2316
- [ Opcodes.call_indirect, argc + 2, 0 ],
2317
- ...setLastType(scope),
2318
- ], [
2319
- // type return & this
2320
- ...createThisArg(scope, decl),
2321
- ...argsOut,
2322
- [ Opcodes.local_get, funcLocal ],
2323
- [ Opcodes.call_indirect, argc + 1, 0 ],
2324
- ...setLastType(scope),
2325
- ]),
2289
+ checkFlag(0b10, [
2290
+ // type return & constr
2291
+ ...createNewTarget(scope, decl),
2292
+ ...createThisArg(scope, decl, [], knownThis),
2293
+ ...argsOut,
2294
+ [ Opcodes.local_get, funcLocal ],
2295
+ [ Opcodes.call_indirect, argc + 2, 0 ],
2296
+ ...setLastType(scope),
2297
+ ], [
2326
2298
  // type return
2327
- checkFlag(0b100, [
2328
- // type return & new.target
2329
- ...createNewTarget(scope, decl),
2330
- ...argsOut,
2331
- [ Opcodes.local_get, funcLocal ],
2332
- [ Opcodes.call_indirect, argc + 1, 0 ],
2333
- ...setLastType(scope),
2334
- ], [
2335
- // type return
2336
- ...argsOut,
2337
- [ Opcodes.local_get, funcLocal ],
2338
- [ Opcodes.call_indirect, argc, 0 ],
2339
- ...setLastType(scope),
2340
- ]),
2341
- )
2299
+ ...argsOut,
2300
+ [ Opcodes.local_get, funcLocal ],
2301
+ [ Opcodes.call_indirect, argc, 0 ],
2302
+ ...setLastType(scope),
2303
+ ])
2342
2304
  );
2343
2305
  };
2344
2306
 
@@ -2408,14 +2370,10 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2408
2370
  return internalThrow(scope, 'TypeError', `${unhackName(name)} is not a constructor`, true);
2409
2371
  }
2410
2372
 
2411
- if (func && func.newTarget) {
2373
+ if (func && func.constr) {
2412
2374
  out.push(...createNewTarget(scope, decl, idx - importedFuncs.length));
2413
- paramOffset += 2;
2414
- }
2415
-
2416
- if (func && func.usesThis) {
2417
2375
  out.push(...createThisArg(scope, decl, func));
2418
- paramOffset += 2;
2376
+ paramOffset += 4;
2419
2377
  }
2420
2378
 
2421
2379
  let args = [...decl.arguments];
@@ -2509,13 +2467,11 @@ const generateThis = (scope, decl, _global, _name) => {
2509
2467
  ];
2510
2468
  }
2511
2469
 
2512
- scope.usesThis = true;
2513
-
2514
2470
  return [
2515
2471
  [ Opcodes.local_get, '#this' ],
2516
2472
  ...setLastType(scope, [ [ Opcodes.local_get, '#this#type' ] ])
2517
2473
  ];
2518
- }
2474
+ };
2519
2475
 
2520
2476
  // bad hack for undefined and null working without additional logic
2521
2477
  const DEFAULT_VALUE = () => ({
@@ -4337,8 +4293,6 @@ const generateEmpty = (scope, decl) => {
4337
4293
  const generateMeta = (scope, decl) => {
4338
4294
  switch (`${decl.meta.name}.${decl.property.name}`) {
4339
4295
  case 'new.target': {
4340
- scope.newTarget = true;
4341
-
4342
4296
  return [
4343
4297
  [ Opcodes.local_get, '#newtarget' ],
4344
4298
  ];
@@ -4778,12 +4732,11 @@ const countParams = (func, name = undefined) => {
4778
4732
  if (func.argc) return func.argc;
4779
4733
 
4780
4734
  let params = func.params.length;
4781
- if (func.newTarget) params -= 2;
4782
- if (func.usesThis) params -= 2;
4735
+ if (func.constr) params -= 4;
4783
4736
  if (!func.internal || builtinFuncs[func.name]?.typedParams) params = Math.floor(params / 2);
4784
4737
 
4785
- return params;
4786
- }
4738
+ return func.argc = params;
4739
+ };
4787
4740
 
4788
4741
  const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) => {
4789
4742
  const name = decl.object.name;
@@ -5235,13 +5188,6 @@ const generateFunc = (scope, decl) => {
5235
5188
 
5236
5189
  func.params = Object.values(func.locals).map(x => x.type);
5237
5190
 
5238
- func.argc = countParams(func, name);
5239
-
5240
- if (func.constr) {
5241
- func.newTarget = true;
5242
- func.usesThis = true;
5243
- }
5244
-
5245
5191
  let body = objectHack(decl.body);
5246
5192
  if (decl.type === 'ArrowFunctionExpression' && decl.expression) {
5247
5193
  // hack: () => 0 -> () => return 0
@@ -5275,18 +5221,10 @@ const generateFunc = (scope, decl) => {
5275
5221
  wasm.push(...generateReturn(func, {}));
5276
5222
  }
5277
5223
 
5278
- if (func.newTarget || func.usesThis) {
5224
+ if (func.constr) {
5279
5225
  const locals = func.locals;
5280
- let idxOffset = 0;
5281
- func.params = [...func.params];
5282
- if (func.usesThis) {
5283
- func.params.unshift(valtypeBinary, Valtype.i32);
5284
- idxOffset += 2;
5285
- }
5286
- if (func.newTarget) {
5287
- func.params.unshift(valtypeBinary, Valtype.i32);
5288
- idxOffset += 2;
5289
- }
5226
+ let idxOffset = 4;
5227
+ func.params = [ valtypeBinary, Valtype.i32, valtypeBinary, Valtype.i32, ...func.params ];
5290
5228
 
5291
5229
  // move all local indexes by idxOffset
5292
5230
  func.localInd += idxOffset;
@@ -5295,15 +5233,11 @@ const generateFunc = (scope, decl) => {
5295
5233
  }
5296
5234
 
5297
5235
  let indexes = idxOffset;
5298
- // note: make sure to add these in reverse order of location
5299
- if (func.usesThis) {
5300
- locals['#this#type'] = { idx: --indexes, type: Valtype.i32 };
5301
- locals['#this'] = { idx: --indexes, type: valtypeBinary };
5302
- }
5303
- if (func.newTarget) {
5304
- locals['#newtarget#type'] = { idx: --indexes, type: Valtype.i32 };
5305
- locals['#newtarget'] = { idx: --indexes, type: valtypeBinary };
5306
- }
5236
+
5237
+ locals['#this#type'] = { idx: --indexes, type: Valtype.i32 };
5238
+ locals['#this'] = { idx: --indexes, type: valtypeBinary };
5239
+ locals['#newtarget#type'] = { idx: --indexes, type: Valtype.i32 };
5240
+ locals['#newtarget'] = { idx: --indexes, type: valtypeBinary };
5307
5241
 
5308
5242
  for (let i = 0; i < wasm.length; i++) {
5309
5243
  // note: these needs to be copied, even though they realistically shouldn't
@@ -217,7 +217,7 @@ ${funcs.map(x => {
217
217
  returns: ${JSON.stringify(x.returns)}, ${x.returnType != null ? `returnType: ${JSON.stringify(x.returnType)}` : 'typedReturns: 1'},
218
218
  locals: ${JSON.stringify(locals.slice(x.params.length).map(x => x[1].type))}, localNames: ${JSON.stringify(locals.map(x => x[0]))},
219
219
  ${x.globalInits ? ` globalInits: {${Object.keys(x.globalInits).map(y => `${y}: ${rewriteWasm(x.globalInits[y])}`).join(',')}},\n` : ''}${x.data && x.data.length > 0 ? ` data: [${x.data.map(x => `[${x.offset ?? 'null'},[${x.bytes.join(',')}]]`).join(',')}],` : ''}
220
- ${x.table ? ` table: 1,` : ''}${x.constr ? ` constr: 1,` : ''}${x.usesThis ? ` usesThis: 1,` : ''}${x.newTarget ? ` newTarget: 1,` : ''}${x.argc !== undefined ? ` argc: ${x.argc},` : ''}${x.hasRestArgument ? ` hasRestArgument: 1,` : ''}
220
+ ${x.table ? ` table: 1,` : ''}${x.constr ? ` constr: 1,` : ''}${x.hasRestArgument ? ` hasRestArgument: 1,` : ''}
221
221
  };`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n');
222
222
  }).join('\n')}
223
223
  };`;
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.24.13+4aea75f9a",
4
+ "version": "0.24.14+e5d79b96e",
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.24.13+4aea75f9a';
3
+ globalThis.version = '0.24.14+e5d79b96e';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {