porffor 0.14.0-f67c123a1 → 0.16.0-08983b6b1
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/CONTRIBUTING.md +16 -10
- package/README.md +14 -30
- package/asur/index.js +1 -1
- package/compiler/2c.js +172 -59
- package/compiler/allocators.js +128 -0
- package/compiler/assemble.js +37 -5
- package/compiler/builtins/annexb_string.ts +1 -0
- package/compiler/builtins/array.ts +154 -7
- package/compiler/builtins/base64.ts +1 -0
- package/compiler/builtins/boolean.ts +3 -1
- package/compiler/builtins/console.ts +6 -0
- package/compiler/builtins/crypto.ts +1 -0
- package/compiler/builtins/date.ts +5 -30
- package/compiler/builtins/error.js +22 -0
- package/compiler/builtins/escape.ts +1 -2
- package/compiler/builtins/function.ts +2 -0
- package/compiler/builtins/int.ts +2 -0
- package/compiler/builtins/math.ts +410 -0
- package/compiler/builtins/number.ts +12 -21
- package/compiler/builtins/object.ts +2 -0
- package/compiler/builtins/porffor.d.ts +18 -0
- package/compiler/builtins/set.ts +22 -12
- package/compiler/builtins/string.ts +1 -0
- package/compiler/builtins/string_f64.ts +10 -0
- package/compiler/builtins/symbol.ts +62 -0
- package/compiler/builtins/z_ecma262.ts +62 -0
- package/compiler/builtins.js +50 -12
- package/compiler/codegen.js +826 -552
- package/compiler/cyclone.js +535 -0
- package/compiler/decompile.js +7 -1
- package/compiler/generated_builtins.js +635 -84
- package/compiler/havoc.js +93 -0
- package/compiler/index.js +108 -15
- package/compiler/opt.js +10 -44
- package/compiler/parse.js +3 -9
- package/compiler/pgo.js +212 -0
- package/compiler/precompile.js +17 -11
- package/compiler/prefs.js +13 -5
- package/compiler/prototype.js +200 -186
- package/compiler/wasmSpec.js +2 -2
- package/compiler/wrap.js +128 -44
- package/package.json +3 -5
- package/runner/index.js +31 -15
- package/runner/repl.js +18 -2
- /package/runner/{profiler.js → profile.js} +0 -0
package/compiler/precompile.js
CHANGED
@@ -18,15 +18,15 @@ const compile = async (file, [ _funcs, _globals ]) => {
|
|
18
18
|
first = source.slice(0, source.indexOf('\n'));
|
19
19
|
}
|
20
20
|
|
21
|
-
let args = ['--bytestring', '--todo-time=compile', '--
|
21
|
+
let args = ['--bytestring', '--todo-time=compile', '--truthy=no_nan_negative', '--no-treeshake-wasm-imports', '--no-rm-unused-types', '--scoped-page-names', '--funsafe-no-unlikely-proto-checks', '--fast-length', '--parse-types', '--opt-types'];
|
22
22
|
if (first.startsWith('// @porf')) {
|
23
|
-
args =
|
23
|
+
args = first.slice('// @porf '.length).split(' ').concat(args);
|
24
24
|
}
|
25
25
|
process.argv = argv.concat(args);
|
26
26
|
|
27
27
|
const porfCompile = (await import(`./index.js?_=${Date.now()}`)).default;
|
28
28
|
|
29
|
-
let { funcs, globals, data, exceptions } = porfCompile(source, ['module']);
|
29
|
+
let { funcs, globals, data, exceptions } = porfCompile(source, ['module', 'typed']);
|
30
30
|
|
31
31
|
const allocated = new Set();
|
32
32
|
|
@@ -35,14 +35,17 @@ const compile = async (file, [ _funcs, _globals ]) => {
|
|
35
35
|
if (x.data) {
|
36
36
|
x.data = x.data.map(x => data[x]);
|
37
37
|
for (const y in x.data) {
|
38
|
-
x.data[y].offset -= x.data[0].offset;
|
38
|
+
if (x.data[y].offset != null) x.data[y].offset -= x.data[0].offset;
|
39
39
|
}
|
40
40
|
}
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
|
42
|
+
if (x.exceptions) {
|
43
|
+
x.exceptions = x.exceptions.map(x => {
|
44
|
+
const obj = exceptions[x];
|
45
|
+
if (obj) obj.exceptId = x;
|
46
|
+
return obj;
|
47
|
+
}).filter(x => x);
|
48
|
+
}
|
46
49
|
|
47
50
|
const locals = Object.keys(x.locals).reduce((acc, y) => {
|
48
51
|
acc[x.locals[y].idx] = { ...x.locals[y], name: y };
|
@@ -87,6 +90,8 @@ const compile = async (file, [ _funcs, _globals ]) => {
|
|
87
90
|
};
|
88
91
|
|
89
92
|
const precompile = async () => {
|
93
|
+
if (globalThis._porf_loadParser) await globalThis._porf_loadParser('@babel/parser');
|
94
|
+
|
90
95
|
const dir = join(__dirname, 'builtins');
|
91
96
|
|
92
97
|
let funcs = [], globals = [];
|
@@ -111,8 +116,9 @@ ${funcs.map(x => {
|
|
111
116
|
${x.returnType != null ? `returnType: ${JSON.stringify(x.returnType)}` : 'typedReturns: true'},
|
112
117
|
locals: ${JSON.stringify(Object.values(x.locals).slice(x.params.length).map(x => x.type))},
|
113
118
|
localNames: ${JSON.stringify(Object.keys(x.locals))},
|
114
|
-
${x.data && x.data.length > 0 ? ` data: ${JSON.stringify(x.data)}
|
115
|
-
|
119
|
+
${x.data && x.data.length > 0 ? ` data: ${JSON.stringify(x.data)},` : ''}
|
120
|
+
${x.table ? ` table: true` : ''}
|
121
|
+
};`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n');
|
116
122
|
}).join('\n')}
|
117
123
|
};`;
|
118
124
|
};
|
package/compiler/prefs.js
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
const onByDefault = [ 'bytestring', '
|
1
|
+
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'rmUnusedTypes' ];
|
2
2
|
|
3
3
|
let cache = {};
|
4
4
|
const obj = new Proxy({}, {
|
5
5
|
get(_, p) {
|
6
|
-
|
7
|
-
if (cache[p]) return cache[p];
|
6
|
+
if (cache[p] != null) return cache[p];
|
8
7
|
|
9
|
-
|
8
|
+
const ret = (() => {
|
10
9
|
// fooBar -> foo-bar
|
11
10
|
const name = p[0] === '_' ? p : p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
12
11
|
const prefix = name.length === 1 ? '-' : '--';
|
@@ -19,9 +18,18 @@ const obj = new Proxy({}, {
|
|
19
18
|
if (onByDefault.includes(p)) return true;
|
20
19
|
return undefined;
|
21
20
|
})();
|
21
|
+
|
22
|
+
// do not cache in web demo as args are changed live
|
23
|
+
if (!globalThis.document) cache[p] = ret;
|
24
|
+
return ret;
|
25
|
+
},
|
26
|
+
|
27
|
+
set(_, p, v) {
|
28
|
+
cache[p] = v;
|
29
|
+
return true;
|
22
30
|
}
|
23
31
|
});
|
24
32
|
|
25
|
-
|
33
|
+
export const uncache = () => cache = {};
|
26
34
|
|
27
35
|
export default obj;
|