porffor 0.36.1 → 0.36.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.
@@ -3141,15 +3141,22 @@ const privateIdentifierToIdentifier = decl => ({
3141
3141
  name: privateIDName(decl.name)
3142
3142
  });
3143
3143
 
3144
- const getProperty = decl => {
3144
+ const getProperty = (decl, forceValueStr = false) => {
3145
3145
  const prop = decl.property ?? decl.key;
3146
3146
  if (decl.computed) return prop;
3147
3147
 
3148
- if (prop.name) return {
3148
+ // identifier -> literal
3149
+ if (prop.name != null) return {
3149
3150
  type: 'Literal',
3150
3151
  value: prop.type === 'PrivateIdentifier' ? privateIDName(prop.name) : prop.name,
3151
3152
  };
3152
3153
 
3154
+ // force literal values to be string (eg 0 -> '0')
3155
+ if (forceValueStr && prop.value != null) return {
3156
+ ...prop,
3157
+ value: prop.value.toString()
3158
+ };
3159
+
3153
3160
  return prop;
3154
3161
  };
3155
3162
 
@@ -3287,9 +3294,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3287
3294
  ...(op === '=' ? [] : [ [ Opcodes.local_tee, localTmp(scope, '#objset_object', Valtype.i32) ] ]),
3288
3295
  ...getNodeType(scope, object),
3289
3296
 
3290
- ...propertyWasm,
3291
- ...getNodeType(scope, property),
3292
- ...toPropertyKey(scope, op === '='),
3297
+ ...toPropertyKey(scope, propertyWasm, getNodeType(scope, property), decl.left.computed, op === '='),
3293
3298
  ...(op === '=' ? [] : [ [ Opcodes.local_set, localTmp(scope, '#objset_property_type', Valtype.i32) ] ]),
3294
3299
  ...(op === '=' ? [] : [
3295
3300
  Opcodes.i32_to_u,
@@ -3309,7 +3314,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3309
3314
  ], generate(scope, decl.right), getLastType(scope), getNodeType(scope, decl.right), false, name, true)),
3310
3315
  ...getNodeType(scope, decl),
3311
3316
 
3312
- [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_set').index ],
3317
+ [ Opcodes.call, includeBuiltin(scope, scope.strict ? '__Porffor_object_setStrict' : '__Porffor_object_set').index ],
3313
3318
  [ Opcodes.drop ],
3314
3319
  // ...setLastType(scope, getNodeType(scope, decl)),
3315
3320
  ],
@@ -3320,9 +3325,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3320
3325
  ...(op === '=' ? [] : [ [ Opcodes.local_tee, localTmp(scope, '#objset_object', Valtype.i32) ] ]),
3321
3326
  ...getNodeType(scope, object),
3322
3327
 
3323
- ...propertyWasm,
3324
- ...getNodeType(scope, property),
3325
- ...toPropertyKey(scope, op === '='),
3328
+ ...toPropertyKey(scope, propertyWasm, getNodeType(scope, property), decl.left.computed, op === '='),
3326
3329
  ...(op === '=' ? [] : [ [ Opcodes.local_set, localTmp(scope, '#objset_property_type', Valtype.i32) ] ]),
3327
3330
  ...(op === '=' ? [] : [
3328
3331
  Opcodes.i32_to_u,
@@ -3342,7 +3345,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3342
3345
  ], generate(scope, decl.right), getLastType(scope), getNodeType(scope, decl.right), false, name, true)),
3343
3346
  ...getNodeType(scope, decl),
3344
3347
 
3345
- [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_set').index ],
3348
+ [ Opcodes.call, includeBuiltin(scope, scope.strict ? '__Porffor_object_setStrict' : '__Porffor_object_set').index ],
3346
3349
  [ Opcodes.drop ],
3347
3350
  // ...setLastType(scope, getNodeType(scope, decl)),
3348
3351
  ],
@@ -3647,11 +3650,9 @@ const generateUnary = (scope, decl) => {
3647
3650
  Opcodes.i32_to_u,
3648
3651
  ...getNodeType(scope, object),
3649
3652
 
3650
- ...generate(scope, property),
3651
- ...getNodeType(scope, property),
3652
- ...toPropertyKey(scope, true),
3653
+ ...toPropertyKey(scope, generate(scope, property), getNodeType(scope, property), decl.argument.computed, true),
3653
3654
 
3654
- [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_delete').index ],
3655
+ [ Opcodes.call, includeBuiltin(scope, scope.strict ? '__Porffor_object_deleteStrict' : '__Porffor_object_delete').index ],
3655
3656
  [ Opcodes.drop ],
3656
3657
  Opcodes.i32_from_u
3657
3658
  ];
@@ -4781,7 +4782,7 @@ const printStaticStr = str => {
4781
4782
  out.push(
4782
4783
  // ...number(str.charCodeAt(i)),
4783
4784
  ...number(str.charCodeAt(i), Valtype.i32),
4784
- Opcodes.i32_from_u,
4785
+ [ Opcodes.f64_convert_i32_u ],
4785
4786
  [ Opcodes.call, importedFuncs.printChar ]
4786
4787
  );
4787
4788
  }
@@ -4895,13 +4896,14 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
4895
4896
  // hack: handle allocation for #member_prop's here instead of in several places /shrug
4896
4897
  let shouldGet = true;
4897
4898
  if (name === '#member_prop') {
4898
- out.push(...number(rawPtr, Valtype.i32));
4899
+ out.push(...number(rawPtr));
4899
4900
  shouldGet = false;
4900
4901
  }
4901
4902
 
4902
4903
  if (name === '#member_prop_assign') {
4903
4904
  out.push(
4904
- [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ]
4905
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
4906
+ Opcodes.i32_from_u
4905
4907
  );
4906
4908
  shouldGet = false;
4907
4909
  }
@@ -4911,7 +4913,14 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
4911
4913
  ...(shouldGet ? [
4912
4914
  [ global ? Opcodes.global_get : Opcodes.local_get, local.idx ],
4913
4915
  Opcodes.i32_to_u
4914
- ] : []),
4916
+ ] : [
4917
+ // hack: make precompile realise we are allocating
4918
+ ...(globalThis.precompile ? [
4919
+ [ global ? Opcodes.global_set : Opcodes.local_set, local.idx ],
4920
+ [ global ? Opcodes.global_get : Opcodes.local_get, local.idx ],
4921
+ ] : []),
4922
+ Opcodes.i32_to_u
4923
+ ]),
4915
4924
  [ Opcodes.local_set, pointerTmp ]
4916
4925
  );
4917
4926
 
@@ -5040,13 +5049,20 @@ const generateArray = (scope, decl, global = false, name = '$undeclared', initEm
5040
5049
  return makeArray(scope, decl, global, name, initEmpty, valtype, false, true)[0];
5041
5050
  };
5042
5051
 
5043
- const toPropertyKey = (scope, i32Conv = false) => [
5052
+ // opt: do not call ToPropertyKey for non-computed properties as unneeded
5053
+ const toPropertyKey = (scope, wasm, type, computed = false, i32Conv = false) => computed ? [
5054
+ ...wasm,
5055
+ ...type,
5044
5056
  [ Opcodes.call, includeBuiltin(scope, '__ecma262_ToPropertyKey').index ],
5045
5057
  ...(i32Conv ? [
5046
5058
  [ Opcodes.local_set, localTmp(scope, '#swap', Valtype.i32) ],
5047
5059
  Opcodes.i32_to_u,
5048
5060
  [ Opcodes.local_get, localTmp(scope, '#swap', Valtype.i32) ]
5049
5061
  ] : [])
5062
+ ] : [
5063
+ ...wasm,
5064
+ ...(i32Conv ? [ Opcodes.i32_to_u ] : []),
5065
+ ...type
5050
5066
  ];
5051
5067
 
5052
5068
  const generateObject = (scope, decl, global = false, name = '$undeclared') => {
@@ -5083,7 +5099,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
5083
5099
  continue;
5084
5100
  }
5085
5101
 
5086
- const k = getProperty(x);
5102
+ const k = getProperty(x, true);
5087
5103
  if (isFuncType(value.type)) {
5088
5104
  let id = value.id;
5089
5105
 
@@ -5100,9 +5116,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
5100
5116
  [ Opcodes.local_get, tmp ],
5101
5117
  ...number(TYPES.object, Valtype.i32),
5102
5118
 
5103
- ...generate(scope, k),
5104
- ...getNodeType(scope, k),
5105
- ...toPropertyKey(scope, true),
5119
+ ...toPropertyKey(scope, generate(scope, k), getNodeType(scope, k), computed, true),
5106
5120
 
5107
5121
  ...generate(scope, value),
5108
5122
  ...(kind !== 'init' ? [ Opcodes.i32_to_u ] : []),
@@ -5397,9 +5411,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5397
5411
  Opcodes.i32_to_u,
5398
5412
  ...getNodeType(scope, object),
5399
5413
 
5400
- ...propertyWasm,
5401
- ...getNodeType(scope, property),
5402
- ...toPropertyKey(scope, true),
5414
+ ...toPropertyKey(scope, propertyWasm, getNodeType(scope, property), decl.computed, true),
5403
5415
 
5404
5416
  [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
5405
5417
  ...setLastType(scope)
@@ -5410,9 +5422,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5410
5422
  Opcodes.i32_to_u,
5411
5423
  ...getNodeType(scope, object),
5412
5424
 
5413
- ...propertyWasm,
5414
- ...getNodeType(scope, property),
5415
- ...toPropertyKey(scope, true),
5425
+ ...toPropertyKey(scope, propertyWasm, getNodeType(scope, property), decl.computed, true),
5416
5426
 
5417
5427
  [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
5418
5428
  ...setLastType(scope)
@@ -5633,7 +5643,7 @@ const generateClass = (scope, decl) => {
5633
5643
 
5634
5644
  let object = _static ? root : proto;
5635
5645
 
5636
- const k = getProperty(x);
5646
+ const k = getProperty(x, true);
5637
5647
 
5638
5648
  let initKind = 'init';
5639
5649
  if (kind === 'get' || kind === 'set') initKind = kind;
@@ -5674,9 +5684,7 @@ const generateClass = (scope, decl) => {
5674
5684
  Opcodes.i32_to_u,
5675
5685
  ...getNodeType(outScope, object),
5676
5686
 
5677
- ...generate(outScope, k),
5678
- ...getNodeType(outScope, k),
5679
- ...toPropertyKey(outScope, true),
5687
+ ...toPropertyKey(outScope, generate(outScope, k), getNodeType(outScope, k), computed, true),
5680
5688
 
5681
5689
  ...generate(outScope, value),
5682
5690
  ...(initKind !== 'init' ? [ Opcodes.i32_to_u ] : []),
@@ -5765,6 +5773,8 @@ const objectHack = node => {
5765
5773
  if (objectName !== 'Object_prototype' && (node.property.name === 'propertyIsEnumerable' || node.property.name === 'hasOwnProperty' || node.property.name === 'isPrototypeOf')) return abortOut;
5766
5774
 
5767
5775
  const name = '__' + objectName + '_' + node.property.name;
5776
+ if ((!hasFuncWithName(name) && !Object.hasOwn(builtinVars, name)) && (hasFuncWithName(objectName) || Object.hasOwn(builtinVars, objectName))) return abortOut;
5777
+
5768
5778
  if (Prefs.codeLog) log('codegen', `object hack! ${node.object.name}.${node.property.name} -> ${name}`);
5769
5779
 
5770
5780
  return {
package/compiler/index.js CHANGED
@@ -16,8 +16,9 @@ globalThis.decompile = decompile;
16
16
  const logFuncs = (funcs, globals, exceptions) => {
17
17
  console.log('\n' + underline(bold('funcs')));
18
18
 
19
+ const wanted = Prefs.f;
19
20
  for (const f of funcs) {
20
- if (f.internal) continue;
21
+ if ((wanted && f.name !== wanted) || (!wanted && f.internal)) continue;
21
22
  console.log(decompile(f.wasm, f.name, f.index, f.locals, f.params, f.returns, funcs, globals, exceptions));
22
23
  }
23
24
 
@@ -166,7 +167,7 @@ export default (code, flags) => {
166
167
  const wasm = out.wasm = assemble(funcs, globals, tags, pages, data, flags);
167
168
  if (logProgress) progressDone('assembled', t3);
168
169
 
169
- if (Prefs.optFuncs) logFuncs(funcs, globals, exceptions);
170
+ if (Prefs.optFuncs || Prefs.f) logFuncs(funcs, globals, exceptions);
170
171
 
171
172
  if (Prefs.compileAllocLog) {
172
173
  const wasmPages = Math.ceil((pages.size * pageSize) / 65536);
@@ -53,11 +53,13 @@ const compile = async (file, _funcs) => {
53
53
  const returnOverrides = {
54
54
  __Porffor_object_get: [ Valtype.f64, Valtype.i32 ],
55
55
  __Porffor_object_set: [ Valtype.f64, Valtype.i32 ],
56
+ __Porffor_object_setStrict: [ Valtype.f64, Valtype.i32 ],
56
57
  __Porffor_object_packAccessor: [ Valtype.f64, Valtype.i32 ]
57
58
  };
58
59
 
59
60
  const paramOverrides = {
60
61
  __Porffor_object_set: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
62
+ __Porffor_object_setStrict: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
61
63
  __Porffor_object_expr_init: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
62
64
  __Porffor_object_expr_initWithFlags: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32, Valtype.i32, Valtype.i32 ],
63
65
  __Porffor_object_define: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32, Valtype.i32, Valtype.i32 ],
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.36.1+7b9b6a8dd",
4
+ "version": "0.36.3+71c03246c",
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.36.1+7b9b6a8dd';
3
+ globalThis.version = '0.36.3+71c03246c';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {