porffor 0.58.19 → 0.59.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.
- package/AGENT.md +16 -7
- package/compiler/assemble.js +2 -13
- package/compiler/builtins/regexp.ts +186 -7
- package/compiler/builtins/string.ts +0 -35
- package/compiler/builtins/string_f64.ts +97 -0
- package/compiler/builtins.js +30 -37
- package/compiler/builtins_precompiled.js +381 -369
- package/compiler/codegen.js +60 -15
- package/compiler/pgo.js +21 -43
- package/compiler/wrap.js +3 -8
- package/fuzz/index.js +1 -1
- package/package.json +1 -1
- package/runtime/debug.js +1 -1
- package/runtime/index.js +1 -1
- package/runtime/profile.js +1 -1
- package/runtime/repl.js +1 -1
- package/wow.js +0 -1
package/compiler/builtins.js
CHANGED
@@ -5,8 +5,11 @@ import { TYPES, TYPE_NAMES } from './types.js';
|
|
5
5
|
import { number, unsignedLEB128 } from './encoding.js';
|
6
6
|
import './prefs.js';
|
7
7
|
|
8
|
-
export
|
9
|
-
|
8
|
+
export let importedFuncs;
|
9
|
+
export const setImports = (v = null) => {
|
10
|
+
importedFuncs = v ?? { length: 0 };
|
11
|
+
};
|
12
|
+
setImports();
|
10
13
|
|
11
14
|
/**
|
12
15
|
* Create an import function for the Porffor world to use.
|
@@ -18,51 +21,41 @@ Object.defineProperty(importedFuncs, 'length', { configurable: true, writable: t
|
|
18
21
|
* @param {string} c - C source code to compile as import implementation
|
19
22
|
*/
|
20
23
|
export const createImport = (name, params, returns, js = null, c = null) => {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
if (!globalThis.valtypeBinary) {
|
25
|
+
globalThis.valtype ??= Prefs.valtype ?? 'f64';
|
26
|
+
globalThis.valtypeBinary = Valtype[valtype];
|
27
|
+
}
|
28
|
+
|
29
|
+
if (typeof params === 'number') params = new Array(params).fill(valtypeBinary);
|
30
|
+
if (typeof returns === 'number') returns = new Array(returns).fill(valtypeBinary);
|
27
31
|
|
28
32
|
if (name in importedFuncs) {
|
29
33
|
// overwrite existing import
|
30
34
|
const existing = importedFuncs[name];
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
const call = +existing;
|
36
|
+
const replacement = new Number(call);
|
37
|
+
replacement.name = name;
|
38
|
+
replacement.import = existing.import;
|
39
|
+
replacement.params = params;
|
40
|
+
replacement.returns = returns;
|
41
|
+
replacement.js = js;
|
42
|
+
replacement.c = c;
|
43
|
+
|
44
|
+
importedFuncs[name] = replacement;
|
37
45
|
return;
|
38
46
|
}
|
39
47
|
|
40
48
|
const call = importedFuncs.length;
|
41
49
|
const ident = String.fromCharCode(97 + importedFuncs.length);
|
42
|
-
let obj;
|
43
|
-
const get = () => {
|
44
|
-
if (obj) return obj;
|
45
|
-
lazy();
|
46
|
-
|
47
|
-
obj = new Number(call);
|
48
|
-
obj.name = name;
|
49
|
-
obj.import = ident;
|
50
|
-
obj.params = params;
|
51
|
-
obj.returns = returns;
|
52
|
-
obj.js = js;
|
53
|
-
obj.c = c;
|
54
|
-
return obj;
|
55
|
-
};
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
});
|
51
|
+
const obj = importedFuncs[name] = importedFuncs[call] = new Number(call);
|
52
|
+
obj.name = name;
|
53
|
+
obj.import = ident;
|
54
|
+
obj.params = params;
|
55
|
+
obj.returns = returns;
|
56
|
+
obj.js = js;
|
57
|
+
obj.c = c;
|
58
|
+
|
66
59
|
importedFuncs.length = call + 1;
|
67
60
|
};
|
68
61
|
|