porffor 0.59.2 → 0.59.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.
@@ -879,7 +879,7 @@ const performLogicOp = (scope, op, left, right, leftType, rightType) => {
879
879
  return [
880
880
  ...left,
881
881
  [ Opcodes.local_tee, localTmp(scope, 'logictmp') ],
882
- ...checks[op](scope, [], leftType, false, true),
882
+ ...checks[op](scope, [], leftType),
883
883
  [ Opcodes.if, valtypeBinary ],
884
884
  ...right,
885
885
  // note type
@@ -935,25 +935,29 @@ const compareStrings = (scope, left, right, leftType, rightType, noConv = false)
935
935
  ];
936
936
  };
937
937
 
938
- const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode = undefined) => {
939
- const truthyMode = forceTruthyMode ?? Prefs.truthy ?? 'full';
938
+ const truthy = (scope, wasm, type, nonbinary = true, intIn = false) => {
939
+ if (valtypeBinary === Valtype.i32) intIn = true;
940
+
941
+ // nonbinary = true: int output, 0 or non-0
942
+ // nonbinary = false: float output, 0 or 1
943
+
944
+ const truthyMode = nonbinary ? (Prefs.truthy ?? 'full') : 'full';
940
945
  if (isIntToFloatOp(wasm[wasm.length - 1])) return [
941
946
  ...wasm,
942
947
  ...(truthyMode === 'full' ? [
943
948
  [ Opcodes.f64_const, 0 ],
944
949
  [ Opcodes.f64_ne ],
945
- ...(!intOut ? [ Opcodes.i32_from_u ] : [])
946
- ] : [
947
- ...(!intIn && intOut ? [ Opcodes.i32_to_u ] : [])
948
- ])
950
+ ...(!nonbinary ? [ Opcodes.i32_from_u ] : [])
951
+ ] : (!intIn && nonbinary ? [ Opcodes.i32_to_u ] : []))
949
952
  ];
953
+
950
954
  if (isIntOp(wasm[wasm.length - 1])) return [
951
955
  ...wasm,
952
956
  ...(truthyMode === 'full' ? [
953
957
  [ Opcodes.i32_eqz ],
954
958
  [ Opcodes.i32_eqz ]
955
959
  ] : []),
956
- ...(intOut ? [] : [ Opcodes.i32_from ]),
960
+ ...(nonbinary ? [] : [ Opcodes.i32_from ])
957
961
  ];
958
962
 
959
963
  // todo/perf: use knownType and custom bytecode here instead of typeSwitch
@@ -973,21 +977,21 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
973
977
  [ Opcodes.f64_gt ]
974
978
  ]),
975
979
 
976
- ...(intOut ? [] : [ Opcodes.i32_from ]),
980
+ ...(nonbinary ? [] : [ Opcodes.i32_from ]),
977
981
  ];
978
982
 
979
983
  if (truthyMode === 'no_negative') return [
980
984
  // if value != 0 or NaN, non-binary output. negative numbers not truthy :/
981
985
  ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
982
986
  ...(intIn ? [] : [ Opcodes.i32_to ]),
983
- ...(intOut ? [] : [ Opcodes.i32_from ])
987
+ ...(nonbinary ? [] : [ Opcodes.i32_from ])
984
988
  ];
985
989
 
986
990
  if (truthyMode === 'no_nan_negative') return [
987
991
  // simpler and faster but makes NaN truthy and negative numbers not truthy,
988
992
  // plus non-binary output
989
993
  ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
990
- ...(!intOut || (intIn && intOut) ? [] : [ Opcodes.i32_to_u ])
994
+ ...(!nonbinary || (intIn && nonbinary) ? [] : [ Opcodes.i32_to_u ])
991
995
  ];
992
996
  })();
993
997
 
@@ -1004,27 +1008,32 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
1004
1008
  [ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
1005
1009
 
1006
1010
  // if length != 0
1007
- /* [ Opcodes.i32_eqz ],
1008
- [ Opcodes.i32_eqz ], */
1009
- ...(intOut ? [] : [ Opcodes.i32_from_u ])
1011
+ ...(nonbinary ? [] : [
1012
+ [ Opcodes.i32_eqz ],
1013
+ [ Opcodes.i32_eqz ],
1014
+ Opcodes.i32_from_u
1015
+ ])
1010
1016
  ] ],
1011
1017
 
1012
1018
  ...(truthyMode === 'full' ? [ [ [ TYPES.booleanobject, TYPES.numberobject ], [
1013
1019
  // always truthy :))
1014
1020
  ...(!useTmp ? [ [ Opcodes.drop ] ] : []),
1015
- number(1, intOut ? Valtype.i32 : valtypeBinary)
1021
+ number(1, nonbinary ? Valtype.i32 : valtypeBinary)
1016
1022
  ] ] ] : []),
1017
1023
 
1018
1024
  [ 'default', def ]
1019
- ], intOut ? Valtype.i32 : valtypeBinary)
1025
+ ], nonbinary ? Valtype.i32 : valtypeBinary)
1020
1026
  ];
1021
1027
  };
1022
1028
 
1023
- const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode = undefined) => {
1029
+ const falsy = (scope, wasm, type, nonbinary = true, intIn = false) => {
1030
+ // nonbinary = true: int output, 0 or non-0
1031
+ // nonbinary = false: float output, 0 or 1
1032
+
1024
1033
  const useTmp = knownType(scope, type) == null;
1025
1034
  const tmp = useTmp && localTmp(scope, `#logicinner_tmp${intIn ? '_int' : ''}`, intIn ? Valtype.i32 : valtypeBinary);
1026
1035
 
1027
- const truthyMode = forceTruthyMode ?? Prefs.truthy ?? 'full';
1036
+ const truthyMode = Prefs.truthy ?? 'full';
1028
1037
  const def = (() => {
1029
1038
  if (truthyMode === 'full') return [
1030
1039
  // if value == 0 or NaN
@@ -1038,7 +1047,7 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode
1038
1047
  [ Opcodes.i32_eqz ]
1039
1048
  ]),
1040
1049
 
1041
- ...(intOut ? [] : [ Opcodes.i32_from ]),
1050
+ ...(nonbinary ? [] : [ Opcodes.i32_from ]),
1042
1051
  ];
1043
1052
 
1044
1053
  if (truthyMode === 'no_negative') return [
@@ -1046,15 +1055,15 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode
1046
1055
  ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
1047
1056
  ...(intIn ? [] : [ Opcodes.i32_to ]),
1048
1057
  [ Opcodes.i32_eqz ],
1049
- ...(intOut ? [] : [ Opcodes.i32_from ])
1058
+ ...(nonbinary ? [] : [ Opcodes.i32_from ])
1050
1059
  ];
1051
1060
 
1052
1061
  if (truthyMode === 'no_nan_negative') return [
1053
1062
  // simpler and faster but makes NaN truthy and negative numbers not truthy,
1054
1063
  // plus non-binary output
1055
1064
  ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
1056
- ...(intIn ? [ [ Opcodes.i32_eqz ] ] : [ ...Opcodes.eqz ]),
1057
- ...(intOut ? [] : [ Opcodes.i32_from_u ])
1065
+ ...(intIn ? [ [ Opcodes.i32_eqz ] ] : Opcodes.eqz),
1066
+ ...(nonbinary ? [] : [ Opcodes.i32_from_u ])
1058
1067
  ];
1059
1068
  })();
1060
1069
 
@@ -1072,21 +1081,24 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode
1072
1081
 
1073
1082
  // if length == 0
1074
1083
  [ Opcodes.i32_eqz ],
1075
- ...(intOut ? [] : [ Opcodes.i32_from_u ])
1084
+ ...(nonbinary ? [] : [ Opcodes.i32_from_u ])
1076
1085
  ] ],
1077
1086
 
1078
1087
  ...(truthyMode === 'full' ? [ [ [ TYPES.booleanobject, TYPES.numberobject ], [
1079
1088
  // always truthy :))
1080
1089
  ...(!useTmp ? [ [ Opcodes.drop ] ] : []),
1081
- number(0, intOut ? Valtype.i32 : valtypeBinary)
1090
+ number(0, nonbinary ? Valtype.i32 : valtypeBinary)
1082
1091
  ] ] ] : []),
1083
1092
 
1084
1093
  [ 'default', def ]
1085
- ], intOut ? Valtype.i32 : valtypeBinary)
1094
+ ], nonbinary ? Valtype.i32 : valtypeBinary)
1086
1095
  ];
1087
1096
  };
1088
1097
 
1089
- const nullish = (scope, wasm, type, intIn = false, intOut = false) => {
1098
+ const nullish = (scope, wasm, type, nonbinary = true, intIn = false) => {
1099
+ // nonbinary = true: int output, 0 or non-0
1100
+ // nonbinary = false: float output, 0 or 1
1101
+
1090
1102
  const useTmp = knownType(scope, type) == null;
1091
1103
  const tmp = useTmp && localTmp(scope, `#logicinner_tmp${intIn ? '_int' : ''}`, intIn ? Valtype.i32 : valtypeBinary);
1092
1104
 
@@ -1098,21 +1110,21 @@ const nullish = (scope, wasm, type, intIn = false, intOut = false) => {
1098
1110
  [ TYPES.undefined, [
1099
1111
  // empty
1100
1112
  ...(!useTmp ? [ [ Opcodes.drop ] ] : []),
1101
- number(1, intOut ? Valtype.i32 : valtypeBinary)
1113
+ number(1, nonbinary ? Valtype.i32 : valtypeBinary)
1102
1114
  ] ],
1103
1115
  [ TYPES.object, [
1104
1116
  // object, null if == 0
1105
1117
  ...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
1106
1118
 
1107
- ...(intIn ? [ [ Opcodes.i32_eqz ] ] : [ ...Opcodes.eqz ]),
1108
- ...(intOut ? [] : [ Opcodes.i32_from_u ])
1119
+ ...(intIn ? [ [ Opcodes.i32_eqz ] ] : Opcodes.eqz),
1120
+ ...(nonbinary ? [] : [ Opcodes.i32_from_u ])
1109
1121
  ] ],
1110
1122
  [ 'default', [
1111
1123
  // not
1112
1124
  ...(!useTmp ? [ [ Opcodes.drop ] ] : []),
1113
- number(0, intOut ? Valtype.i32 : valtypeBinary)
1125
+ number(0, nonbinary ? Valtype.i32 : valtypeBinary)
1114
1126
  ] ]
1115
- ], intOut ? Valtype.i32 : valtypeBinary)
1127
+ ], nonbinary ? Valtype.i32 : valtypeBinary)
1116
1128
  ];
1117
1129
  };
1118
1130
 
@@ -1348,14 +1360,14 @@ const generateBinaryExp = (scope, decl) => {
1348
1360
  // opt: == null|undefined -> nullish
1349
1361
  if (decl.operator === '==' || decl.operator === '!=') {
1350
1362
  if (knownNullish(decl.right)) {
1351
- const out = nullish(scope, generate(scope, decl.left), getNodeType(scope, decl.left), false, true);
1363
+ const out = nullish(scope, generate(scope, decl.left), getNodeType(scope, decl.left));
1352
1364
  if (decl.operator === '!=') out.push([ Opcodes.i32_eqz ]);
1353
1365
  out.push(Opcodes.i32_from_u);
1354
1366
  return out;
1355
1367
  }
1356
1368
 
1357
1369
  if (knownNullish(decl.left)) {
1358
- const out = nullish(scope, generate(scope, decl.right), getNodeType(scope, decl.right), false, true);
1370
+ const out = nullish(scope, generate(scope, decl.right), getNodeType(scope, decl.right));
1359
1371
  if (decl.operator === '!=') out.push([ Opcodes.i32_eqz ]);
1360
1372
  out.push(Opcodes.i32_from_u);
1361
1373
  return out;
@@ -1450,7 +1462,9 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
1450
1462
  }
1451
1463
  }, extra);
1452
1464
 
1453
- const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globalInits = {}, returns = [], returnType, localNames = [], globalNames = [], table = false, constr = false, hasRestArgument = false, usesTag = false, usesImports = false, returnTypes } = {}) => {
1465
+ const asmFunc = (name, func) => {
1466
+ func = { ...func };
1467
+ let { wasm, params, locals: localTypes, localNames = [], table, usesTag, returnTypes, returnType } = func;
1454
1468
  if (wasm == null) { // called with no built-in
1455
1469
  log.warning('codegen', `${name} has no built-in!`);
1456
1470
  wasm = [];
@@ -1465,19 +1479,11 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
1465
1479
  locals[localNames[i] ?? `l${i}`] = { idx: i, type: allLocals[i] };
1466
1480
  }
1467
1481
 
1468
- const func = {
1469
- name,
1470
- params,
1471
- typedParams,
1472
- locals,
1473
- localInd: allLocals.length,
1474
- returns,
1475
- returnType,
1476
- internal: true,
1477
- index: currentFuncIndex++,
1478
- globalInits,
1479
- constr, table, usesImports, hasRestArgument
1480
- };
1482
+ func.internal = true;
1483
+ func.name = name;
1484
+ func.locals = locals;
1485
+ func.localInd = allLocals.length;
1486
+ func.index = currentFuncIndex++;
1481
1487
 
1482
1488
  funcs.push(func);
1483
1489
  funcIndex[name] = func.index;
@@ -1505,8 +1511,9 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
1505
1511
  typeUsed(func, returnType);
1506
1512
  }
1507
1513
 
1508
- func.jsLength = countLength(func);
1514
+ if (func.jsLength == null) func.jsLength = countLength(func);
1509
1515
  func.wasm = wasm;
1516
+
1510
1517
  return func;
1511
1518
  };
1512
1519
 
@@ -2483,14 +2490,13 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2483
2490
  out = out.concat(generate(scope, arg), valtypeBinary === Valtype.i32 && scope.locals[arg.name]?.type !== Valtype.f64 ? [ [ Opcodes.f64_convert_i32_s ] ] : [], getNodeType(scope, arg));
2484
2491
  }
2485
2492
 
2486
- let knownThis = undefined, getCallee = undefined;
2487
-
2488
2493
  const tmpName = '#indirect' + uniqId() + '_';
2489
2494
  const calleeLocal = localTmp(scope, tmpName + 'callee');
2495
+ let callee = decl.callee, callAsNew = decl._new, sup = false, knownThis = undefined;
2490
2496
 
2491
2497
  // hack: this should be more thorough, Function.bind, etc
2492
- if (!decl._new && (decl.callee.type === 'MemberExpression' || decl.callee.type === 'ChainExpression')) {
2493
- const { property, object, computed, optional } = decl.callee.expression ?? decl.callee;
2498
+ if (!callAsNew && (callee.type === 'MemberExpression' || callee.type === 'ChainExpression')) {
2499
+ const { property, object, computed, optional } = callee.expression ?? callee;
2494
2500
  if (object && property) {
2495
2501
  const thisLocal = localTmp(scope, tmpName + 'caller');
2496
2502
  const thisLocalType = localTmp(scope, tmpName + 'caller#type', Valtype.i32);
@@ -2499,7 +2505,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2499
2505
  [ Opcodes.local_get, thisLocal ],
2500
2506
  [ Opcodes.local_get, thisLocalType ]
2501
2507
  ];
2502
- getCallee = generate(scope, {
2508
+ callee = {
2503
2509
  type: 'MemberExpression',
2504
2510
  object: {
2505
2511
  type: 'Wasm',
@@ -2516,11 +2522,10 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2516
2522
  property,
2517
2523
  computed,
2518
2524
  optional
2519
- });
2525
+ };
2520
2526
  }
2521
2527
  }
2522
2528
 
2523
- let callee = decl.callee, callAsNew = decl._new, sup = false;
2524
2529
  if (callee.type === 'Super') {
2525
2530
  // call super constructor with direct super() call
2526
2531
  callee = getObjProp(callee, 'constructor');
@@ -2538,7 +2543,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2538
2543
  const thisWasm = decl._thisWasm ?? knownThis ?? createThisArg(scope, decl);
2539
2544
 
2540
2545
  out = [
2541
- ...(getCallee ? getCallee : generate(scope, callee)),
2546
+ ...generate(scope, callee),
2542
2547
  [ Opcodes.local_set, calleeLocal ],
2543
2548
 
2544
2549
  ...typeSwitch(scope, getNodeType(scope, callee), {
@@ -4244,11 +4249,11 @@ const generateUnary = (scope, decl) => {
4244
4249
  const arg = decl.argument;
4245
4250
  if (arg.type === 'UnaryExpression' && arg.operator === '!') {
4246
4251
  // opt: !!x -> is x truthy
4247
- return truthy(scope, generate(scope, arg.argument), getNodeType(scope, arg.argument), false, false, 'full');
4252
+ return truthy(scope, generate(scope, arg.argument), getNodeType(scope, arg.argument), false);
4248
4253
  }
4249
4254
 
4250
4255
  // !=
4251
- return falsy(scope, generate(scope, arg), getNodeType(scope, arg), false, false);
4256
+ return falsy(scope, generate(scope, arg), getNodeType(scope, arg), false);
4252
4257
 
4253
4258
  case 'void': {
4254
4259
  // drop current expression value after running, give undefined
@@ -4449,7 +4454,7 @@ const generateIf = (scope, decl) => {
4449
4454
  ];
4450
4455
  }
4451
4456
 
4452
- const out = truthy(scope, generate(scope, decl.test), getNodeType(scope, decl.test), false, true);
4457
+ const out = truthy(scope, generate(scope, decl.test), getNodeType(scope, decl.test));
4453
4458
  out.push([ Opcodes.if, Blocktype.void ]);
4454
4459
  depth.push('if');
4455
4460
  inferBranchStart(scope, decl.consequent);
@@ -4480,7 +4485,7 @@ const generateIf = (scope, decl) => {
4480
4485
  };
4481
4486
 
4482
4487
  const generateConditional = (scope, decl) => {
4483
- const out = truthy(scope, generate(scope, decl.test), getNodeType(scope, decl.test), false, true);
4488
+ const out = truthy(scope, generate(scope, decl.test), getNodeType(scope, decl.test));
4484
4489
 
4485
4490
  out.push([ Opcodes.if, valtypeBinary ]);
4486
4491
  depth.push('if');
@@ -5630,6 +5635,7 @@ const generateArray = (scope, decl, global = false, name = '$undeclared', static
5630
5635
  Opcodes.i32_from_u
5631
5636
  );
5632
5637
 
5638
+ typeUsed(scope, TYPES.array);
5633
5639
  return out;
5634
5640
  };
5635
5641
 
@@ -5755,37 +5761,14 @@ const countParams = (func, name = undefined) => {
5755
5761
  let params = func.params.length;
5756
5762
  if (func.constr) params -= 4;
5757
5763
  if (func.method) params -= 2;
5758
- if (!func.internal || builtinFuncs[name]?.typedParams) params = Math.floor(params / 2);
5764
+ if (!func.internal || func.typedParams) params = Math.floor(params / 2);
5759
5765
 
5760
5766
  return func.argc = params;
5761
5767
  };
5762
5768
 
5763
5769
  const countLength = (func, name = undefined) => {
5764
5770
  if (func && func.jsLength != null) return func.jsLength;
5765
-
5766
- name ??= func.name;
5767
-
5768
- let count = countParams(func, name);
5769
- if (builtinFuncs[name] && name.includes('_prototype_')) count--;
5770
- if (func.hasRestArgument) count--;
5771
-
5772
- if (func.internal) {
5773
- // some js built-ins have an old non-standard length
5774
- const override = ({
5775
- Array: 1,
5776
- String: 1,
5777
- __Object_assign: 2,
5778
- __String_fromCharCode: 1,
5779
- __String_fromCodePoint: 1,
5780
- __Array_prototype_concat: 1,
5781
- __Array_prototype_push: 1,
5782
- __Array_prototype_unshift: 1,
5783
- __String_prototype_concat: 1,
5784
- __ByteString_prototype_concat: 1
5785
- })[name];
5786
- if (override != null) return override;
5787
- }
5788
- return count;
5771
+ return countParams(func, name ?? func.name);
5789
5772
  };
5790
5773
 
5791
5774
  const generateMember = (scope, decl, _global, _name) => {
@@ -6157,7 +6140,7 @@ const generateMember = (scope, decl, _global, _name) => {
6157
6140
  ...generate(scope, object),
6158
6141
  [ Opcodes.local_tee, objectTmp ],
6159
6142
 
6160
- ...nullish(scope, [], type, false, true),
6143
+ ...nullish(scope, [], type),
6161
6144
  [ Opcodes.if, Blocktype.void ],
6162
6145
  ...setLastType(scope, TYPES.undefined),
6163
6146
  number(0),
@@ -7061,6 +7044,25 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
7061
7044
  args.push({ name, def, destr, type: typedInput && x.typeAnnotation });
7062
7045
  }
7063
7046
 
7047
+ // custom built-in length changes
7048
+ if (globalThis.precompile) {
7049
+ if (name.includes('_prototype_')) jsLength--;
7050
+ jsLength = ({
7051
+ Array: 1,
7052
+ String: 1,
7053
+ __Object_assign: 2,
7054
+ __String_fromCharCode: 1,
7055
+ __String_fromCodePoint: 1,
7056
+ __Array_prototype_concat: 1,
7057
+ __Array_prototype_push: 1,
7058
+ __Array_prototype_unshift: 1,
7059
+ __String_prototype_concat: 1,
7060
+ __ByteString_prototype_concat: 1,
7061
+ __Atomics_wait: 4,
7062
+ __Atomics_notify: 3
7063
+ })[name] ?? jsLength;
7064
+ }
7065
+
7064
7066
  func.params = new Array((params.length + (func.constr ? 2 : (func.method ? 1 : 0))) * 2).fill(0).map((_, i) => i % 2 ? Valtype.i32 : valtypeBinary);
7065
7067
  func.jsLength = jsLength;
7066
7068
 
package/compiler/index.js CHANGED
@@ -75,9 +75,6 @@ export default (code, module = Prefs.module) => {
75
75
  let outFile = Prefs.o;
76
76
  const logProgress = Prefs.profileCompiler || (outFile && !Prefs.native);
77
77
 
78
- globalThis.valtype = Prefs.valtype ?? 'f64';
79
- globalThis.valtypeBinary = Valtype[valtype];
80
-
81
78
  // use smaller page sizes internally (65536 / 4 = 16384)
82
79
  globalThis.pageSize = Prefs.pageSize ?? (PageSize / 4);
83
80
 
@@ -280,7 +280,7 @@ ${funcs.map(x => {
280
280
  const returnTypes = [...(x.returnTypes ?? [])].filter(x => ![ TYPES.undefined, TYPES.number, TYPES.boolean, TYPES.function ].includes(x));
281
281
  return `this${name} = {
282
282
  wasm:${rewriteWasm(x.wasm)},
283
- params:${JSON.stringify(x.params)},typedParams:1,returns:${JSON.stringify(x.returns)},${x.returnType != null ? `returnType:${JSON.stringify(x.returnType)},` : ''}${returnTypes.length > 0 ? `returnTypes:${JSON.stringify(returnTypes)},` : ''}
283
+ params:${JSON.stringify(x.params)},typedParams:1,returns:${JSON.stringify(x.returns)},${x.returnType != null ? `returnType:${JSON.stringify(x.returnType)},` : ''}${returnTypes.length > 0 ? `returnTypes:${JSON.stringify(returnTypes)},` : ''}jsLength:${x.jsLength},
284
284
  locals:${JSON.stringify(locals.slice(x.params.length).map(x => x[1].type))},localNames:${JSON.stringify(locals.map(x => x[0]))},
285
285
  ${x.globalInits ? `globalInits:{${Object.keys(x.globalInits).map(y => `${y}:${rewriteWasm(x.globalInits[y])}`).join(',')}},` : ''}${x.data && Object.keys(x.data).length > 0 ? `data:${JSON.stringify(x.data)},` : ''}
286
286
  ${x.table ? `table:1,` : ''}${x.constr ? `constr:1,` : ''}${x.hasRestArgument ? `hasRestArgument:1,` : ''}${x.usesTag ? `usesTag:1,` : ''}${x.usesImports ? `usesImports:1,` : ''}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.59.2",
4
+ "version": "0.59.3",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runtime/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.59.2';
3
+ globalThis.version = '0.59.3';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
package/AGENT.md DELETED
@@ -1,22 +0,0 @@
1
- you are an assistant coder for Porffor - an early javascript and typescript to webassembly and native ahead-of-time compiler. the codebase is written in js and ts.
2
-
3
- IMPORTANT:
4
- - built-ins apis (Date, String.prototype, etc) are written in ts inside `compiler/builtins`
5
- - once you update a file inside that directory, you MUST run `./porf precompile` to compile to make your changes effective
6
-
7
- Test your work using the test262 tools available, iterate independently but do not get stuck on one chain of thought or approach. Paths for test262 tools should be relative to the 'test262/test' directory (e.g., 'built-ins/RegExp' NOT 'test262/test/built-ins/RegExp').
8
-
9
- You can also do the following via bash/shell commands:
10
- - To get an overview of the most failing directories, use the command: `node test262/fails.cjs`
11
- - To just evaluate code in the engine, use the command: `./porf -p "..."`
12
-
13
- ## Code Style
14
- - After finishing, check if your work/diff could be simplified
15
- - Always use single quotes (unless double is required)
16
- - 2-space indentation, LF line endings, no trailing whitespace
17
- - Built-in APIs in `compiler/builtins/` written in TypeScript
18
- - Inline code in built-ins, avoid helper functions
19
- - Use semicolons
20
- - Do not use trailing commas
21
- - Use const/let, avoid var
22
- - Follow existing naming: camelCase for variables, PascalCase for types