porffor 0.2.0-fde989a → 0.14.0-0d97d1e6a
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 +256 -0
- package/LICENSE +20 -20
- package/README.md +131 -86
- package/asur/README.md +2 -0
- package/asur/index.js +1262 -0
- package/byg/index.js +216 -0
- package/compiler/2c.js +2 -53
- package/compiler/{sections.js → assemble.js} +95 -21
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +18 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +76 -0
- package/compiler/builtins/boolean.ts +18 -0
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/date.ts +2067 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/function.ts +5 -0
- package/compiler/builtins/int.ts +145 -0
- package/compiler/builtins/number.ts +529 -0
- package/compiler/builtins/object.ts +4 -0
- package/compiler/builtins/porffor.d.ts +60 -0
- package/compiler/builtins/set.ts +187 -0
- package/compiler/builtins/string.ts +1080 -0
- package/compiler/builtins/symbol.ts +61 -0
- package/compiler/builtins.js +440 -285
- package/compiler/{codeGen.js → codegen.js} +1116 -489
- package/compiler/decompile.js +3 -4
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +94 -10
- package/compiler/expression.js +1 -1
- package/compiler/generated_builtins.js +1670 -0
- package/compiler/index.js +27 -43
- package/compiler/log.js +6 -3
- package/compiler/opt.js +55 -41
- package/compiler/parse.js +38 -30
- package/compiler/precompile.js +120 -0
- package/compiler/prefs.js +31 -0
- package/compiler/prototype.js +31 -46
- package/compiler/types.js +38 -0
- package/compiler/wasmSpec.js +33 -8
- package/compiler/wrap.js +107 -71
- package/package.json +9 -5
- package/porf +2 -0
- package/rhemyn/compile.js +46 -27
- package/rhemyn/parse.js +322 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +33 -34
- package/runner/debug.js +117 -0
- package/runner/index.js +78 -11
- package/runner/profiler.js +75 -0
- package/runner/repl.js +40 -13
- package/runner/sizes.js +37 -37
- package/runner/version.js +10 -8
- package/compiler/builtins/base64.js +0 -92
- package/filesize.cmd +0 -2
- package/runner/info.js +0 -89
- package/runner/profile.js +0 -46
- package/runner/results.json +0 -1
- package/runner/transform.js +0 -15
- package/tmp.c +0 -661
- package/util/enum.js +0 -20
package/runner/version.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
import
|
1
|
+
import { readFileSync } from 'node:fs';
|
2
2
|
|
3
|
-
let
|
4
|
-
|
5
|
-
rev = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version.split('-')[1].slice(0, 7);
|
6
|
-
} catch {
|
7
|
-
rev = fs.readFileSync(new URL('../.git/refs/heads/main', import.meta.url), 'utf8').trim().slice(0, 7);
|
8
|
-
}
|
3
|
+
export let version = 'unknown';
|
4
|
+
export let rev = 'unknown';
|
9
5
|
|
10
|
-
|
6
|
+
const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
7
|
+
version = packageJson.version.split('-')[0];
|
8
|
+
rev = packageJson.version.split('-')[1];
|
9
|
+
|
10
|
+
if (!rev) rev = readFileSync(new URL('../.git/refs/heads/main', import.meta.url), 'utf8').trim().slice(0, 9);
|
11
|
+
|
12
|
+
export default `${version}-${rev}`;
|
@@ -1,92 +0,0 @@
|
|
1
|
-
var btoa_a = str => {
|
2
|
-
// todo: throw invalid character for unicode
|
3
|
-
|
4
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
5
|
-
const mask = (1 << 6) - 1;
|
6
|
-
|
7
|
-
let out = '';
|
8
|
-
let bits = 0, buffer = 0;
|
9
|
-
for (let i = 0; i < str.length; i++) {
|
10
|
-
buffer = (buffer << 8) | (0xff & str.charCodeAt(i));
|
11
|
-
bits += 8;
|
12
|
-
|
13
|
-
while (bits > 6) {
|
14
|
-
bits -= 6;
|
15
|
-
out += chars[mask & (buffer >> bits)];
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
if (bits) {
|
20
|
-
out += chars[mask & (buffer << (6 - bits))]
|
21
|
-
}
|
22
|
-
|
23
|
-
while ((out.length * 6) & 7) {
|
24
|
-
out += '=';
|
25
|
-
}
|
26
|
-
|
27
|
-
return out;
|
28
|
-
};
|
29
|
-
|
30
|
-
var btoa = function (input) {
|
31
|
-
// todo: throw invalid character for unicode
|
32
|
-
const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
33
|
-
|
34
|
-
let output = "";
|
35
|
-
let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
36
|
-
let i = 0;
|
37
|
-
|
38
|
-
while (i < input.length) {
|
39
|
-
chr1 = input.charCodeAt(i++);
|
40
|
-
chr2 = input.charCodeAt(i++);
|
41
|
-
chr3 = input.charCodeAt(i++);
|
42
|
-
|
43
|
-
enc1 = chr1 >> 2;
|
44
|
-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
45
|
-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
46
|
-
enc4 = chr3 & 63;
|
47
|
-
|
48
|
-
if (isNaN(chr2)) {
|
49
|
-
enc3 = enc4 = 64;
|
50
|
-
} else if (isNaN(chr3)) {
|
51
|
-
enc4 = 64;
|
52
|
-
}
|
53
|
-
|
54
|
-
output += keyStr.charAt(enc1);
|
55
|
-
output += keyStr.charAt(enc2);
|
56
|
-
output += keyStr.charAt(enc3);
|
57
|
-
output += keyStr.charAt(enc4);
|
58
|
-
}
|
59
|
-
|
60
|
-
return output;
|
61
|
-
};
|
62
|
-
|
63
|
-
var atob_b = function (input) {
|
64
|
-
const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
65
|
-
|
66
|
-
let output = "";
|
67
|
-
let chr1, chr2, chr3;
|
68
|
-
let enc1, enc2, enc3, enc4;
|
69
|
-
let i = 0;
|
70
|
-
|
71
|
-
while (i < input.length) {
|
72
|
-
enc1 = keyStr.indexOf(input.charAt(i++));
|
73
|
-
enc2 = keyStr.indexOf(input.charAt(i++));
|
74
|
-
enc3 = keyStr.indexOf(input.charAt(i++));
|
75
|
-
enc4 = keyStr.indexOf(input.charAt(i++));
|
76
|
-
|
77
|
-
chr1 = (enc1 << 2) | (enc2 >> 4);
|
78
|
-
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
79
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
80
|
-
|
81
|
-
output += String.fromCharCode(chr1);
|
82
|
-
|
83
|
-
if (enc3 != 64) {
|
84
|
-
output += String.fromCharCode(chr2);
|
85
|
-
}
|
86
|
-
if (enc4 != 64) {
|
87
|
-
output += String.fromCharCode(chr3);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
return output;
|
92
|
-
};
|
package/filesize.cmd
DELETED
package/runner/info.js
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
import compile from '../compiler/wrap.js';
|
2
|
-
import fs from 'node:fs';
|
3
|
-
|
4
|
-
/* if (globalThis.process) {
|
5
|
-
const v8 = await import('node:v8');
|
6
|
-
v8.setFlagsFromString('--experimental-wasm-gc');
|
7
|
-
} */
|
8
|
-
|
9
|
-
const raw = process.argv.includes('-raw');
|
10
|
-
|
11
|
-
const file = process.argv.slice(2).find(x => x[0] !== '-');
|
12
|
-
if (!file) {
|
13
|
-
// run repl if no file given
|
14
|
-
await import('./repl.js');
|
15
|
-
|
16
|
-
// do nothing for the rest of this file
|
17
|
-
await new Promise(() => {});
|
18
|
-
}
|
19
|
-
|
20
|
-
const source = fs.readFileSync(file, 'utf8');
|
21
|
-
|
22
|
-
const underline = x => `\u001b[4m\u001b[1m${x}\u001b[0m`;
|
23
|
-
const bold = x => `\u001b[1m${x}\u001b[0m`;
|
24
|
-
|
25
|
-
if (!raw) console.log(`\n${underline('source')}\n` + source);
|
26
|
-
if (!raw) console.log(`\n\n${underline('processing')}`);
|
27
|
-
|
28
|
-
let cache = '';
|
29
|
-
const print = str => {
|
30
|
-
cache += str;
|
31
|
-
|
32
|
-
if (str === '\n') {
|
33
|
-
process.stdout.write(cache);
|
34
|
-
cache = '';
|
35
|
-
}
|
36
|
-
};
|
37
|
-
|
38
|
-
const t0 = performance.now();
|
39
|
-
const { wasm, exports, pages } = await compile(source, raw ? [ 'module' ] : [ 'module', 'info' ], {}, print);
|
40
|
-
|
41
|
-
if (!raw && typeof Deno === 'undefined') fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
42
|
-
|
43
|
-
if (!process.argv.includes('-no-run')) {
|
44
|
-
console.log(`\n\n${underline('output')}`);
|
45
|
-
const t2 = performance.now();
|
46
|
-
|
47
|
-
exports.main();
|
48
|
-
print('\n');
|
49
|
-
|
50
|
-
if (!raw) console.log(bold(`\n\nexecuted in ${(performance.now() - t2).toFixed(2)}ms`));
|
51
|
-
}
|
52
|
-
|
53
|
-
if (!raw) console.log(bold(`wasm binary is ${wasm.byteLength} bytes`));
|
54
|
-
if (!raw) console.log(`total: ${(performance.now() - t0).toFixed(2)}ms`);
|
55
|
-
|
56
|
-
if (!raw && process.argv.includes('-mem') && exports.$) {
|
57
|
-
console.log();
|
58
|
-
|
59
|
-
let lastMemory, lastPages;
|
60
|
-
const PageSize = 65536;
|
61
|
-
const memoryToString = mem => {
|
62
|
-
let out = '';
|
63
|
-
const pages = lastPages.length;
|
64
|
-
const wasmPages = mem.buffer.byteLength / PageSize;
|
65
|
-
|
66
|
-
out += `\x1B[1mallocated ${mem.buffer.byteLength / 1024}KiB\x1B[0m for ${pages} things using ${wasmPages} Wasm page${wasmPages === 1 ? '' : 's'}\n`;
|
67
|
-
|
68
|
-
const buf = new Uint8Array(mem.buffer);
|
69
|
-
|
70
|
-
for (let i = 0; i < pages; i++) {
|
71
|
-
out += `\x1B[36m${lastPages[i]}\x1B[2m | \x1B[0m`;
|
72
|
-
|
73
|
-
for (let j = 0; j < 50; j++) {
|
74
|
-
const val = buf[i * pageSize + j];
|
75
|
-
if (val === 0) out += '\x1B[2m';
|
76
|
-
out += val.toString(16).padStart(2, '0');
|
77
|
-
if (val === 0) out += '\x1B[0m';
|
78
|
-
out += ' ';
|
79
|
-
}
|
80
|
-
out += '\n';
|
81
|
-
}
|
82
|
-
|
83
|
-
return out;
|
84
|
-
};
|
85
|
-
|
86
|
-
lastPages = [...pages.keys()];
|
87
|
-
lastMemory = exports.$;
|
88
|
-
console.log(memoryToString(lastMemory));
|
89
|
-
}
|
package/runner/profile.js
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
import compile from '../compiler/index.js';
|
2
|
-
import fs from 'node:fs';
|
3
|
-
|
4
|
-
let csv = `phase,time\n`;
|
5
|
-
|
6
|
-
csv += `node,${performance.now()}\n`;
|
7
|
-
|
8
|
-
const t0 = performance.now();
|
9
|
-
const file = process.argv.slice(2).find(x => x[0] !== '-');
|
10
|
-
const source = fs.readFileSync(file, 'utf8');
|
11
|
-
csv += `read,${performance.now() - t0}\n`;
|
12
|
-
|
13
|
-
console.log = x => {
|
14
|
-
if (x.includes(' in ')) {
|
15
|
-
csv += [ 'parse', 'codegen', 'opt', 'sections' ][parseInt(x[0]) - 1] + ',' + x.split(' in ')[1].slice(0, -2) + '\n';
|
16
|
-
}
|
17
|
-
};
|
18
|
-
|
19
|
-
const wasm = compile(source, [ 'info' ]);
|
20
|
-
|
21
|
-
let cache = '';
|
22
|
-
const print = str => {
|
23
|
-
cache += str;
|
24
|
-
|
25
|
-
if (str === '\n') {
|
26
|
-
process.stdout.write(cache);
|
27
|
-
cache = '';
|
28
|
-
}
|
29
|
-
};
|
30
|
-
|
31
|
-
const t1 = performance.now();
|
32
|
-
const { instance } = await WebAssembly.instantiate(wasm, {
|
33
|
-
'': {
|
34
|
-
p: i => print(Number(i).toString()),
|
35
|
-
c: i => print(String.fromCharCode(Number(i)))
|
36
|
-
}
|
37
|
-
});
|
38
|
-
csv += `inst,${performance.now() - t1}\n`;
|
39
|
-
|
40
|
-
const t2 = performance.now();
|
41
|
-
instance.exports.m();
|
42
|
-
print('\n');
|
43
|
-
|
44
|
-
csv += `exec,${performance.now() - t2}`;
|
45
|
-
|
46
|
-
fs.writeFileSync(`profile.csv`, csv);
|