porffor 0.50.24 → 0.50.26
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 +3 -4
- package/compiler/2c.js +1 -1
- package/compiler/index.js +0 -4
- package/compiler/opt.js +0 -27
- package/compiler/wasmSpec.js +38 -29
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/compiler/diagram.js +0 -31
package/README.md
CHANGED
@@ -98,8 +98,9 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
98
98
|
|
99
99
|
## Codebase
|
100
100
|
- `compiler`: contains the compiler itself
|
101
|
-
- `
|
102
|
-
- `
|
101
|
+
- `builtins`: built-in apis written in typescript
|
102
|
+
- `2c.js`: custom wasm-to-c engine
|
103
|
+
- `allocator.js`: static/compile-time allocator
|
103
104
|
- `assemble.js`: assembles wasm ops and metadata into a spec-compliant wasm module/file
|
104
105
|
- `builtins.js`: all manually written built-ins of the engine (spec, custom. vars, funcs)
|
105
106
|
- `builtins_object.js`: all the various built-in objects (think `String`, `globalThis`, etc.)
|
@@ -107,7 +108,6 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
107
108
|
- `codegen.js`: code (wasm) generation, ast -> wasm. The bulk of the effort
|
108
109
|
- `cyclone.js`: wasm partial constant evaluator (it is fast and dangerous hence "cyclone")
|
109
110
|
- `decompile.js`: basic wasm decompiler for debug info
|
110
|
-
- `diagram.js`: produces [Mermaid](https://mermaid.js.org) graphs
|
111
111
|
- `embedding.js`: utils for embedding consts
|
112
112
|
- `encoding.js`: utils for encoding things as bytes as wasm expects
|
113
113
|
- `expression.js`: mapping most operators to an opcode (advanced are as built-ins eg `f64_%`)
|
@@ -131,7 +131,6 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
131
131
|
- `compile.js`: compiles regex ast into wasm bytecode aot
|
132
132
|
- `parse.js`: own regex parser
|
133
133
|
|
134
|
-
- `test`: contains many test files for majority of supported features
|
135
134
|
- `test262`: test262 runner and utils
|
136
135
|
|
137
136
|
## Usecases
|
package/compiler/2c.js
CHANGED
@@ -918,5 +918,5 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
|
|
918
918
|
const makeIncludes = includes => [...includes.keys()].map(x => `#include <${x}>\n`).join('');
|
919
919
|
out = platformSpecific(makeIncludes(winIncludes), makeIncludes(unixIncludes), false) + '\n' + makeIncludes(includes) + '\n' + alwaysPreface + [...prepend.values()].join('\n') + '\n\n' + out;
|
920
920
|
|
921
|
-
return `// generated by porffor ${globalThis.version}\n` + out.trim();
|
921
|
+
return `// generated by porffor ${globalThis.version ?? ''}\n` + out.trim();
|
922
922
|
};
|
package/compiler/index.js
CHANGED
@@ -9,7 +9,6 @@ import toc from './2c.js';
|
|
9
9
|
import * as pgo from './pgo.js';
|
10
10
|
import cyclone from './cyclone.js';
|
11
11
|
import './prefs.js';
|
12
|
-
import * as Diagram from './diagram.js';
|
13
12
|
|
14
13
|
globalThis.decompile = decompile;
|
15
14
|
|
@@ -188,9 +187,6 @@ export default (code, module = undefined) => {
|
|
188
187
|
}
|
189
188
|
};
|
190
189
|
print(data);
|
191
|
-
|
192
|
-
// const url = Diagram.url(Diagram.tree(data));
|
193
|
-
// console.log(`built-in tree: ${url}`);
|
194
190
|
}
|
195
191
|
|
196
192
|
if (logProgress) progressStart('assembling...');
|
package/compiler/opt.js
CHANGED
@@ -11,11 +11,6 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
11
11
|
const tailCall = Prefs.tailCall;
|
12
12
|
if (tailCall) log.warning('opt', 'tail call proposal is not widely implemented! (you used --tail-call)');
|
13
13
|
|
14
|
-
// todo: this breaks exceptions after due to indexes not being adjusted
|
15
|
-
// const tagUse = tags.reduce((acc, x) => { acc[x.idx] = 0; return acc; }, {});
|
16
|
-
// const exceptionUse = exceptions.reduce((acc, _, i) => { acc[i] = 0; return acc; }, {});
|
17
|
-
|
18
|
-
// wasm transform pass
|
19
14
|
let fi = 0;
|
20
15
|
for (const f of funcs) {
|
21
16
|
const wasm = f.wasm;
|
@@ -34,13 +29,6 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
34
29
|
inst = [ ...inst ];
|
35
30
|
wasm[i] = inst;
|
36
31
|
|
37
|
-
// if (inst[0] === Opcodes.throw) {
|
38
|
-
// tagUse[inst[1]]++;
|
39
|
-
|
40
|
-
// const exceptId = read_signedLEB128(wasm[i - 1].slice(1));
|
41
|
-
// exceptionUse[exceptId]++;
|
42
|
-
// }
|
43
|
-
|
44
32
|
if (inst[0] === Opcodes.block) {
|
45
33
|
// remove unneeded blocks (no brs inside)
|
46
34
|
// block
|
@@ -251,19 +239,4 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
251
239
|
}
|
252
240
|
}
|
253
241
|
}
|
254
|
-
|
255
|
-
// for (const x in tagUse) {
|
256
|
-
// if (tagUse[x] === 0) {
|
257
|
-
// const el = tags.find(y => y.idx === x);
|
258
|
-
// tags.splice(tags.indexOf(el), 1);
|
259
|
-
// }
|
260
|
-
// }
|
261
|
-
|
262
|
-
// for (const x of Object.keys(exceptionUse).sort((a, b) => b - a)) {
|
263
|
-
// if (exceptionUse[x] === 0) {
|
264
|
-
// exceptions.splice(+x, 1);
|
265
|
-
// }
|
266
|
-
// }
|
267
|
-
|
268
|
-
// return funcs;
|
269
242
|
};
|
package/compiler/wasmSpec.js
CHANGED
@@ -1,18 +1,36 @@
|
|
1
|
-
const
|
2
|
-
|
3
|
-
|
4
|
-
for (let i = 0; i < args.length; i++) {
|
5
|
-
obj[i] = args[i];
|
6
|
-
obj[args[i]] = i;
|
7
|
-
}
|
1
|
+
export const Magic = [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ];
|
2
|
+
export const PageSize = 65536; // 64KiB
|
3
|
+
export const FuncType = 0x60;
|
8
4
|
|
9
|
-
|
5
|
+
export const Section = {
|
6
|
+
custom: 0,
|
7
|
+
type: 1,
|
8
|
+
import: 2,
|
9
|
+
func: 3,
|
10
|
+
table: 4,
|
11
|
+
memory: 5,
|
12
|
+
global: 6,
|
13
|
+
export: 7,
|
14
|
+
start: 8,
|
15
|
+
element: 9,
|
16
|
+
code: 10,
|
17
|
+
data: 11,
|
18
|
+
data_count: 12,
|
19
|
+
tag: 13
|
10
20
|
};
|
11
21
|
|
12
|
-
export const
|
13
|
-
|
22
|
+
export const ExportDesc = {
|
23
|
+
func: 0,
|
24
|
+
table: 1,
|
25
|
+
mem: 2,
|
26
|
+
global: 3,
|
27
|
+
tag: 4
|
28
|
+
};
|
14
29
|
|
15
|
-
export const Mut =
|
30
|
+
export const Mut = {
|
31
|
+
const: 0,
|
32
|
+
var: 1
|
33
|
+
};
|
16
34
|
|
17
35
|
export const Valtype = {
|
18
36
|
i32: 0x7f,
|
@@ -21,13 +39,21 @@ export const Valtype = {
|
|
21
39
|
v128: 0x7b
|
22
40
|
};
|
23
41
|
|
42
|
+
export const ValtypeSize = {
|
43
|
+
i8: 1,
|
44
|
+
i16: 2,
|
45
|
+
i32: 4,
|
46
|
+
i64: 8,
|
47
|
+
f64: 8
|
48
|
+
};
|
49
|
+
|
24
50
|
export const Reftype = {
|
25
51
|
funcref: 0x70,
|
26
52
|
externref: 0x6f
|
27
53
|
};
|
28
54
|
|
29
55
|
export const Blocktype = {
|
30
|
-
void: 0x40
|
56
|
+
void: 0x40
|
31
57
|
};
|
32
58
|
|
33
59
|
export const Opcodes = {
|
@@ -221,21 +247,4 @@ export const Opcodes = {
|
|
221
247
|
v128_or: [ 0xfd, 80 ],
|
222
248
|
v128_xor: [ 0xfd, 81 ],
|
223
249
|
v128_any_true: [ 0xfd, 83 ]
|
224
|
-
};
|
225
|
-
|
226
|
-
export const FuncType = 0x60;
|
227
|
-
export const Empty = 0x00;
|
228
|
-
|
229
|
-
export const Magic = [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ];
|
230
|
-
|
231
|
-
export const PageSize = 65536; // 64KiB (1024 * 8)
|
232
|
-
|
233
|
-
export const ValtypeSize = {
|
234
|
-
i32: 4,
|
235
|
-
i64: 8,
|
236
|
-
f64: 8,
|
237
|
-
|
238
|
-
// special
|
239
|
-
i8: 1,
|
240
|
-
i16: 2
|
241
250
|
};
|
package/package.json
CHANGED
package/runner/index.js
CHANGED
package/compiler/diagram.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
export const tree = data => {
|
2
|
-
let out = 'flowchart LR\n';
|
3
|
-
let ids = new Map();
|
4
|
-
|
5
|
-
const run = (x, parent = null) => {
|
6
|
-
for (const [ name, children ] of x) {
|
7
|
-
const alreadyHas = ids.has(name);
|
8
|
-
if (!alreadyHas) ids.set(name, ids.size);
|
9
|
-
const id = ids.get(name);
|
10
|
-
|
11
|
-
if (!alreadyHas || parent != null) {
|
12
|
-
if (parent != null) out += `${parent}-->`;
|
13
|
-
out += `${id}${alreadyHas ? '' : `["${name}"]`}\n`;
|
14
|
-
}
|
15
|
-
|
16
|
-
if (children) run(children, id);
|
17
|
-
}
|
18
|
-
};
|
19
|
-
run(data);
|
20
|
-
|
21
|
-
return out;
|
22
|
-
};
|
23
|
-
|
24
|
-
export const url = code => `https://mermaid.live/view#${btoa(JSON.stringify({
|
25
|
-
mermaid: code.length > 10000 ? { theme: 'dark', securityLevel: 'loose', maxEdges: 5000 } : { theme: 'dark' },
|
26
|
-
updateDiagram: true,
|
27
|
-
autoSync: true,
|
28
|
-
rough: false,
|
29
|
-
panZoom: true,
|
30
|
-
code
|
31
|
-
}))}`;
|