porffor 0.34.20 → 0.35.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.
package/CONTRIBUTING.md CHANGED
@@ -366,7 +366,7 @@ builtins/tostring_number: impl radix
366
366
 
367
367
  ## Test262
368
368
 
369
- For the first time, ensure you run `./test262/setup.sh`.
369
+ For the first time, ensure you run `./test262/setup.sh` (Unix) or `.\test262\setup.cmd` (Windows).
370
370
 
371
371
  Run `node test262` to run all the tests and get an output of total overall test results.
372
372
 
@@ -33,15 +33,11 @@ const encodeNames = funcs => {
33
33
  funcs.map(x => unsignedLEB128(x.asmIndex).concat(encodeString(x.name))),
34
34
  );
35
35
  const localsSection = encodeVector(
36
- funcs.map(x =>
37
- unsignedLEB128(x.asmIndex).concat(
38
- encodeVector(
39
- Object.entries(x.locals).map(([name, local]) =>
40
- unsignedLEB128(local.idx).concat(encodeString(name)),
41
- ),
42
- ),
43
- ),
44
- ),
36
+ funcs.map(x => unsignedLEB128(x.asmIndex).concat(encodeVector(
37
+ Object.entries(x.locals).map(([name, local]) =>
38
+ unsignedLEB128(local.idx).concat(encodeString(name))
39
+ )
40
+ )))
45
41
  );
46
42
 
47
43
  return [
@@ -49,7 +45,7 @@ const encodeNames = funcs => {
49
45
  ...encodeSection(1, functionsSection),
50
46
  ...encodeSection(2, localsSection),
51
47
  ];
52
- }
48
+ };
53
49
 
54
50
  export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) => {
55
51
  const types = [], typeCache = {};
@@ -1066,9 +1066,6 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
1066
1066
  }
1067
1067
 
1068
1068
  if (decl.operator === 'in') {
1069
- // hack: a in b -> Object.hasOwn(b, a)
1070
- // todo: not spec compliant, in should check prototype chain too (once we have it)
1071
-
1072
1069
  return generate(scope, {
1073
1070
  type: 'CallExpression',
1074
1071
  callee: {
@@ -1112,6 +1109,7 @@ const asmFuncToAsm = (scope, func) => {
1112
1109
  builtin: (n, offset = false) => {
1113
1110
  let idx = funcIndex[n] ?? importedFuncs[n];
1114
1111
  if (idx == null && builtinFuncs[n]) {
1112
+ // console.log(scope.name, '->', n);
1115
1113
  includeBuiltin(scope, n);
1116
1114
  idx = funcIndex[n];
1117
1115
  }
@@ -3173,7 +3171,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3173
3171
  const usedProps = [];
3174
3172
  for (const prop of properties) {
3175
3173
  if (prop.type == 'Property') { // let { foo } = {}
3176
- usedProps.push(!prop.computed && prop.key.type !== 'Literal' ? { type: 'Literal', value: prop.key.name } : prop.key);
3174
+ usedProps.push(getProperty(prop));
3177
3175
 
3178
3176
  if (prop.value.type === 'AssignmentPattern') { // let { foo = defaultValue } = {}
3179
3177
  decls.push(
@@ -3257,13 +3255,22 @@ const generateVar = (scope, decl) => {
3257
3255
  return out;
3258
3256
  };
3259
3257
 
3260
- const getMemberProperty = decl => {
3261
- if (decl.computed) return decl.property;
3258
+ const privateIDName = name => '.#.' + name;
3259
+ const privateIdentifierToIdentifier = decl => ({
3260
+ type: 'Identifier',
3261
+ name: privateIDName(decl.name)
3262
+ });
3263
+
3264
+ const getProperty = decl => {
3265
+ const prop = decl.property ?? decl.key;
3266
+ if (decl.computed) return prop;
3262
3267
 
3263
- return {
3268
+ if (prop.name) return {
3264
3269
  type: 'Literal',
3265
- value: decl.property.name
3270
+ value: prop.type === 'PrivateIdentifier' ? privateIDName(prop.name) : prop.name,
3266
3271
  };
3272
+
3273
+ return prop;
3267
3274
  };
3268
3275
 
3269
3276
  // todo: optimize this func for valueUnused
@@ -3348,7 +3355,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3348
3355
  const pointerTmp = localTmp(scope, '#member_setter_ptr_tmp', Valtype.i32);
3349
3356
 
3350
3357
  const object = decl.left.object;
3351
- const property = getMemberProperty(decl.left);
3358
+ const property = getProperty(decl.left);
3352
3359
 
3353
3360
  // todo/perf: use i32 object (and prop?) locals
3354
3361
  const objectWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_obj') ] ];
@@ -3751,7 +3758,7 @@ const generateUnary = (scope, decl) => {
3751
3758
  case 'delete': {
3752
3759
  if (decl.argument.type === 'MemberExpression') {
3753
3760
  const object = decl.argument.object;
3754
- const property = getMemberProperty(decl.argument);
3761
+ const property = getProperty(decl.argument);
3755
3762
 
3756
3763
  if (property.value === 'length' || property.value === 'name') scope.noFastFuncMembers = true;
3757
3764
 
@@ -5183,12 +5190,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
5183
5190
  continue;
5184
5191
  }
5185
5192
 
5186
- let k = key;
5187
- if (!computed && key.type !== 'Literal') k = {
5188
- type: 'Literal',
5189
- value: key.name
5190
- };
5191
-
5193
+ const k = getProperty(x);
5192
5194
  if (isFuncType(value.type)) {
5193
5195
  let id = value.id;
5194
5196
 
@@ -5287,7 +5289,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5287
5289
  }
5288
5290
 
5289
5291
  const object = decl.object;
5290
- const property = getMemberProperty(decl);
5292
+ const property = getProperty(decl);
5291
5293
 
5292
5294
  // generate now so type is gotten correctly later (it gets cached)
5293
5295
  generate(scope, object);
@@ -5404,7 +5406,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5404
5406
  const type = TYPES[x.split('_prototype')[0].slice(2).toLowerCase()];
5405
5407
  if (type == null) continue;
5406
5408
 
5407
- // do not __proto__ primitive hack for objects
5409
+ // do not __proto__ primitive hack for objects or functions
5408
5410
  if (type === TYPES.object || type === TYPES.function) continue;
5409
5411
 
5410
5412
  const ident = {
@@ -5721,27 +5723,12 @@ const generateClass = (scope, decl) => {
5721
5723
 
5722
5724
  if (decl.superClass) {
5723
5725
  out.push(
5724
- ...generateCall(scope, {
5725
- type: 'CallExpression',
5726
- callee: {
5727
- type: 'Identifier',
5728
- name: '__Porffor_object_assignAll'
5729
- },
5730
- arguments: [
5731
- proto,
5732
- {
5733
- type: 'MemberExpression',
5734
- object: decl.superClass,
5735
- property: {
5736
- type: 'Identifier',
5737
- name: 'prototype'
5738
- },
5739
- computed: false,
5740
- optional: false
5741
- }
5742
- ]
5743
- }),
5744
- [ Opcodes.drop ]
5726
+ // class Foo {}
5727
+ // class Bar extends Foo {}
5728
+ // Bar.__proto__ = Foo
5729
+ // Bar.prototype.__proto__ = Foo.prototype
5730
+ ...generate(scope, setObjProp(root, '__proto__', decl.superClass)),
5731
+ ...generate(scope, setObjProp(getObjProp(root, 'prototype'), '__proto__', getObjProp(decl.superClass, 'prototype')))
5745
5732
  );
5746
5733
  }
5747
5734
 
@@ -5753,11 +5740,7 @@ const generateClass = (scope, decl) => {
5753
5740
 
5754
5741
  let object = _static ? root : proto;
5755
5742
 
5756
- let k = key;
5757
- if (!computed && key.type !== 'Literal') k = {
5758
- type: 'Literal',
5759
- value: key.name
5760
- };
5743
+ const k = getProperty(x);
5761
5744
 
5762
5745
  let initKind = 'init';
5763
5746
  if (kind === 'get' || kind === 'set') initKind = kind;
@@ -6024,8 +6007,8 @@ const generateFunc = (scope, decl, outUnused = false) => {
6024
6007
  else func.returns = [];
6025
6008
  }
6026
6009
 
6027
- // inject promise job runner func at the end of main if job queue is used
6028
- if (Object.hasOwn(funcIndex, '__ecma262_HostEnqueuePromiseJob')) {
6010
+ // inject promise job runner func at the end of main if promises are made
6011
+ if (Object.hasOwn(funcIndex, 'Promise') || Object.hasOwn(funcIndex, '__Promise_resolve') || Object.hasOwn(funcIndex, '__Promise_reject')) {
6029
6012
  wasm.push(
6030
6013
  [ Opcodes.call, includeBuiltin(scope, '__Porffor_promise_runJobs').index ],
6031
6014
  [ Opcodes.drop ],
@@ -6358,8 +6341,8 @@ export default program => {
6358
6341
 
6359
6342
  delete globals['#ind'];
6360
6343
 
6361
- // if blank main func and other exports, remove it
6362
- if (main.wasm.length === 0 && funcs.reduce((acc, x) => acc + (x.export ? 1 : 0), 0) > 1) funcs.splice(main.index - importedFuncs.length, 1);
6344
+ // if wanted and blank main func and other exports, remove it
6345
+ if (Prefs.rmBlankMain && main.wasm.length === 0 && funcs.some(x => x.export)) funcs.splice(main.index - importedFuncs.length, 1);
6363
6346
 
6364
6347
  // make ~empty funcs for never generated funcs
6365
6348
  // todo: these should just be deleted once able
package/compiler/wrap.js CHANGED
@@ -137,6 +137,9 @@ ${flags & 0b0001 ? ` get func idx: ${get}
137
137
  // eg: __String_prototype_toLowerCase -> toLowerCase
138
138
  if (name.startsWith('__')) name = name.split('_').pop();
139
139
 
140
+ // anonymous functions
141
+ if (name.startsWith('#')) name = '';
142
+
140
143
  // make fake empty func for repl/etc
141
144
  return {[name]() {}}[name];
142
145
  }
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.34.20+ef2ae4c4d",
4
+ "version": "0.35.0+8b2f7cee3",
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.34.20+ef2ae4c4d';
3
+ globalThis.version = '0.35.0+8b2f7cee3';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {