porffor 0.16.0-688a50c13 → 0.16.0-7339fdd79
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/README.md +5 -17
- package/compiler/2c.js +75 -15
- package/compiler/allocators.js +128 -0
- package/compiler/assemble.js +7 -1
- package/compiler/builtins/array.ts +72 -5
- package/compiler/builtins/date.ts +2 -27
- package/compiler/builtins/number.ts +10 -21
- package/compiler/builtins/porffor.d.ts +7 -0
- package/compiler/builtins/set.ts +1 -2
- package/compiler/builtins/z_ecma262.ts +62 -0
- package/compiler/codegen.js +116 -74
- package/compiler/generated_builtins.js +100 -62
- package/compiler/index.js +15 -1
- package/compiler/opt.js +1 -1
- package/compiler/parse.js +0 -6
- package/compiler/pgo.js +5 -0
- package/compiler/precompile.js +1 -1
- package/compiler/prefs.js +1 -2
- package/compiler/wasmSpec.js +2 -2
- package/compiler/wrap.js +16 -15
- package/package.json +1 -1
- package/runner/index.js +5 -0
- package/a.txt +0 -457
- package/b.txt +0 -457
- package/compiler/allocators/grow.js +0 -26
- package/compiler/allocators/index.js +0 -10
- package/compiler/allocators/static.js +0 -42
- package/no_pgo.txt +0 -923
- package/pgo.txt +0 -916
package/compiler/index.js
CHANGED
@@ -45,6 +45,8 @@ export default (code, flags) => {
|
|
45
45
|
if (target !== 'wasm') Prefs.pgo = Prefs.pgo === false ? false : true;
|
46
46
|
if (Prefs.pgo) pgo.setup();
|
47
47
|
|
48
|
+
if (Prefs.profileCompiler) console.log(`0. began compilation (host runtime startup) in ${performance.now().toFixed(2)}ms`);
|
49
|
+
|
48
50
|
const t0 = performance.now();
|
49
51
|
const program = parse(code, flags);
|
50
52
|
if (Prefs.profileCompiler) console.log(`1. parsed in ${(performance.now() - t0).toFixed(2)}ms`);
|
@@ -107,7 +109,7 @@ export default (code, flags) => {
|
|
107
109
|
|
108
110
|
if (Prefs.optFuncs) logFuncs(funcs, globals, exceptions);
|
109
111
|
|
110
|
-
if (Prefs.
|
112
|
+
if (Prefs.compileAllocLog) {
|
111
113
|
const wasmPages = Math.ceil((pages.size * pageSize) / 65536);
|
112
114
|
const bytes = wasmPages * 65536;
|
113
115
|
log('alloc', `\x1B[1mallocated ${bytes / 1024}KiB\x1B[0m for ${pages.size} things using ${wasmPages} Wasm page${wasmPages === 1 ? '' : 's'}`);
|
@@ -148,7 +150,12 @@ export default (code, flags) => {
|
|
148
150
|
const args = [ ...compiler, tmpfile, '-o', outFile ?? (process.platform === 'win32' ? 'out.exe' : 'out'), '-' + cO ];
|
149
151
|
if (!Prefs.compiler) args.push('-flto=thin', '-march=native', '-s', '-ffast-math', '-fno-exceptions', '-fno-ident', '-fno-asynchronous-unwind-tables', '-ffunction-sections', '-fdata-sections', '-Wl,--gc-sections');
|
150
152
|
|
153
|
+
const t4 = performance.now();
|
151
154
|
const c = toc(out);
|
155
|
+
if (Prefs.profileCompiler) console.log(`5. compiled to c in ${(performance.now() - t4).toFixed(2)}ms`);
|
156
|
+
|
157
|
+
const t5 = performance.now();
|
158
|
+
|
152
159
|
fs.writeFileSync(tmpfile, c);
|
153
160
|
|
154
161
|
// obvious command escape is obvious
|
@@ -156,6 +163,8 @@ export default (code, flags) => {
|
|
156
163
|
|
157
164
|
fs.unlinkSync(tmpfile);
|
158
165
|
|
166
|
+
if (Prefs.profileCompiler) console.log(`6. compiled to native (using ${compiler}) in ${(performance.now() - t5).toFixed(2)}ms`);
|
167
|
+
|
159
168
|
if (process.version) {
|
160
169
|
if (Prefs.native) {
|
161
170
|
const cleanup = () => {
|
@@ -177,6 +186,11 @@ export default (code, flags) => {
|
|
177
186
|
} catch {}
|
178
187
|
}
|
179
188
|
|
189
|
+
if (!Prefs.native && globalThis.file) {
|
190
|
+
const total = performance.now();
|
191
|
+
console.log(`\u001b[90m[${total.toFixed(2)}ms]\u001b[0m \u001b[92mcompiled ${globalThis.file} -> ${outFile}\u001b[0m`);
|
192
|
+
}
|
193
|
+
|
180
194
|
process.exit();
|
181
195
|
}
|
182
196
|
}
|
package/compiler/opt.js
CHANGED
@@ -250,7 +250,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
250
250
|
}
|
251
251
|
|
252
252
|
// remove setting last type if it is never gotten
|
253
|
-
if (!f.gotLastType && inst[0] === Opcodes.local_set && inst[1] === lastType) {
|
253
|
+
if (!f.internal && !f.gotLastType && inst[0] === Opcodes.local_set && inst[1] === lastType) {
|
254
254
|
// replace this inst with drop
|
255
255
|
wasm.splice(i, 1, [ Opcodes.drop ]); // remove this and last inst
|
256
256
|
if (i > 0) i--;
|
package/compiler/parse.js
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
import { log } from './log.js';
|
2
2
|
import Prefs from './prefs.js';
|
3
3
|
|
4
|
-
// deno compat
|
5
|
-
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
|
6
|
-
const textEncoder = new TextEncoder();
|
7
|
-
globalThis.process = { argv: ['', '', ...Deno.args], stdout: { write: str => Deno.writeAllSync(Deno.stdout, textEncoder.encode(str)) } };
|
8
|
-
}
|
9
|
-
|
10
4
|
const file = process.argv.slice(2).find(x => x[0] !== '-' && !['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(x));
|
11
5
|
|
12
6
|
// should we try to support types (while parsing)
|
package/compiler/pgo.js
CHANGED
@@ -78,6 +78,9 @@ export const run = obj => {
|
|
78
78
|
try {
|
79
79
|
obj.wasm = assemble(obj.funcs, obj.globals, obj.tags, obj.pages, obj.data, obj.flags, true);
|
80
80
|
|
81
|
+
Prefs._profileCompiler = Prefs.profileCompiler;
|
82
|
+
Prefs.profileCompiler = false;
|
83
|
+
|
81
84
|
const { exports } = wrap(obj, [], {
|
82
85
|
y: n => {
|
83
86
|
activeFunc = n;
|
@@ -105,6 +108,8 @@ export const run = obj => {
|
|
105
108
|
throw e;
|
106
109
|
}
|
107
110
|
|
111
|
+
Prefs.profileCompiler = Prefs._profileCompiler;
|
112
|
+
|
108
113
|
for (const x of funcs) {
|
109
114
|
const wasmFunc = wasmFuncs.find(y => y.name === x.name);
|
110
115
|
wasmFunc.wasm = wasmFunc.originalWasm;
|
package/compiler/precompile.js
CHANGED
@@ -35,7 +35,7 @@ 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
41
|
|
package/compiler/prefs.js
CHANGED
@@ -3,8 +3,7 @@ const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'ind
|
|
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
|
package/compiler/wasmSpec.js
CHANGED
@@ -191,6 +191,8 @@ export const Opcodes = {
|
|
191
191
|
i32_trunc_sat_f64_s: [ 0xfc, 0x02 ],
|
192
192
|
i32_trunc_sat_f64_u: [ 0xfc, 0x03 ],
|
193
193
|
|
194
|
+
memory_init: [ 0xfc, 0x08 ],
|
195
|
+
data_drop: [ 0xfc, 0x09 ],
|
194
196
|
memory_copy: [ 0xfc, 0x0a ],
|
195
197
|
|
196
198
|
// simd insts are 0xFD simdop: varuint32
|
@@ -209,8 +211,6 @@ export const Opcodes = {
|
|
209
211
|
i32x4_add: [ 0xfd, 0xae, 0x01 ],
|
210
212
|
i32x4_sub: [ 0xfd, 0xb1, 0x01 ],
|
211
213
|
i32x4_mul: [ 0xfd, 0xb5, 0x01 ],
|
212
|
-
|
213
|
-
i32x4_dot_i16x8_s: [ 0xfd, 0xba, 0x01 ],
|
214
214
|
};
|
215
215
|
|
216
216
|
export const FuncType = 0x60;
|
package/compiler/wrap.js
CHANGED
@@ -11,13 +11,13 @@ const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs'))
|
|
11
11
|
const bold = x => `\u001b[1m${x}\u001b[0m`;
|
12
12
|
|
13
13
|
export const readByteStr = (memory, ptr) => {
|
14
|
-
const length = (new Int32Array(memory.buffer
|
14
|
+
const length = (new Int32Array(memory.buffer, ptr, 1))[0];
|
15
15
|
return Array.from(new Uint8Array(memory.buffer, ptr + 4, length)).map(x => String.fromCharCode(x)).join('');
|
16
16
|
};
|
17
17
|
|
18
18
|
export const writeByteStr = (memory, ptr, str) => {
|
19
19
|
const length = str.length;
|
20
|
-
(new Int32Array(memory.buffer
|
20
|
+
(new Int32Array(memory.buffer, ptr, 1))[0] = length;
|
21
21
|
|
22
22
|
const arr = new Uint8Array(memory.buffer, ptr + 4, length);
|
23
23
|
for (let i = 0; i < length; i++) {
|
@@ -46,17 +46,17 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
46
46
|
}
|
47
47
|
|
48
48
|
case TYPES.string: {
|
49
|
-
const length = (new Int32Array(memory.buffer
|
49
|
+
const length = (new Int32Array(memory.buffer, value, 1))[0];
|
50
50
|
return Array.from(new Uint16Array(memory.buffer, value + 4, length)).map(x => String.fromCharCode(x)).join('');
|
51
51
|
}
|
52
52
|
|
53
53
|
case TYPES.bytestring: {
|
54
|
-
const length = (new Int32Array(memory.buffer
|
54
|
+
const length = (new Int32Array(memory.buffer, value, 1))[0];
|
55
55
|
return Array.from(new Uint8Array(memory.buffer, value + 4, length)).map(x => String.fromCharCode(x)).join('');
|
56
56
|
}
|
57
57
|
|
58
58
|
case TYPES.array: {
|
59
|
-
const length = (new Int32Array(memory.buffer
|
59
|
+
const length = (new Int32Array(memory.buffer, value, 1))[0];
|
60
60
|
|
61
61
|
const out = [];
|
62
62
|
for (let i = 0; i < length; i++) {
|
@@ -77,12 +77,12 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
77
77
|
}
|
78
78
|
|
79
79
|
case TYPES.date: {
|
80
|
-
const t = (new Float64Array(memory.buffer
|
80
|
+
const t = (new Float64Array(memory.buffer, value, 1))[0];
|
81
81
|
return new Date(t);
|
82
82
|
}
|
83
83
|
|
84
84
|
case TYPES.set: {
|
85
|
-
const size = (new Int32Array(memory.buffer
|
85
|
+
const size = (new Int32Array(memory.buffer, value, 1))[0];
|
86
86
|
|
87
87
|
const out = new Set();
|
88
88
|
for (let i = 0; i < size; i++) {
|
@@ -102,17 +102,18 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
102
102
|
return out;
|
103
103
|
}
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
case TYPES.symbol: {
|
106
|
+
const descStore = pages.get('bytestring: __Porffor_symbol_descStore/ptr').ind * pageSize;
|
107
|
+
if (!descStore) return Symbol();
|
108
108
|
|
109
|
-
|
110
|
-
// const t = (new Uint8Array(memory.buffer, offset + 8, 1))[0];
|
109
|
+
const offset = descStore + 4 + ((value - 1) * 9);
|
111
110
|
|
112
|
-
|
111
|
+
const v = (new Float64Array(memory.buffer.slice(offset, offset + 8), 0, 1))[0];
|
112
|
+
const t = (new Uint8Array(memory.buffer, offset + 8, 1))[0];
|
113
113
|
|
114
|
-
|
115
|
-
|
114
|
+
const desc = porfToJSValue({ memory, funcs, pages }, v, t);
|
115
|
+
return Symbol(desc);
|
116
|
+
}
|
116
117
|
|
117
118
|
default: return value;
|
118
119
|
}
|
package/package.json
CHANGED
package/runner/index.js
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import fs from 'node:fs';
|
3
3
|
|
4
|
+
// deno compat
|
5
|
+
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
|
6
|
+
globalThis.process = await import('node:process');
|
7
|
+
}
|
8
|
+
|
4
9
|
const start = performance.now();
|
5
10
|
|
6
11
|
if (process.argv.includes('--compile-hints')) {
|