porffor 0.2.0-fdf0fc5 → 0.14.0-032e4ad08
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 +9 -3
- package/README.md +17 -14
- package/asur/index.js +1 -1
- package/byg/index.js +3 -24
- package/compiler/2c.js +66 -54
- package/compiler/assemble.js +51 -11
- package/compiler/builtins/annexb_string.js +10 -10
- package/compiler/builtins/annexb_string.ts +4 -3
- package/compiler/builtins/array.ts +85 -9
- package/compiler/builtins/base64.ts +2 -1
- package/compiler/builtins/boolean.ts +2 -2
- package/compiler/builtins/crypto.ts +2 -1
- package/compiler/builtins/date.ts +2 -3
- package/compiler/builtins/error.js +22 -0
- package/compiler/builtins/escape.ts +2 -3
- package/compiler/builtins/function.ts +1 -1
- package/compiler/builtins/int.ts +1 -1
- package/compiler/builtins/math.ts +410 -0
- package/compiler/builtins/number.ts +4 -7
- package/compiler/builtins/object.ts +1 -1
- package/compiler/builtins/porffor.d.ts +9 -8
- package/compiler/builtins/set.ts +197 -3
- package/compiler/builtins/string.ts +2 -1
- package/compiler/builtins/symbol.ts +62 -0
- package/compiler/builtins.js +41 -15
- package/compiler/codegen.js +653 -366
- package/compiler/decompile.js +3 -3
- package/compiler/embedding.js +2 -2
- package/compiler/encoding.js +0 -14
- package/compiler/expression.js +1 -1
- package/compiler/generated_builtins.js +771 -187
- package/compiler/index.js +5 -11
- package/compiler/opt.js +7 -7
- package/compiler/parse.js +2 -4
- package/compiler/precompile.js +18 -25
- package/compiler/prefs.js +6 -2
- package/compiler/prototype.js +185 -162
- package/compiler/wasmSpec.js +5 -0
- package/compiler/wrap.js +150 -90
- package/package.json +1 -1
- package/porffor_tmp.c +202 -0
- package/runner/compare.js +0 -1
- package/runner/debug.js +1 -6
- package/runner/index.js +5 -4
- package/runner/profiler.js +15 -42
- package/runner/repl.js +20 -10
- package/runner/sizes.js +2 -2
- package/runner/version.js +10 -8
package/runner/repl.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
import { TYPE_NAMES } from '../compiler/types.js';
|
1
2
|
import compile from '../compiler/wrap.js';
|
2
|
-
import
|
3
|
+
import version from './version.js';
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
import util from 'node:util';
|
6
|
+
|
7
|
+
process.argv.push('--no-opt-unused');
|
6
8
|
|
7
9
|
let repl;
|
8
10
|
try {
|
@@ -17,8 +19,6 @@ try {
|
|
17
19
|
repl = (await import('node-repl-polyfill')).default;
|
18
20
|
}
|
19
21
|
|
20
|
-
// process.argv.push('-O0'); // disable opts
|
21
|
-
|
22
22
|
globalThis.valtype = 'f64';
|
23
23
|
|
24
24
|
const valtypeOpt = process.argv.find(x => x.startsWith('--valtype='));
|
@@ -32,7 +32,7 @@ if (host.startsWith('Node')) host = '\x1B[92m' + host;
|
|
32
32
|
if (host.startsWith('Deno')) host = '\x1B[97m' + host;
|
33
33
|
if (host.startsWith('Bun')) host = '\x1B[93m' + host;
|
34
34
|
|
35
|
-
console.log(`Welcome to \x1B[1m\x1B[35mPorffor\x1B[0m \x1B[90m(${
|
35
|
+
console.log(`Welcome to \x1B[1m\x1B[35mPorffor\x1B[0m \x1B[90m(${version})\x1B[0m running on \x1B[1m${host.replace('/', ' \x1B[0m\x1B[90m(')})\x1B[0m`);
|
36
36
|
console.log(`\x1B[90musing opt ${process.argv.find(x => x.startsWith('-O')) ?? '-O1'}, parser ${parser}, valtype ${valtype}\x1B[0m`);
|
37
37
|
console.log();
|
38
38
|
|
@@ -81,21 +81,31 @@ const run = async (source, _context, _filename, callback, run = true) => {
|
|
81
81
|
let toRun = (prev ? (prev + `;\nprint(-0x1337);\n`) : '') + source.trim();
|
82
82
|
|
83
83
|
let shouldPrint = !prev;
|
84
|
-
const { exports,
|
84
|
+
const { exports, pages } = await compile(toRun, [], {}, str => {
|
85
85
|
if (shouldPrint) process.stdout.write(str);
|
86
86
|
if (str === '-4919') shouldPrint = true;
|
87
87
|
});
|
88
|
-
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
89
88
|
|
90
89
|
if (run && exports.$) {
|
91
90
|
lastMemory = exports.$;
|
92
91
|
lastPages = [...pages.keys()];
|
93
92
|
}
|
94
93
|
|
95
|
-
|
96
|
-
|
94
|
+
let ret = run ? exports.main() : undefined;
|
95
|
+
let value, type;
|
96
|
+
if (ret?.type != null) {
|
97
|
+
value = ret.value;
|
98
|
+
type = ret.type;
|
99
|
+
ret = ret.js;
|
100
|
+
}
|
101
|
+
|
102
|
+
console.log(util.inspect(ret, false, 2, true), (value != null ? `\x1B[34m\x1B[3m(value: ${value}, type: ${TYPE_NAMES[type]})\x1B[0m` : ''));
|
103
|
+
|
104
|
+
// callback(null, ret);
|
97
105
|
|
98
106
|
prev = prev + ';\n' + source.trim();
|
107
|
+
|
108
|
+
callback();
|
99
109
|
};
|
100
110
|
|
101
111
|
const replServer = repl.start({ prompt: '> ', eval: run });
|
package/runner/sizes.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import fs from 'node:fs';
|
2
1
|
import compile from '../compiler/index.js';
|
2
|
+
import fs from 'node:fs';
|
3
3
|
|
4
4
|
// deno compat
|
5
5
|
const textEncoder = new TextEncoder();
|
@@ -18,7 +18,7 @@ const perform = async (file, args) => {
|
|
18
18
|
console.log(label, ' '.repeat(40 - label.length), `${size}b`);
|
19
19
|
};
|
20
20
|
|
21
|
-
const argsValtypes = [ '--valtype=i32', '--valtype=
|
21
|
+
const argsValtypes = [ '--valtype=i32', '--valtype=f64' ];
|
22
22
|
const argsOptlevels = [ '-O0', '-O1', '-O2', '-O3' ];
|
23
23
|
|
24
24
|
for (const file of [ 'bench/prime_basic.js', 'bench/fib_iter.js', 'test/math_1.js', 'test/math_3.js', 'test/while_1.js', 'test/for_2.js', 'test/unary_3.js', 'test/updateexp_1.js', 'test/eq_3.js', 'test/empty.js' ]) {
|
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}`;
|