porffor 0.2.0-77e30e8 → 0.2.0-94ef1ca
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 +1 -1
- package/compiler/index.js +3 -6
- package/compiler/parse.js +29 -5
- package/compiler/wrap.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Porffor <sup><sub>/ˈpɔrfɔr/ *(poor-for)*</sup></sub>
|
2
|
-
A from-scratch experimental
|
2
|
+
A from-scratch experimental **AOT** optimizing JS -> Wasm/C engine/compiler/runtime in JS. Not serious/intended for (real) use. (this is a straight forward, honest readme)<br>
|
3
3
|
Age: ~6 months (very on and off)
|
4
4
|
|
5
5
|
## Design
|
package/compiler/index.js
CHANGED
@@ -28,8 +28,8 @@ const logFuncs = (funcs, globals, exceptions) => {
|
|
28
28
|
|
29
29
|
const getArg = name => process.argv.find(x => x.startsWith(`-${name}=`))?.slice(name.length + 2);
|
30
30
|
|
31
|
-
const writeFileSync = (typeof process !== 'undefined' ? (await import('node:fs')).writeFileSync : undefined);
|
32
|
-
const execSync = (typeof process !== 'undefined' ? (await import('node:child_process')).execSync : undefined);
|
31
|
+
const writeFileSync = (typeof process?.version !== 'undefined' ? (await import('node:fs')).writeFileSync : undefined);
|
32
|
+
const execSync = (typeof process?.version !== 'undefined' ? (await import('node:child_process')).execSync : undefined);
|
33
33
|
|
34
34
|
export default (code, flags) => {
|
35
35
|
globalThis.optLog = process.argv.includes('-opt-log');
|
@@ -75,14 +75,13 @@ export default (code, flags) => {
|
|
75
75
|
|
76
76
|
if (target === 'c') {
|
77
77
|
const c = toc(out);
|
78
|
+
out.c = c;
|
78
79
|
|
79
80
|
if (outFile) {
|
80
81
|
writeFileSync(outFile, c);
|
81
82
|
} else {
|
82
83
|
console.log(c);
|
83
84
|
}
|
84
|
-
|
85
|
-
process.exit();
|
86
85
|
}
|
87
86
|
|
88
87
|
if (target === 'native') {
|
@@ -97,8 +96,6 @@ export default (code, flags) => {
|
|
97
96
|
|
98
97
|
// obvious command escape is obvious
|
99
98
|
execSync(args.join(' '), { stdio: 'inherit' });
|
100
|
-
|
101
|
-
process.exit();
|
102
99
|
}
|
103
100
|
|
104
101
|
return out;
|
package/compiler/parse.js
CHANGED
@@ -8,10 +8,16 @@ if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
|
|
8
8
|
|
9
9
|
// import { parse } from 'acorn';
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
const
|
11
|
+
let parser, parse;
|
12
|
+
|
13
|
+
const loadParser = async () => {
|
14
|
+
parser = process.argv.find(x => x.startsWith('-parser='))?.split('=')?.[1] ?? 'acorn';
|
15
|
+
0, { parse } = (await import((globalThis.document ? 'https://esm.sh/' : '') + parser));
|
16
|
+
};
|
17
|
+
globalThis._porf_loadParser = loadParser;
|
18
|
+
await loadParser();
|
14
19
|
|
20
|
+
// todo: review which to use by default
|
15
21
|
// supported parsers:
|
16
22
|
// - acorn
|
17
23
|
// - meriyah
|
@@ -24,8 +30,26 @@ const types = process.argv.includes('-types');
|
|
24
30
|
if (types && !['@babel/parser', 'hermes-parser'].includes(parser)) log.warning('parser', `passed -types with a parser (${parser}) which does not support`);
|
25
31
|
|
26
32
|
export default (input, flags) => {
|
27
|
-
|
33
|
+
const ast = parse(input, {
|
34
|
+
// acorn
|
28
35
|
ecmaVersion: 'latest',
|
29
|
-
|
36
|
+
|
37
|
+
// meriyah
|
38
|
+
next: true,
|
39
|
+
module: flags.includes('module'),
|
40
|
+
webcompat: true,
|
41
|
+
|
42
|
+
// babel
|
43
|
+
plugins: types ? ['estree', 'typescript'] : ['estree'],
|
44
|
+
|
45
|
+
// multiple
|
46
|
+
sourceType: flags.includes('module') ? 'module' : 'script',
|
47
|
+
ranges: false,
|
48
|
+
tokens: false,
|
49
|
+
comments: false,
|
30
50
|
});
|
51
|
+
|
52
|
+
if (ast.type === 'File') return ast.program;
|
53
|
+
|
54
|
+
return ast;
|
31
55
|
};
|
package/compiler/wrap.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import compile from './index.js';
|
2
2
|
import decompile from './decompile.js';
|
3
|
-
import fs from 'node:fs';
|
3
|
+
// import fs from 'node:fs';
|
4
4
|
|
5
5
|
const bold = x => `\u001b[1m${x}\u001b[0m`;
|
6
6
|
|
@@ -25,7 +25,7 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
25
25
|
const times = [];
|
26
26
|
|
27
27
|
const t1 = performance.now();
|
28
|
-
const { wasm, funcs, globals, tags, exceptions, pages } = compile(source, flags);
|
28
|
+
const { wasm, funcs, globals, tags, exceptions, pages, c } = compile(source, flags);
|
29
29
|
|
30
30
|
if (source.includes('export function')) flags.push('module');
|
31
31
|
|
@@ -126,8 +126,8 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
126
126
|
}
|
127
127
|
|
128
128
|
if (flags.includes('decomp')) {
|
129
|
-
return { exports, wasm, times, decomps: funcs.map(x => decompile(x.wasm, x.name, x.index, x.locals, x.params, x.returns, funcs, globals, exceptions)) };
|
129
|
+
return { exports, wasm, times, decomps: funcs.map(x => decompile(x.wasm, x.name, x.index, x.locals, x.params, x.returns, funcs, globals, exceptions)), c };
|
130
130
|
}
|
131
131
|
|
132
|
-
return { exports, wasm, times, pages };
|
132
|
+
return { exports, wasm, times, pages, c };
|
133
133
|
};
|
package/package.json
CHANGED