porffor 0.2.0-2265539 → 0.2.0-22b3092
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/.vscode/launch.json +18 -0
- package/LICENSE +20 -20
- package/README.md +61 -43
- package/asur/README.md +2 -0
- package/asur/index.js +1262 -0
- package/byg/index.js +237 -0
- package/compiler/2c.js +1 -1
- package/compiler/{sections.js → assemble.js} +57 -10
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +19 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +49 -39
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/int.ts +147 -0
- package/compiler/builtins/number.ts +527 -0
- package/compiler/builtins/porffor.d.ts +26 -19
- package/compiler/builtins/string.ts +1055 -0
- package/compiler/builtins/tostring.ts +45 -0
- package/compiler/builtins.js +412 -105
- package/compiler/{codeGen.js → codegen.js} +674 -287
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +684 -4
- package/compiler/index.js +16 -14
- package/compiler/log.js +6 -3
- package/compiler/opt.js +23 -22
- package/compiler/parse.js +31 -25
- package/compiler/precompile.js +19 -25
- package/compiler/prefs.js +2 -2
- package/compiler/prototype.js +2 -18
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +27 -8
- package/compiler/wrap.js +46 -45
- package/package.json +9 -5
- package/porf +2 -0
- package/rhemyn/compile.js +3 -2
- package/rhemyn/parse.js +323 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +34 -34
- package/runner/debug.js +122 -0
- package/runner/index.js +31 -9
- package/runner/profiler.js +102 -0
- package/runner/repl.js +40 -7
- package/runner/sizes.js +37 -37
- package/test262_changes_from_1afe9b87d2_to_04-09.md +270 -0
- package/demo.js +0 -3
- package/demo.ts +0 -1
- package/filesize.cmd +0 -2
- package/hello +0 -0
- package/runner/info.js +0 -89
- package/runner/profile.js +0 -46
- package/runner/results.json +0 -1
- package/runner/transform.js +0 -15
- package/tmp.c +0 -152
- package/util/enum.js +0 -20
package/compiler/wrap.js
CHANGED
@@ -1,50 +1,44 @@
|
|
1
1
|
import compile from './index.js';
|
2
2
|
import decompile from './decompile.js';
|
3
3
|
import { encodeVector, encodeLocal } from './encoding.js';
|
4
|
-
|
4
|
+
import Prefs from './prefs.js';
|
5
|
+
import { log } from './log.js';
|
6
|
+
import { TYPES } from './types.js';
|
5
7
|
|
6
8
|
const bold = x => `\u001b[1m${x}\u001b[0m`;
|
7
9
|
|
8
|
-
const typeBase = 0x00;
|
9
|
-
const internalTypeBase = 0x10;
|
10
|
-
const TYPES = {
|
11
|
-
[typeBase]: 'number',
|
12
|
-
[typeBase + 1]: 'boolean',
|
13
|
-
[typeBase + 2]: 'string',
|
14
|
-
[typeBase + 3]: 'undefined',
|
15
|
-
[typeBase + 4]: 'object',
|
16
|
-
[typeBase + 5]: 'function',
|
17
|
-
[typeBase + 6]: 'symbol',
|
18
|
-
[typeBase + 7]: 'bigint',
|
19
|
-
|
20
|
-
// internal
|
21
|
-
[internalTypeBase]: '_array',
|
22
|
-
[internalTypeBase + 1]: '_regexp',
|
23
|
-
[internalTypeBase + 2]: '_bytestring'
|
24
|
-
};
|
25
|
-
|
26
10
|
export default async (source, flags = [ 'module' ], customImports = {}, print = str => process.stdout.write(str)) => {
|
27
11
|
const times = [];
|
28
12
|
|
29
13
|
const t1 = performance.now();
|
30
14
|
const { wasm, funcs, globals, tags, exceptions, pages, c } = compile(source, flags);
|
31
15
|
|
16
|
+
globalThis.porfDebugInfo = { funcs, globals };
|
17
|
+
|
32
18
|
if (source.includes('export function')) flags.push('module');
|
33
19
|
|
34
|
-
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
20
|
+
// (await import('node:fs')).writeFileSync('out.wasm', Buffer.from(wasm));
|
35
21
|
|
36
22
|
times.push(performance.now() - t1);
|
37
|
-
if (
|
23
|
+
if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
|
38
24
|
|
39
25
|
const t2 = performance.now();
|
40
26
|
|
41
27
|
let instance;
|
42
28
|
try {
|
43
|
-
|
29
|
+
let wasmEngine = WebAssembly;
|
30
|
+
if (Prefs.asur) {
|
31
|
+
log.warning('wrap', 'using our !experimental! asur wasm engine instead of host to run');
|
32
|
+
wasmEngine = await import('../asur/index.js');
|
33
|
+
}
|
34
|
+
|
35
|
+
0, { instance } = await wasmEngine.instantiate(wasm, {
|
44
36
|
'': {
|
45
37
|
p: valtype === 'i64' ? i => print(Number(i).toString()) : i => print(i.toString()),
|
46
38
|
c: valtype === 'i64' ? i => print(String.fromCharCode(Number(i))) : i => print(String.fromCharCode(i)),
|
47
|
-
t:
|
39
|
+
t: () => performance.now(),
|
40
|
+
y: () => {},
|
41
|
+
z: () => {},
|
48
42
|
...customImports
|
49
43
|
}
|
50
44
|
});
|
@@ -52,8 +46,10 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
52
46
|
// only backtrace for runner, not test262/etc
|
53
47
|
if (!process.argv[1].includes('/runner')) throw e;
|
54
48
|
|
55
|
-
const funcInd = parseInt(e.message.match(/function #([0-9]+) /)[1]);
|
56
|
-
const blobOffset = parseInt(e.message.split('@')[1]);
|
49
|
+
const funcInd = parseInt(e.message.match(/function #([0-9]+) /)?.[1]);
|
50
|
+
const blobOffset = parseInt(e.message.split('@')?.[1]);
|
51
|
+
|
52
|
+
if (!funcInd) throw e;
|
57
53
|
|
58
54
|
// convert blob offset -> function wasm offset.
|
59
55
|
// this is not good code and is somewhat duplicated
|
@@ -131,7 +127,7 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
131
127
|
}
|
132
128
|
|
133
129
|
times.push(performance.now() - t2);
|
134
|
-
if (
|
130
|
+
if (Prefs.profileCompiler) console.log(`instantiated in ${times[1].toFixed(2)}ms`);
|
135
131
|
|
136
132
|
const exports = {};
|
137
133
|
|
@@ -159,43 +155,48 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
159
155
|
|
160
156
|
// if (ret >= typeBase && ret <= typeBase + 8) return ret > (typeBase + 7) ? 'object' : TYPES[ret];
|
161
157
|
|
162
|
-
switch (
|
163
|
-
case
|
164
|
-
case
|
165
|
-
case
|
158
|
+
switch (type) {
|
159
|
+
case TYPES.boolean: return Boolean(ret);
|
160
|
+
case TYPES.undefined: return undefined;
|
161
|
+
case TYPES.object: return ret === 0 ? null : {};
|
166
162
|
|
167
|
-
case
|
163
|
+
case TYPES.string: {
|
168
164
|
const pointer = ret;
|
169
165
|
const length = new Int32Array(memory.buffer, pointer, 1);
|
170
166
|
|
171
|
-
|
172
|
-
|
167
|
+
return Array.from(new Uint16Array(memory.buffer, pointer + 4, length)).map(x => String.fromCharCode(x)).join('');
|
168
|
+
}
|
173
169
|
|
174
|
-
|
170
|
+
case TYPES.function: {
|
171
|
+
// wasm func index, including all imports
|
172
|
+
const func = funcs.find(x => (x.originalIndex ?? x.index) === ret);
|
173
|
+
// if (!func) return ret;
|
174
|
+
if (!func) return function () {};
|
175
|
+
|
176
|
+
// make fake empty func for repl/etc
|
177
|
+
return {[func.name]() {}}[func.name];
|
175
178
|
}
|
176
179
|
|
177
|
-
case
|
180
|
+
case TYPES._array: {
|
178
181
|
const pointer = ret;
|
179
182
|
const length = new Int32Array(memory.buffer, pointer, 1);
|
180
183
|
|
181
|
-
|
184
|
+
// have to slice because of memory alignment
|
185
|
+
const buf = memory.buffer.slice(pointer + 4, pointer + 4 + 8 * length);
|
186
|
+
|
187
|
+
return Array.from(new Float64Array(buf));
|
182
188
|
}
|
183
189
|
|
184
|
-
case
|
190
|
+
case TYPES._bytestring: {
|
185
191
|
const pointer = ret;
|
186
192
|
const length = new Int32Array(memory.buffer, pointer, 1);
|
187
193
|
|
188
194
|
return Array.from(new Uint8Array(memory.buffer, pointer + 4, length)).map(x => String.fromCharCode(x)).join('');
|
189
195
|
}
|
190
196
|
|
191
|
-
case
|
192
|
-
//
|
193
|
-
|
194
|
-
// if (!func) return ret;
|
195
|
-
if (!func) return function () {};
|
196
|
-
|
197
|
-
// make fake empty func for repl/etc
|
198
|
-
return {[func.name]() {}}[func.name];
|
197
|
+
case TYPES._date: {
|
198
|
+
// todo
|
199
|
+
throw new Error('todo! deserialize date');
|
199
200
|
}
|
200
201
|
|
201
202
|
default: return ret;
|
package/package.json
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
{
|
2
2
|
"name": "porffor",
|
3
3
|
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
|
4
|
-
"version": "0.2.0-
|
4
|
+
"version": "0.2.0-22b3092",
|
5
5
|
"author": "CanadaHonk",
|
6
6
|
"license": "MIT",
|
7
|
+
"scripts": {
|
8
|
+
"precompile": "node ./compiler/precompile.js"
|
9
|
+
},
|
7
10
|
"dependencies": {
|
8
|
-
"acorn": "^8.
|
11
|
+
"acorn": "^8.11.3",
|
12
|
+
"node-repl-polyfill": "^0.1.1"
|
9
13
|
},
|
10
14
|
"optionalDependencies": {
|
11
|
-
"@babel/parser": "^7.
|
15
|
+
"@babel/parser": "^7.24.4",
|
12
16
|
"hermes-parser": "^0.18.2",
|
13
17
|
"meriyah": "^4.3.9"
|
14
18
|
},
|
15
19
|
"bin": {
|
16
20
|
"porf": "./runner/index.js"
|
17
21
|
},
|
18
|
-
"main": "./
|
22
|
+
"main": "./compiler/wrap.js",
|
19
23
|
"type": "module",
|
20
24
|
"repository": {
|
21
25
|
"type": "git",
|
@@ -25,4 +29,4 @@
|
|
25
29
|
"url": "https://github.com/CanadaHonk/porffor/issues"
|
26
30
|
},
|
27
31
|
"homepage": "https://porffor.goose.icu"
|
28
|
-
}
|
32
|
+
}
|
package/porf
CHANGED
package/rhemyn/compile.js
CHANGED
@@ -160,7 +160,7 @@ const generateSet = (node, negated, get) => {
|
|
160
160
|
];
|
161
161
|
}
|
162
162
|
|
163
|
-
out = out.concat(new Array(node.body.length - 1).fill(negated ? [ Opcodes.i32_or ] : [ Opcodes.i32_and ]));
|
163
|
+
if (node.body.length > 0) out = out.concat(new Array(node.body.length - 1).fill(negated ? [ Opcodes.i32_or ] : [ Opcodes.i32_and ]));
|
164
164
|
|
165
165
|
return [
|
166
166
|
...out,
|
@@ -188,7 +188,8 @@ const generateRange = (node, negated, get) => {
|
|
188
188
|
};
|
189
189
|
|
190
190
|
const generateGroup = (node, negated, get) => {
|
191
|
-
|
191
|
+
// todo
|
192
|
+
return [];
|
192
193
|
};
|
193
194
|
|
194
195
|
export const test = (regex, index = 0, name = 'regex_test_' + regex) => outputFunc(generate(parse(regex), false, true, 'test'), name, index);
|