porffor 0.57.8 → 0.57.10

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.
@@ -9,18 +9,31 @@ export const importedFuncs = {};
9
9
  Object.defineProperty(importedFuncs, 'length', { configurable: true, writable: true, value: 0 });
10
10
 
11
11
  export const createImport = (name, params, returns, js = null, c = null) => {
12
- if (name in importedFuncs) return false;
12
+ const lazy = () => {
13
+ if (typeof params === 'function') params = params();
14
+ if (typeof returns === 'function') returns = returns();
15
+ if (typeof params === 'number') params = new Array(params).fill(valtypeBinary);
16
+ if (typeof returns === 'number') returns = new Array(returns).fill(valtypeBinary);
17
+ };
18
+
19
+ if (name in importedFuncs) {
20
+ // overwrite existing import
21
+ const existing = importedFuncs[name];
22
+ lazy();
23
+
24
+ existing.params = params;
25
+ existing.returns = returns;
26
+ existing.js = js;
27
+ existing.c = c;
28
+ return;
29
+ }
13
30
 
14
31
  const call = importedFuncs.length;
15
32
  const ident = String.fromCharCode(97 + importedFuncs.length);
16
33
  let obj;
17
34
  const get = () => {
18
35
  if (obj) return obj;
19
-
20
- if (typeof params === 'function') params = params();
21
- if (typeof returns === 'function') returns = returns();
22
- if (typeof params === 'number') params = new Array(params).fill(valtypeBinary);
23
- if (typeof returns === 'number') returns = new Array(returns).fill(valtypeBinary);
36
+ lazy();
24
37
 
25
38
  obj = new Number(call);
26
39
  obj.name = name;
@@ -2703,7 +2703,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2703
2703
 
2704
2704
  if (
2705
2705
  func?.returns?.length === 0 ||
2706
- (idx === importedFuncs[name] && importedFuncs[importedFuncs[name]]?.returns === 0)
2706
+ (idx === importedFuncs[name] && importedFuncs[importedFuncs[name]]?.returns?.length === 0)
2707
2707
  ) {
2708
2708
  out.push(number(UNDEFINED));
2709
2709
  }
@@ -5750,7 +5750,7 @@ const generateMember = (scope, decl, _global, _name) => {
5750
5750
  if (func) return withType(scope, [ number(countLength(func, name)) ], TYPES.number);
5751
5751
 
5752
5752
  if (Object.hasOwn(builtinFuncs, name)) return withType(scope, [ number(countLength(builtinFuncs[name], name)) ], TYPES.number);
5753
- if (Object.hasOwn(importedFuncs, name)) return withType(scope, [ number(importedFuncs[name].params.length ?? importedFuncs[name].params) ], TYPES.number);
5753
+ if (Object.hasOwn(importedFuncs, name)) return withType(scope, [ number(importedFuncs[name].params.length) ], TYPES.number);
5754
5754
  if (Object.hasOwn(internalConstrs, name)) return withType(scope, [ number(internalConstrs[name].length ?? 0) ], TYPES.number);
5755
5755
  }
5756
5756
 
@@ -102,8 +102,8 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
102
102
  const callFunc = funcs.find(x => x.index === idx);
103
103
  if (callFunc) out += ` ;; $${callFunc.name} ${makeSignature(callFunc.params, callFunc.returns)}`;
104
104
  if (globalThis.importFuncs && idx < importFuncs.length) {
105
- const importFunc = importFuncs[idx];
106
- out += ` ;; import ${importFunc.name} ${makeSignature(typeof importFunc.params === 'object' ? importFunc.params : new Array(importFunc.params).fill(valtypeBinary), new Array(importFunc.returns).fill(valtypeBinary),)}`;
105
+ const importFunc = globalThis.importFuncs[idx];
106
+ out += ` ;; import ${importFunc.name} ${makeSignature(importFunc.params, importFunc.returns)}`;
107
107
  }
108
108
  }
109
109
 
package/compiler/wrap.js CHANGED
@@ -383,21 +383,6 @@ export default (source, module = undefined, customImports = {}, print = str => p
383
383
 
384
384
  for (const x in customImports) {
385
385
  const custom = customImports[x];
386
-
387
- if (x in importedFuncs) {
388
- // overwrite with user custom import
389
- const existing = importedFuncs[x];
390
- if (typeof custom === 'function') {
391
- existing.js = custom;
392
- } else {
393
- existing.params = custom.params;
394
- existing.returns = custom.returns;
395
- existing.js = custom.js;
396
- existing.c = custom.c;
397
- }
398
- continue;
399
- }
400
-
401
386
  // todo: make a simpler api for just js functions at some point using function.length etc
402
387
  createImport(x, custom.params, custom.returns, custom.js, custom.c);
403
388
  }
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.57.8",
4
+ "version": "0.57.10",
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.57.8';
3
+ globalThis.version = '0.57.10';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {