porffor 0.27.2 → 0.28.1

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.
@@ -1486,7 +1486,7 @@ const getNodeType = (scope, node) => {
1486
1486
  if (scope.locals['#last_type']) return getLastType(scope);
1487
1487
 
1488
1488
  // presume
1489
- // todo: warn here?
1489
+ if (Prefs.warnAssumedType) console.warn(`Indirect call assumed to be number`);
1490
1490
  return TYPES.number;
1491
1491
  }
1492
1492
 
@@ -1524,7 +1524,7 @@ const getNodeType = (scope, node) => {
1524
1524
  if (scope.locals['#last_type']) return getLastType(scope);
1525
1525
 
1526
1526
  // presume
1527
- // todo: warn here?
1527
+ if (Prefs.warnAssumedType) console.warn(`Call to ${name} assumed to be number`);
1528
1528
  return TYPES.number;
1529
1529
 
1530
1530
  // let protoFunc;
@@ -1633,6 +1633,7 @@ const getNodeType = (scope, node) => {
1633
1633
  if (scope.locals['#last_type']) return getLastType(scope);
1634
1634
 
1635
1635
  // presume
1636
+ if (Prefs.warnAssumedType) console.warn(`Member access to field .${name} assumed to be number`);
1636
1637
  return TYPES.number;
1637
1638
  }
1638
1639
 
@@ -1664,7 +1665,7 @@ const getNodeType = (scope, node) => {
1664
1665
  if (scope.locals['#last_type']) return getLastType(scope);
1665
1666
 
1666
1667
  // presume
1667
- // todo: warn here?
1668
+ if (Prefs.warnAssumedType) console.warn(`AST node ${node.type} assumed to be number`);
1668
1669
  return TYPES.number;
1669
1670
  })();
1670
1671
 
@@ -2429,6 +2430,14 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2429
2430
  [ Opcodes.i32_load16_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize), 'read func lut' ]
2430
2431
  ], tableBc, valtypeBinary)
2431
2432
  ],
2433
+
2434
+ ...(decl.optional ? {
2435
+ [TYPES.undefined]: [
2436
+ ...number(UNDEFINED),
2437
+ ...setLastType(scope, TYPES.undefined)
2438
+ ]
2439
+ } : {}),
2440
+
2432
2441
  default: internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, true)
2433
2442
  })
2434
2443
  ];
@@ -5212,8 +5221,6 @@ const objectHack = node => {
5212
5221
  };
5213
5222
 
5214
5223
  const generateFunc = (scope, decl) => {
5215
- if (decl.generator) return todo(scope, 'generator functions are not supported');
5216
-
5217
5224
  const name = decl.id ? decl.id.name : `anonymous${uniqId()}`;
5218
5225
  const params = decl.params ?? [];
5219
5226
 
@@ -5235,6 +5242,19 @@ const generateFunc = (scope, decl) => {
5235
5242
  funcIndex[name] = func.index;
5236
5243
  funcs.push(func);
5237
5244
 
5245
+ let errorWasm = null;
5246
+ if (decl.generator) errorWasm = todo(scope, 'generator functions are not supported');
5247
+
5248
+ if (errorWasm) {
5249
+ func.wasm = errorWasm.concat([
5250
+ ...number(UNDEFINED),
5251
+ ...number(TYPES.undefined, Valtype.i32)
5252
+ ]);
5253
+ func.params = [];
5254
+ func.constr = false;
5255
+ return func;
5256
+ }
5257
+
5238
5258
  if (typedInput && decl.returnType) {
5239
5259
  const { type } = extractTypeAnnotation(decl.returnType);
5240
5260
  if (type != null && !Prefs.indirectCalls) {
@@ -5551,6 +5571,16 @@ const internalConstrs = {
5551
5571
  type: TYPES.undefined,
5552
5572
  notConstr: true,
5553
5573
  length: 1
5574
+ },
5575
+
5576
+ __Porffor_rawType: {
5577
+ generate: (scope, decl) => [
5578
+ ...getNodeType(scope, decl.arguments[0]),
5579
+ Opcodes.i32_from_u
5580
+ ],
5581
+ type: TYPES.number,
5582
+ notConstr: true,
5583
+ length: 1
5554
5584
  }
5555
5585
  };
5556
5586
 
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.2+14ef42051",
4
+ "version": "0.28.1+ae39ecbbe",
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.2+14ef42051';
3
+ globalThis.version = '0.28.1+ae39ecbbe';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {