porffor 0.58.0 → 0.58.1
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 +0 -5
- 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 +1 -1
- package/.editorconfig +0 -12
package/README.md
CHANGED
@@ -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.1",
|
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
package/.editorconfig
DELETED