porffor 0.58.0 → 0.58.2
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 +6 -11
- package/compiler/builtins.js +9 -0
- package/compiler/codegen.js +2 -3
- package/compiler/index.js +1 -1
- package/compiler/pgo.js +14 -13
- package/compiler/wrap.js +11 -3
- package/jsr.json +28 -0
- package/package.json +1 -1
- package/runtime/index.js +5 -5
- package/.editorconfig +0 -12
- package/asur/README.md +0 -2
- package/asur/index.js +0 -1262
- package/regex_notes.md +0 -74
- package/richards_direct.js +0 -558
package/README.md
CHANGED
@@ -5,8 +5,8 @@ A from-scratch experimental **AOT** optimizing JS/TS -> Wasm/C engine/compiler/r
|
|
5
5
|
|
6
6
|
## Design
|
7
7
|
Porffor is a very unique JS engine, due many wildly different approaches. It is seriously limited, but what it can do, it does pretty well. Key differences:
|
8
|
-
- 100% AOT compiled (no JIT)
|
9
|
-
-
|
8
|
+
- 100% AOT compiled (no JIT or interpreter)
|
9
|
+
- Zero constant runtime/preluded code
|
10
10
|
- Least Wasm imports possible (only I/O)
|
11
11
|
|
12
12
|
Porffor is primarily built from scratch, the only thing that is not is the parser (using [Acorn](https://github.com/acornjs/acorn)). Binaryen/etc is not used, we make final wasm binaries ourself. You could imagine it as compiling a language which is a sub (some things unsupported) and super (new/custom apis) set of javascript. Not based on any particular spec version.
|
@@ -50,11 +50,11 @@ Expect nothing to work! Only very limited JS is currently supported. See files i
|
|
50
50
|
|
51
51
|
**`porf debug path/to/script.js`**
|
52
52
|
|
53
|
-
### Debugging the compiled Wasm of a JS file
|
53
|
+
<!-- ### Debugging the compiled Wasm of a JS file
|
54
54
|
> [!WARNING]
|
55
55
|
> Very experimental WIP feature!
|
56
56
|
|
57
|
-
**`porf dissect path/to/script.js`**
|
57
|
+
**`porf dissect path/to/script.js`** -->
|
58
58
|
|
59
59
|
|
60
60
|
### Options
|
@@ -73,8 +73,8 @@ Expect nothing to work! Only very limited JS is currently supported. See files i
|
|
73
73
|
|
74
74
|
## Sub-engines
|
75
75
|
|
76
|
-
### Asur
|
77
|
-
Asur is Porffor's own Wasm engine; it is an intentionally simple interpreter written in JS. It is very WIP. See [its readme](asur/README.md) for more details.
|
76
|
+
<!-- ### Asur
|
77
|
+
Asur is Porffor's own Wasm engine; it is an intentionally simple interpreter written in JS. It is very WIP. See [its readme](asur/README.md) for more details. -->
|
78
78
|
|
79
79
|
### 2c
|
80
80
|
2c is Porffor's own Wasm -> C compiler, using generated Wasm bytecode and internal info to generate specific and efficient C code. Little boilerplate/preluded code or required external files, just for CLI binaries (not like wasm2c very much).
|
@@ -88,11 +88,6 @@ Porffor uses a unique versioning system, here's an example: `0.48.7`. Let's brea
|
|
88
88
|
## Performance
|
89
89
|
*For the features it supports most of the time*, Porffor is *blazingly fast* compared to most interpreters and common engines running without JIT. For those with JIT, it is usually slower by default, but can catch up with compiler arguments and typed input, even more so when compiling to native binaries.
|
90
90
|
|
91
|
-
## Test262
|
92
|
-
Porffor can run Test262 via some hacks/transforms which remove unsupported features whilst still doing the same asserts (eg simpler error messages using literals only). It currently passes >14% (see latest commit desc for latest and details). Use `node test262` to test, it will also show a difference of overall results between the last commit and current results.
|
93
|
-
|
94
|
-

|
95
|
-
|
96
91
|
## Codebase
|
97
92
|
- `compiler`: contains the compiler itself
|
98
93
|
- `builtins`: built-in apis written in typescript
|
package/compiler/builtins.js
CHANGED
@@ -8,6 +8,15 @@ import './prefs.js';
|
|
8
8
|
export const importedFuncs = {};
|
9
9
|
Object.defineProperty(importedFuncs, 'length', { configurable: true, writable: true, value: 0 });
|
10
10
|
|
11
|
+
/**
|
12
|
+
* Create an import function for the Porffor world to use.
|
13
|
+
*
|
14
|
+
* @param {string} name - Name of the import
|
15
|
+
* @param {number} params - Number of parameters
|
16
|
+
* @param {number} results - Number of results
|
17
|
+
* @param {function} js - Native (your world) function to call as import implementation
|
18
|
+
* @param {string} c - C source code to compile as import implementation
|
19
|
+
*/
|
11
20
|
export const createImport = (name, params, returns, js = null, c = null) => {
|
12
21
|
const lazy = () => {
|
13
22
|
if (typeof params === 'function') params = params();
|
package/compiler/codegen.js
CHANGED
@@ -1760,7 +1760,7 @@ const getNodeType = (scope, node) => {
|
|
1760
1760
|
const out = typeof ret === 'number' ? [ number(ret, Valtype.i32) ] : ret;
|
1761
1761
|
if (guess != null) out.guess = typeof guess === 'number' ? [ number(guess, Valtype.i32) ] : guess;
|
1762
1762
|
|
1763
|
-
|
1763
|
+
typeUsed(scope, knownType(scope, out));
|
1764
1764
|
return out;
|
1765
1765
|
};
|
1766
1766
|
|
@@ -2595,8 +2595,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2595
2595
|
args = args.slice(0, paramCount - 1);
|
2596
2596
|
args.push({
|
2597
2597
|
type: 'ArrayExpression',
|
2598
|
-
elements: restArgs
|
2599
|
-
_doNotMarkTypeUsed: true
|
2598
|
+
elements: restArgs
|
2600
2599
|
});
|
2601
2600
|
}
|
2602
2601
|
}
|
package/compiler/index.js
CHANGED
@@ -19,7 +19,7 @@ const logFuncs = (funcs, globals, exceptions) => {
|
|
19
19
|
if (typeof wanted !== 'string') wanted = null;
|
20
20
|
|
21
21
|
for (const f of funcs) {
|
22
|
-
if ((wanted && f.name !== wanted) || (!wanted && f.internal)) continue;
|
22
|
+
if ((wanted && (f.name !== wanted && wanted !== '!')) || (!wanted && f.internal)) continue;
|
23
23
|
console.log(disassemble(f.wasm, f.name, f.index, f.locals, f.params, f.returns, funcs, globals, exceptions));
|
24
24
|
}
|
25
25
|
|
package/compiler/pgo.js
CHANGED
@@ -2,7 +2,7 @@ import { Opcodes, Valtype } from './wasmSpec.js';
|
|
2
2
|
import { number } from './encoding.js';
|
3
3
|
import { createImport, importedFuncs } from './builtins.js';
|
4
4
|
import assemble from './assemble.js';
|
5
|
-
import wrap
|
5
|
+
import wrap from './wrap.js';
|
6
6
|
import * as Havoc from './havoc.js';
|
7
7
|
import './prefs.js';
|
8
8
|
|
@@ -95,18 +95,19 @@ export const run = obj => {
|
|
95
95
|
|
96
96
|
const { exports } = wrap(obj, undefined, {
|
97
97
|
readArgv: (ind, outPtr) => {
|
98
|
-
const pgoInd = process.argv.indexOf('--pgo');
|
99
|
-
let args = process.argv.slice(pgoInd);
|
100
|
-
args = args.slice(args.findIndex(x => !x.startsWith('-')) + 1);
|
101
|
-
|
102
|
-
const str = args[ind - 1];
|
103
|
-
if (pgoInd === -1 || !str) {
|
104
|
-
|
105
|
-
|
106
|
-
}
|
107
|
-
|
108
|
-
writeByteStr(exports.$, outPtr, str);
|
109
|
-
return str.length;
|
98
|
+
// const pgoInd = process.argv.indexOf('--pgo');
|
99
|
+
// let args = process.argv.slice(pgoInd);
|
100
|
+
// args = args.slice(args.findIndex(x => !x.startsWith('-')) + 1);
|
101
|
+
|
102
|
+
// const str = args[ind - 1];
|
103
|
+
// if (pgoInd === -1 || !str) {
|
104
|
+
// if (Prefs.pgoLog) console.log('\nPGO warning: script was expecting arguments, please specify args to use for PGO after --pgo arg');
|
105
|
+
// return -1;
|
106
|
+
// }
|
107
|
+
|
108
|
+
// writeByteStr(exports.$, outPtr, str);
|
109
|
+
// return str.length;
|
110
|
+
return -1;
|
110
111
|
},
|
111
112
|
readFile: (pathPtr, outPtr) => {
|
112
113
|
return -1;
|
package/compiler/wrap.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { encodeVector } from './encoding.js';
|
2
1
|
import { importedFuncs, createImport } from './builtins.js';
|
3
2
|
import compile from './index.js';
|
4
3
|
import disassemble from './disassemble.js';
|
@@ -15,12 +14,12 @@ const read = (ta, memory, ptr, length) => {
|
|
15
14
|
return new ta(memory.buffer.slice(ptr, ptr + length * ta.BYTES_PER_ELEMENT), 0, length);
|
16
15
|
};
|
17
16
|
|
18
|
-
|
17
|
+
const readByteStr = (memory, ptr) => {
|
19
18
|
const length = read(Uint32Array, memory, ptr, 1)[0];
|
20
19
|
return Array.from(read(Uint8Array, memory, ptr + 4, length)).map(x => String.fromCharCode(x)).join('');
|
21
20
|
};
|
22
21
|
|
23
|
-
|
22
|
+
const writeByteStr = (memory, ptr, str) => {
|
24
23
|
const length = str.length;
|
25
24
|
|
26
25
|
if (dv?.memory !== memory) dv = new DataView(memory.buffer);
|
@@ -361,6 +360,15 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
361
360
|
};
|
362
361
|
|
363
362
|
export { createImport };
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Compile given JavaScript source code. // todo: more docs here (sorry)
|
366
|
+
*
|
367
|
+
* @param {string} source - JavaScript source code to compile
|
368
|
+
* @param {boolean} module - If the source is a module or not (default: false)
|
369
|
+
* @param {object} customImports - Custom imports
|
370
|
+
* @param {(str: string) => void} print - Function to use for printing (used by console.log etc)
|
371
|
+
*/
|
364
372
|
export default (source, module = undefined, customImports = {}, print = str => process.stdout.write(str)) => {
|
365
373
|
createImport('print', 1, 0, i => print(i.toString()));
|
366
374
|
createImport('printChar', 1, 0, i => print(String.fromCharCode(i)));
|
package/jsr.json
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"name": "@honk/porffor",
|
3
|
+
"version": "0.58.2",
|
4
|
+
"exports": "./compiler/wrap.js",
|
5
|
+
"publish": {
|
6
|
+
"exclude": [
|
7
|
+
".github",
|
8
|
+
"bench",
|
9
|
+
"demos",
|
10
|
+
"test262",
|
11
|
+
"envoy",
|
12
|
+
|
13
|
+
"logo.png",
|
14
|
+
"index.html",
|
15
|
+
"CNAME",
|
16
|
+
"publish.js",
|
17
|
+
|
18
|
+
".repl_history",
|
19
|
+
"*.wasm",
|
20
|
+
"*.csv",
|
21
|
+
"*.txt",
|
22
|
+
"*.exe",
|
23
|
+
|
24
|
+
".npmignore",
|
25
|
+
".editorconfig"
|
26
|
+
]
|
27
|
+
}
|
28
|
+
}
|
package/package.json
CHANGED
package/runtime/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import fs from 'node:fs';
|
3
|
-
globalThis.version = '0.58.
|
3
|
+
globalThis.version = '0.58.2';
|
4
4
|
|
5
5
|
// deno compat
|
6
6
|
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
|
@@ -27,7 +27,7 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
27
27
|
'Analyze': [],
|
28
28
|
profile: [ 93, 'foo.js', 'View detailed func-by-func performance' ],
|
29
29
|
debug: [ 33, 'foo.js', 'Debug the source of a file' ],
|
30
|
-
dissect: [ 33, 'foo.js', 'Debug the compiled Wasm of a file' ],
|
30
|
+
// dissect: [ 33, 'foo.js', 'Debug the compiled Wasm of a file' ],
|
31
31
|
})) {
|
32
32
|
if (color == null) {
|
33
33
|
// header
|
@@ -113,9 +113,9 @@ if (['precompile', 'run', 'wasm', 'native', 'c', 'profile', 'debug', 'dissect'].
|
|
113
113
|
process.argv.push(`--target=${file}`);
|
114
114
|
}
|
115
115
|
|
116
|
-
if (file === 'dissect') {
|
117
|
-
|
118
|
-
}
|
116
|
+
// if (file === 'dissect') {
|
117
|
+
// process.argv.push('--asur', '--wasm-debug');
|
118
|
+
// }
|
119
119
|
|
120
120
|
file = process.argv.slice(2).find(x => x[0] !== '-');
|
121
121
|
|
package/.editorconfig
DELETED
package/asur/README.md
DELETED