porffor 0.18.12 → 0.18.14
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/compiler/builtins/array.ts +2 -2
- package/compiler/builtins/base64.ts +2 -2
- package/compiler/builtins/boolean.ts +1 -1
- package/compiler/builtins/date.ts +9 -9
- package/compiler/builtins/escape.ts +2 -2
- package/compiler/builtins/number.ts +3 -3
- package/compiler/builtins/string.ts +22 -22
- package/compiler/builtins/symbol.ts +1 -1
- package/compiler/builtins/z_ecma262.ts +1 -1
- package/compiler/builtins.js +61 -4
- package/compiler/codegen.js +221 -114
- package/compiler/generated_builtins.js +452 -443
- package/compiler/types.js +14 -13
- package/compiler/wrap.js +41 -26
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/types.js
CHANGED
@@ -9,6 +9,16 @@ export const TYPES = {
|
|
9
9
|
bigint: 0x07
|
10
10
|
};
|
11
11
|
|
12
|
+
// flags
|
13
|
+
export const TYPE_FLAGS = {
|
14
|
+
// iterable: 0b10000000,
|
15
|
+
parity: 0b10000000,
|
16
|
+
length: 0b01000000,
|
17
|
+
};
|
18
|
+
|
19
|
+
// TYPES.string |= TYPE_FLAGS.iterable;
|
20
|
+
TYPES.string |= TYPE_FLAGS.length;
|
21
|
+
|
12
22
|
export const TYPE_NAMES = {
|
13
23
|
[TYPES.number]: 'Number',
|
14
24
|
[TYPES.boolean]: 'Boolean',
|
@@ -20,23 +30,14 @@ export const TYPE_NAMES = {
|
|
20
30
|
[TYPES.bigint]: 'BigInt'
|
21
31
|
};
|
22
32
|
|
23
|
-
// flags
|
24
|
-
export const TYPE_FLAGS = {
|
25
|
-
// iterable: 0b10000000,
|
26
|
-
length: 0b01000000,
|
27
|
-
};
|
28
|
-
|
29
|
-
// TYPES.string |= TYPE_FLAGS.iterable;
|
30
|
-
TYPES.string |= TYPE_FLAGS.length;
|
31
|
-
|
32
33
|
export const typeHasFlag = (type, flag) => (type & flag) !== 0;
|
33
34
|
|
34
35
|
export const INTERNAL_TYPE_BASE = 0x10;
|
35
36
|
let internalTypeIndex = INTERNAL_TYPE_BASE;
|
36
|
-
const registerInternalType = (name, flags = []) => {
|
37
|
-
let n = internalTypeIndex++;
|
37
|
+
const registerInternalType = (name, flags = [], overrideType = undefined) => {
|
38
|
+
let n = overrideType ?? internalTypeIndex++;
|
38
39
|
|
39
|
-
for (const x of flags) {
|
40
|
+
if (!overrideType) for (const x of flags) {
|
40
41
|
if (TYPE_FLAGS[x]) n |= TYPE_FLAGS[x];
|
41
42
|
}
|
42
43
|
|
@@ -49,7 +50,7 @@ const registerInternalType = (name, flags = []) => {
|
|
49
50
|
|
50
51
|
registerInternalType('Array', ['iterable', 'length']);
|
51
52
|
registerInternalType('RegExp');
|
52
|
-
registerInternalType('ByteString', ['iterable', 'length']);
|
53
|
+
registerInternalType('ByteString', ['iterable', 'length'], TYPES.string | TYPE_FLAGS.parity);
|
53
54
|
registerInternalType('Date');
|
54
55
|
registerInternalType('Set', ['iterable']);
|
55
56
|
|
package/compiler/wrap.js
CHANGED
@@ -147,6 +147,36 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
147
147
|
times.push(performance.now() - t1);
|
148
148
|
if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
|
149
149
|
|
150
|
+
const printDecomp = (middleIndex, func, funcs, globals, exceptions) => {
|
151
|
+
console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
|
152
|
+
console.log('\x1B[4m' + func.name + '\x1B[0m');
|
153
|
+
|
154
|
+
const surrounding = Prefs.backtraceSurrounding ?? 5;
|
155
|
+
let min = middleIndex - surrounding;
|
156
|
+
let max = middleIndex + surrounding + 1;
|
157
|
+
if (Prefs.backtraceEntireFunc || middleIndex == -1) {
|
158
|
+
min = 0;
|
159
|
+
max = func.wasm.length;
|
160
|
+
}
|
161
|
+
|
162
|
+
const decomp = decompile(func.wasm.slice(min, max), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
|
163
|
+
|
164
|
+
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
165
|
+
let longest = 0;
|
166
|
+
for (let j = 0; j < decomp.length; j++) {
|
167
|
+
longest = Math.max(longest, noAnsi(decomp[j]).length);
|
168
|
+
}
|
169
|
+
|
170
|
+
if (middleIndex != -1) {
|
171
|
+
const middle = Math.floor(decomp.length / 2);
|
172
|
+
decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
|
173
|
+
}
|
174
|
+
|
175
|
+
if (min != 0) console.log('\x1B[90m...\x1B[0m');
|
176
|
+
console.log(decomp.join('\n'));
|
177
|
+
if (max > func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
|
178
|
+
}
|
179
|
+
|
150
180
|
const backtrace = (funcInd, blobOffset) => {
|
151
181
|
if (funcInd == null || blobOffset == null ||
|
152
182
|
Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
|
@@ -188,7 +218,10 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
188
218
|
if (!mismatch) break;
|
189
219
|
}
|
190
220
|
|
191
|
-
if (i === wasm.length)
|
221
|
+
if (i === wasm.length) {
|
222
|
+
printDecomp(-1, func, funcs, globals, exceptions);
|
223
|
+
return false;
|
224
|
+
}
|
192
225
|
|
193
226
|
const offset = (blobOffset - i) + encodeVector(localDecl).length;
|
194
227
|
|
@@ -199,30 +232,14 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
199
232
|
if (cumLen === offset) break;
|
200
233
|
}
|
201
234
|
|
202
|
-
if (cumLen !== offset)
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
|
207
|
-
|
208
|
-
console.log('\x1B[4m' + func.name + '\x1B[0m');
|
209
|
-
|
210
|
-
const surrounding = 6;
|
211
|
-
|
212
|
-
const decomp = decompile(func.wasm.slice(i - surrounding, i + surrounding + 1), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
|
213
|
-
|
214
|
-
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
215
|
-
let longest = 0;
|
216
|
-
for (let j = 0; j < decomp.length; j++) {
|
217
|
-
longest = Math.max(longest, noAnsi(decomp[j]).length);
|
235
|
+
if (cumLen !== offset) {
|
236
|
+
printDecomp(-1, func, funcs, globals, exceptions);
|
237
|
+
return false;
|
218
238
|
}
|
219
239
|
|
220
|
-
|
221
|
-
decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
|
240
|
+
i -= 1;
|
222
241
|
|
223
|
-
|
224
|
-
console.log(decomp.join('\n'));
|
225
|
-
console.log('\x1B[90m...\x1B[0m\n');
|
242
|
+
printDecomp(i, func, funcs, globals, exceptions);
|
226
243
|
|
227
244
|
return true;
|
228
245
|
};
|
@@ -271,8 +288,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
271
288
|
}
|
272
289
|
});
|
273
290
|
} catch (e) {
|
274
|
-
|
275
|
-
if (!process.argv[1].includes('/runner')) throw e;
|
291
|
+
if (!process.argv.includes('-i')) throw e;
|
276
292
|
if (!(e instanceof WebAssembly.CompileError)) throw e;
|
277
293
|
|
278
294
|
const funcInd = parseInt(e.message.match(/function #([0-9]+) /)?.[1]);
|
@@ -367,8 +383,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
367
383
|
}
|
368
384
|
|
369
385
|
if (e instanceof WebAssembly.RuntimeError) {
|
370
|
-
|
371
|
-
if (!process.argv[1].includes('/runner')) throw e;
|
386
|
+
if (!process.argv.includes('-i')) throw e;
|
372
387
|
|
373
388
|
const match = e.stack.match(/wasm-function\[([0-9]+)\]:([0-9a-z]+)/) ?? [];
|
374
389
|
const funcInd = parseInt(match[1]);
|
package/package.json
CHANGED