porffor 0.58.14 → 0.58.15
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/AGENT.md +13 -0
- package/compiler/builtins/array.ts +23 -0
- package/compiler/builtins/regexp.ts +62 -0
- package/compiler/builtins_precompiled.js +1388 -1383
- package/compiler/codegen.js +81 -72
- package/compiler/cyclone.js +580 -544
- package/compiler/opt.js +8 -14
- package/compiler/parse.js +3 -1
- package/compiler/precompile.js +2 -2
- package/compiler/prototype.js +0 -49
- package/compiler/wrap.js +1 -3
- package/foo.js +22 -4
- package/package.json +1 -1
- package/runtime/index.js +1 -1
- package/slow.js +6882 -0
package/compiler/opt.js
CHANGED
@@ -22,12 +22,8 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
22
22
|
while (runs > 0) {
|
23
23
|
runs--;
|
24
24
|
|
25
|
-
// main pass
|
26
25
|
for (let i = 0; i < wasm.length; i++) {
|
27
|
-
|
28
|
-
inst = [ ...inst ];
|
29
|
-
wasm[i] = inst;
|
30
|
-
|
26
|
+
const inst = wasm[i];
|
31
27
|
if (inst[0] === Opcodes.block) {
|
32
28
|
// remove unneeded blocks (no brs inside)
|
33
29
|
// block
|
@@ -53,23 +49,22 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
53
49
|
if (!hasBranch) {
|
54
50
|
wasm.splice(i, 1); // remove this inst (block)
|
55
51
|
if (i > 0) i--;
|
56
|
-
inst = wasm[i];
|
57
52
|
|
58
53
|
wasm.splice(j - 1, 1); // remove end of this block
|
59
54
|
|
60
55
|
if (Prefs.optLog) log('opt', `removed unneeded block in for loop`);
|
56
|
+
continue;
|
61
57
|
}
|
62
58
|
}
|
63
59
|
|
64
60
|
// remove setting last type if it is never gotten
|
65
61
|
if (!f.internal && !f.gotLastType && inst[0] === Opcodes.local_set && inst[1] === lastType) {
|
66
62
|
// replace this inst with drop
|
67
|
-
wasm
|
68
|
-
if (i > 0) i--;
|
63
|
+
wasm[i] = [ Opcodes.drop ];
|
69
64
|
}
|
70
65
|
|
71
66
|
if (i < 1) continue;
|
72
|
-
|
67
|
+
const lastInst = wasm[i - 1];
|
73
68
|
|
74
69
|
if (lastInst[1] === inst[1] && lastInst[0] === Opcodes.local_set && inst[0] === Opcodes.local_get) {
|
75
70
|
// replace set, get -> tee (sets and returns)
|
@@ -78,8 +73,8 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
78
73
|
// -->
|
79
74
|
// local.tee 0
|
80
75
|
|
81
|
-
lastInst[0] = Opcodes.local_tee; // replace last inst opcode (set -> tee)
|
82
76
|
wasm.splice(i, 1); // remove this inst (get)
|
77
|
+
wasm[i - 1] = [ Opcodes.local_tee, ...lastInst.slice(1) ]; // replace last inst opcode (set -> tee)
|
83
78
|
|
84
79
|
i--;
|
85
80
|
// if (Prefs.optLog) log('opt', `consolidated set, get -> tee`);
|
@@ -105,8 +100,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
105
100
|
// -->
|
106
101
|
// local.set 0
|
107
102
|
|
108
|
-
|
109
|
-
|
103
|
+
wasm[i - 1] = [ Opcodes.local_set, lastInst[1] ]; // change last op
|
110
104
|
wasm.splice(i, 1); // remove this inst
|
111
105
|
i--;
|
112
106
|
continue;
|
@@ -131,7 +125,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
131
125
|
// -->
|
132
126
|
// i32.eqz
|
133
127
|
|
134
|
-
|
128
|
+
wasm[i] = [ Opcodes.eqz[0][0] ]; // eq -> eqz
|
135
129
|
wasm.splice(i - 1, 1); // remove const 0
|
136
130
|
i--;
|
137
131
|
continue;
|
@@ -213,7 +207,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
|
|
213
207
|
// -->
|
214
208
|
// return_call X
|
215
209
|
|
216
|
-
|
210
|
+
wasm[i - 1] = [ Opcodes.return_call, ...lastInst.slice(1) ]; // change last inst return -> return_call
|
217
211
|
|
218
212
|
wasm.splice(i, 1); // remove this inst (return)
|
219
213
|
i--;
|
package/compiler/parse.js
CHANGED
@@ -36,6 +36,7 @@ export default input => {
|
|
36
36
|
next: true,
|
37
37
|
module: Prefs.module,
|
38
38
|
webcompat: true,
|
39
|
+
raw: true,
|
39
40
|
|
40
41
|
// babel
|
41
42
|
plugins: types ? ['estree', 'typescript'] : ['estree'],
|
@@ -46,10 +47,11 @@ export default input => {
|
|
46
47
|
ranges: false,
|
47
48
|
tokens: false,
|
48
49
|
comments: false,
|
50
|
+
preserveParens: false,
|
49
51
|
|
50
52
|
// oxc
|
51
53
|
lang: types ? 'ts' : 'js',
|
52
|
-
showSemanticErrors: true
|
54
|
+
showSemanticErrors: true
|
53
55
|
};
|
54
56
|
|
55
57
|
let ast = parser === 'oxc-parser' ? parse('js', input, options) : parse(input, options);
|
package/compiler/precompile.js
CHANGED
@@ -249,7 +249,7 @@ ${funcs.map(x => {
|
|
249
249
|
.replace(/\"local","(.*?)",(.*?)\]/g, (_, name, valtype) => `loc('${name}',${valtype})]`)
|
250
250
|
.replace(/\[16,"(.*?)"]/g, (_, name) => `[16,builtin('${name}')]`)
|
251
251
|
.replace(/\["funcref",(.*?),"(.*?)"]/g, (_1, op, name) => op === '65' ? `...i32ify(funcRef('${name}'))` : `...funcRef('${name}')`)
|
252
|
-
.replace(/\["str",(.*?),"(.*?)",(.*?)]/g, (_1, op, str,
|
252
|
+
.replace(/\["str",(.*?),"(.*?)",(.*?)]/g, (_1, op, str, bytestring) => op === '65' ? `...i32ify(makeString(_,"${str}",${bytestring}))` : `...makeString(_,"${str}",${bytestring === 'true' ? 1 : 0})`)
|
253
253
|
.replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(_,'${constructor}',\`${message}\`)`)
|
254
254
|
.replace(/\["get object","(.*?)"\]/g, (_, objName) => `...generateIdent(_,{name:'${objName}'})`)
|
255
255
|
.replace(/\[null,"typeswitch case start",\[(.*?)\]\],/g, (_, types) => `...t([${types}],()=>[`)
|
@@ -284,7 +284,7 @@ params:${JSON.stringify(x.params)},typedParams:1,returns:${JSON.stringify(x.retu
|
|
284
284
|
locals:${JSON.stringify(locals.slice(x.params.length).map(x => x[1].type))},localNames:${JSON.stringify(locals.map(x => x[0]))},
|
285
285
|
${x.globalInits ? `globalInits:{${Object.keys(x.globalInits).map(y => `${y}:${rewriteWasm(x.globalInits[y])}`).join(',')}},` : ''}${x.data && Object.keys(x.data).length > 0 ? `data:${JSON.stringify(x.data)},` : ''}
|
286
286
|
${x.table ? `table:1,` : ''}${x.constr ? `constr:1,` : ''}${x.hasRestArgument ? `hasRestArgument:1,` : ''}${x.usesTag ? `usesTag:1,` : ''}${x.usesImports ? `usesImports:1,` : ''}
|
287
|
-
}`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n');
|
287
|
+
}`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll(',\n}', '\n}');
|
288
288
|
}).join('\n')}
|
289
289
|
}`;
|
290
290
|
};
|
package/compiler/prototype.js
CHANGED
@@ -14,54 +14,6 @@ export const PrototypeFuncs = function() {
|
|
14
14
|
else zeroChecks = {};
|
15
15
|
|
16
16
|
this[TYPES.array] = {
|
17
|
-
// lX = local accessor of X ({ get, set }), iX = local index of X, wX = wasm ops of X
|
18
|
-
at: ({ pointer, length, arg, iTmp, setType }) => [
|
19
|
-
...arg,
|
20
|
-
Opcodes.i32_to,
|
21
|
-
[ Opcodes.local_tee, iTmp ],
|
22
|
-
|
23
|
-
// if index < 0: access index + array length
|
24
|
-
number(0, Valtype.i32),
|
25
|
-
[ Opcodes.i32_lt_s ],
|
26
|
-
[ Opcodes.if, Blocktype.void ],
|
27
|
-
[ Opcodes.local_get, iTmp ],
|
28
|
-
...length.getCachedI32(),
|
29
|
-
[ Opcodes.i32_add ],
|
30
|
-
[ Opcodes.local_set, iTmp ],
|
31
|
-
[ Opcodes.end ],
|
32
|
-
|
33
|
-
// if still < 0 or >= length: return undefined
|
34
|
-
[ Opcodes.local_get, iTmp ],
|
35
|
-
number(0, Valtype.i32),
|
36
|
-
[ Opcodes.i32_lt_s ],
|
37
|
-
|
38
|
-
[ Opcodes.local_get, iTmp ],
|
39
|
-
...length.getCachedI32(),
|
40
|
-
[ Opcodes.i32_ge_s ],
|
41
|
-
[ Opcodes.i32_or ],
|
42
|
-
|
43
|
-
[ Opcodes.if, Blocktype.void ],
|
44
|
-
number(UNDEFINED),
|
45
|
-
...setType(TYPES.undefined),
|
46
|
-
[ Opcodes.br, 1 ],
|
47
|
-
[ Opcodes.end ],
|
48
|
-
|
49
|
-
[ Opcodes.local_get, iTmp ],
|
50
|
-
number(ValtypeSize[valtype] + 1, Valtype.i32),
|
51
|
-
[ Opcodes.i32_mul ],
|
52
|
-
...pointer,
|
53
|
-
[ Opcodes.i32_add ],
|
54
|
-
[ Opcodes.local_set, iTmp ],
|
55
|
-
|
56
|
-
// read from memory
|
57
|
-
[ Opcodes.local_get, iTmp ],
|
58
|
-
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
59
|
-
|
60
|
-
[ Opcodes.local_get, iTmp ],
|
61
|
-
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
62
|
-
...setType()
|
63
|
-
],
|
64
|
-
|
65
17
|
pop: ({ pointer, length, iTmp, unusedValue, setType }) => [
|
66
18
|
// if length == 0, noop
|
67
19
|
...length.getCachedI32(),
|
@@ -177,7 +129,6 @@ export const PrototypeFuncs = function() {
|
|
177
129
|
]
|
178
130
|
};
|
179
131
|
|
180
|
-
this[TYPES.array].at.local = Valtype.i32;
|
181
132
|
this[TYPES.array].pop.local = Valtype.i32;
|
182
133
|
|
183
134
|
this[TYPES.string] = {
|
package/compiler/wrap.js
CHANGED
@@ -6,8 +6,6 @@ import './prefs.js';
|
|
6
6
|
|
7
7
|
const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs')) : undefined);
|
8
8
|
|
9
|
-
const checkOOB = (memory, ptr) => ptr >= memory.buffer.byteLength;
|
10
|
-
|
11
9
|
let dv;
|
12
10
|
const read = (ta, memory, ptr, length) => {
|
13
11
|
if (ta === Uint8Array) return new Uint8Array(memory.buffer, ptr, length);
|
@@ -43,7 +41,7 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type, override = undefin
|
|
43
41
|
case TYPES.booleanobject: return new Boolean(value);
|
44
42
|
|
45
43
|
case TYPES.object: {
|
46
|
-
if (value === 0
|
44
|
+
if (value === 0) return null;
|
47
45
|
|
48
46
|
const size = read(Uint16Array, memory, value, 1)[0];
|
49
47
|
|
package/foo.js
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
// (() => {
|
2
|
+
// let y = Math.random();
|
3
|
+
// let x = 0;
|
4
|
+
// if (x === 0) {
|
5
|
+
// x = 1337;
|
6
|
+
// } else {
|
7
|
+
// x = 42;
|
8
|
+
// }
|
9
|
+
// Porffor.log(x);
|
10
|
+
// })()
|
11
|
+
|
12
|
+
const fn = function() {}
|
13
|
+
|
14
|
+
class C {
|
15
|
+
async *m() { return 42; } a; b = 42;
|
16
|
+
c = fn;
|
17
|
+
|
18
|
+
}
|
19
|
+
|
20
|
+
new C();
|
21
|
+
|
22
|
+
console.log(Object.prototype.hasOwnProperty.call(C, "a"))
|
package/package.json
CHANGED