porffor 0.57.9 → 0.57.11
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.
- package/compiler/builtins.js +19 -6
- package/compiler/precompile.js +6 -0
- package/compiler/wrap.js +0 -15
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/builtins.js
CHANGED
@@ -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
|
-
|
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;
|
package/compiler/precompile.js
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
import { Opcodes, Valtype } from './wasmSpec.js';
|
2
2
|
import { read_signedLEB128 } from './encoding.js';
|
3
3
|
import { TYPES, TYPE_NAMES } from './types.js';
|
4
|
+
import { createImport } from './builtins.js';
|
4
5
|
import { log } from './log.js';
|
5
6
|
|
7
|
+
createImport('print', 1, 0);
|
8
|
+
createImport('printChar', 1, 0);
|
9
|
+
createImport('time', 0, 1);
|
10
|
+
createImport('timeOrigin', 0, 1);
|
11
|
+
|
6
12
|
import process from 'node:process';
|
7
13
|
globalThis.process = process;
|
8
14
|
|
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