porffor 0.27.1 → 0.28.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.
@@ -2429,6 +2429,14 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2429
2429
  [ Opcodes.i32_load16_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize), 'read func lut' ]
2430
2430
  ], tableBc, valtypeBinary)
2431
2431
  ],
2432
+
2433
+ ...(decl.optional ? {
2434
+ [TYPES.undefined]: [
2435
+ ...number(UNDEFINED),
2436
+ ...setLastType(scope, TYPES.undefined)
2437
+ ]
2438
+ } : {}),
2439
+
2432
2440
  default: internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, true)
2433
2441
  })
2434
2442
  ];
@@ -2682,7 +2690,7 @@ const typeSwitch = (scope, type, bc, returns = valtypeBinary) => {
2682
2690
  if (Prefs.typeswitchBrtable)
2683
2691
  return brTable(type, bc, returns);
2684
2692
 
2685
- const tmp = localTmp(scope, '#typeswitch_tmp' + (Prefs.typeswitchUniqueTmp ? randId() : ''), Valtype.i32);
2693
+ const tmp = localTmp(scope, '#typeswitch_tmp' + (Prefs.typeswitchUniqueTmp ? uniqId() : ''), Valtype.i32);
2686
2694
  const out = [
2687
2695
  ...type,
2688
2696
  [ Opcodes.local_set, tmp ],
@@ -2833,7 +2841,7 @@ const generateVar = (scope, decl) => {
2833
2841
  for (const x of decl.declarations) {
2834
2842
  if (x.id.type === 'ArrayPattern') {
2835
2843
  const decls = [];
2836
- const tmpName = '#destructure' + randId();
2844
+ const tmpName = '#destructure' + uniqId();
2837
2845
 
2838
2846
  let i = 0;
2839
2847
  const elements = [...x.id.elements];
@@ -4489,7 +4497,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
4489
4497
 
4490
4498
  const out = [];
4491
4499
 
4492
- const uniqueName = name === '$undeclared' ? name + randId() : name;
4500
+ const uniqueName = name === '$undeclared' ? name + uniqId() : name;
4493
4501
 
4494
4502
  const useRawElements = !!decl.rawElements;
4495
4503
  const elements = useRawElements ? decl.rawElements : decl.elements;
@@ -4750,7 +4758,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
4750
4758
  ];
4751
4759
 
4752
4760
  if (decl.properties.length > 0) {
4753
- const tmp = localTmp(scope, `#objectexpr${randId()}`, Valtype.i32);
4761
+ const tmp = localTmp(scope, `#objectexpr${uniqId()}`, Valtype.i32);
4754
4762
  out.push([ Opcodes.local_tee, tmp ]);
4755
4763
 
4756
4764
  for (const x of decl.properties) {
@@ -5164,7 +5172,8 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5164
5172
  return out;
5165
5173
  };
5166
5174
 
5167
- const randId = () => '_' + Math.random().toString(16).slice(2, -2).padEnd(12, '0');
5175
+ globalThis._uniqId = 0;
5176
+ const uniqId = () => '_' + globalThis._uniqId++;
5168
5177
 
5169
5178
  let objectHackers = [];
5170
5179
  const objectHack = node => {
@@ -5211,9 +5220,7 @@ const objectHack = node => {
5211
5220
  };
5212
5221
 
5213
5222
  const generateFunc = (scope, decl) => {
5214
- if (decl.generator) return todo(scope, 'generator functions are not supported');
5215
-
5216
- const name = decl.id ? decl.id.name : `anonymous${randId()}`;
5223
+ const name = decl.id ? decl.id.name : `anonymous${uniqId()}`;
5217
5224
  const params = decl.params ?? [];
5218
5225
 
5219
5226
  // TODO: share scope/locals between !!!
@@ -5234,6 +5241,19 @@ const generateFunc = (scope, decl) => {
5234
5241
  funcIndex[name] = func.index;
5235
5242
  funcs.push(func);
5236
5243
 
5244
+ let errorWasm = null;
5245
+ if (decl.generator) errorWasm = todo(scope, 'generator functions are not supported');
5246
+
5247
+ if (errorWasm) {
5248
+ func.wasm = errorWasm.concat([
5249
+ ...number(UNDEFINED),
5250
+ ...number(TYPES.undefined, Valtype.i32)
5251
+ ]);
5252
+ func.params = [];
5253
+ func.constr = false;
5254
+ return func;
5255
+ }
5256
+
5237
5257
  if (typedInput && decl.returnType) {
5238
5258
  const { type } = extractTypeAnnotation(decl.returnType);
5239
5259
  if (type != null && !Prefs.indirectCalls) {
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.27.1+eb4ce4d61",
4
+ "version": "0.28.0+2cee067f8",
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.27.1+eb4ce4d61';
3
+ globalThis.version = '0.28.0+2cee067f8';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {