porffor 0.0.0-44bc2d8 → 0.0.0-48403fd
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 +50 -15
- package/c +0 -0
- package/c.exe +0 -0
- package/compiler/2c.js +354 -0
- package/compiler/builtins.js +14 -12
- package/compiler/codeGen.js +859 -332
- package/compiler/decompile.js +21 -5
- package/compiler/embedding.js +9 -5
- package/compiler/encoding.js +4 -2
- package/compiler/index.js +56 -5
- package/compiler/opt.js +337 -251
- package/compiler/parse.js +1 -0
- package/compiler/prototype.js +172 -34
- package/compiler/sections.js +46 -5
- package/compiler/wasmSpec.js +3 -0
- package/compiler/wrap.js +11 -5
- package/cool.exe +0 -0
- package/fib.js +10 -0
- package/g +0 -0
- package/g.exe +0 -0
- package/hi.c +37 -0
- package/out +0 -0
- package/out.exe +0 -0
- package/package.json +1 -1
- package/r.js +39 -0
- package/rhemyn/README.md +37 -0
- package/rhemyn/compile.js +214 -0
- package/rhemyn/parse.js +321 -0
- package/rhemyn/test/parse.js +59 -0
- package/runner/index.js +54 -34
- package/runner/info.js +37 -2
- package/runner/repl.js +4 -11
- package/runner/results.json +1 -0
- package/runner/transform.js +2 -1
- package/runner/version.js +10 -0
- package/tmp.c +61 -0
- package/t.js +0 -31
package/runner/info.js
CHANGED
@@ -36,7 +36,7 @@ const print = str => {
|
|
36
36
|
};
|
37
37
|
|
38
38
|
const t0 = performance.now();
|
39
|
-
const { wasm, exports } = await compile(source, raw ? [ 'module' ] : [ 'module', 'info' ], {}, print);
|
39
|
+
const { wasm, exports, pages } = await compile(source, raw ? [ 'module' ] : [ 'module', 'info' ], {}, print);
|
40
40
|
|
41
41
|
if (!raw && typeof Deno === 'undefined') fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
42
42
|
|
@@ -51,4 +51,39 @@ if (!process.argv.includes('-no-run')) {
|
|
51
51
|
}
|
52
52
|
|
53
53
|
if (!raw) console.log(bold(`wasm binary is ${wasm.byteLength} bytes`));
|
54
|
-
if (!raw) console.log(`total: ${(performance.now() - t0).toFixed(2)}ms`);
|
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/repl.js
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
import compile from '../compiler/wrap.js';
|
2
|
+
import rev from './version.js';
|
2
3
|
|
3
4
|
import repl from 'node:repl';
|
4
|
-
import fs from 'node:fs';
|
5
|
-
|
6
|
-
let rev = 'unknown';
|
7
|
-
try {
|
8
|
-
rev = fs.readFileSync(new URL('../.git/refs/heads/main', import.meta.url), 'utf8').trim().slice(0, 7);
|
9
|
-
} catch {
|
10
|
-
rev = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version.split('-')[1];
|
11
|
-
}
|
12
5
|
|
13
6
|
// process.argv.push('-O0'); // disable opts
|
14
7
|
|
@@ -28,7 +21,7 @@ const memoryToString = mem => {
|
|
28
21
|
const pages = lastPages.length;
|
29
22
|
const wasmPages = mem.buffer.byteLength / PageSize;
|
30
23
|
|
31
|
-
out += `\x1B[1mallocated ${mem.buffer.byteLength / 1024}
|
24
|
+
out += `\x1B[1mallocated ${mem.buffer.byteLength / 1024}KB\x1B[0m for ${pages} thing${pages === 1 ? '' : 's'} using ${wasmPages} Wasm page${wasmPages === 1 ? '' : 's'}\n`;
|
32
25
|
|
33
26
|
const buf = new Uint8Array(mem.buffer);
|
34
27
|
|
@@ -48,7 +41,7 @@ const memoryToString = mem => {
|
|
48
41
|
return out;
|
49
42
|
};
|
50
43
|
|
51
|
-
const alwaysPrev = process.argv.includes('-
|
44
|
+
const alwaysPrev = process.argv.includes('-prev');
|
52
45
|
|
53
46
|
let prev = '';
|
54
47
|
const run = async (source, _context, _filename, callback, run = true) => {
|
@@ -56,7 +49,7 @@ const run = async (source, _context, _filename, callback, run = true) => {
|
|
56
49
|
if (alwaysPrev) prev = toRun + ';\n';
|
57
50
|
|
58
51
|
const { exports, wasm, pages } = await compile(toRun, []);
|
59
|
-
fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
52
|
+
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
60
53
|
|
61
54
|
if (run && exports.$) {
|
62
55
|
lastMemory = exports.$;
|