porffor 0.30.9 → 0.30.11
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/assemble.js +14 -3
- package/compiler/builtins/__internal_object.ts +4 -1
- package/compiler/builtins_precompiled.js +2 -2
- package/compiler/prefs.js +22 -30
- package/compiler/wrap.js +13 -30
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/assemble.js
CHANGED
@@ -309,7 +309,8 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
309
309
|
|
310
310
|
// todo: move const, call transforms here too?
|
311
311
|
|
312
|
-
const
|
312
|
+
const makeAssembled = Prefs.d;
|
313
|
+
let wasm = [], wasmNonFlat = [];
|
313
314
|
for (let i = 0; i < x.wasm.length; i++) {
|
314
315
|
let o = x.wasm[i];
|
315
316
|
|
@@ -323,10 +324,20 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
323
324
|
unsignedLEB128_into(n, o);
|
324
325
|
}
|
325
326
|
|
326
|
-
|
327
|
+
for (let j = 0; j < o.length; j++) {
|
328
|
+
const x = o[j];
|
329
|
+
if (x == null || !(x <= 0xff)) continue;
|
330
|
+
wasm.push(x);
|
331
|
+
}
|
332
|
+
|
333
|
+
if (makeAssembled) wasmNonFlat.push(o);
|
334
|
+
}
|
335
|
+
|
336
|
+
if (makeAssembled) {
|
337
|
+
x.assembled = { localDecl, wasm, wasmNonFlat };
|
327
338
|
}
|
328
339
|
|
329
|
-
return encodeVector([ ...encodeVector(localDecl), ...wasm
|
340
|
+
return encodeVector([ ...encodeVector(localDecl), ...wasm, Opcodes.end ]);
|
330
341
|
}))
|
331
342
|
);
|
332
343
|
|
@@ -4,7 +4,10 @@ export const __Porffor_object_getObject = (obj: any): any => {
|
|
4
4
|
const funcI32: i32 = Porffor.wasm`local.get ${obj}`;
|
5
5
|
let underlying: object = underlyingFuncObjs.get(funcI32);
|
6
6
|
if (underlying == null) {
|
7
|
-
underlying =
|
7
|
+
underlying = {};
|
8
|
+
underlying.prototype = {};
|
9
|
+
underlying.prototype.constructor = obj;
|
10
|
+
|
8
11
|
underlyingFuncObjs.set(funcI32, underlying);
|
9
12
|
}
|
10
13
|
|
@@ -3,10 +3,10 @@ import { number } from './embedding.js';
|
|
3
3
|
|
4
4
|
export const BuiltinFuncs = function() {
|
5
5
|
this.__Porffor_object_getObject = {
|
6
|
-
wasm: (scope, {glbl,builtin}) => [[32,1],[184],[68,0,0,0,0,0,0,24,64],[97],[4,64],[32,0],[33,2],...glbl(35, 'underlyingFuncObjs', 124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[16, builtin('__Map_prototype_get')],[26],[34,3],[68,0,0,0,0,0,0,0,0],[97],[4,64],[16, builtin('__Porffor_allocate')],[
|
6
|
+
wasm: (scope, {glbl,builtin,internalThrow}) => [[32,1],[184],[68,0,0,0,0,0,0,24,64],[97],[4,64],[32,0],[33,2],...glbl(35, 'underlyingFuncObjs', 124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[16, builtin('__Map_prototype_get')],[26],[34,3],[68,0,0,0,0,0,0,0,0],[97],[4,64],[16, builtin('__Porffor_allocate')],[184],[34,3],[33,9],[16, builtin('__Porffor_allocate')],[34,11],[65,9],[54,1,0],[32,11],[65,240,0],[58,0,4],[32,11],[65,242,0],[58,0,5],[32,11],[65,239,0],[58,0,6],[32,11],[65,244,0],[58,0,7],[32,11],[65,239,0],[58,0,8],[32,11],[65,244,0],[58,0,9],[32,11],[65,249,0],[58,0,10],[32,11],[65,240,0],[58,0,11],[32,11],[65,229,0],[58,0,12],[32,11],[184],[33,10],[32,9],[252,3],[65,7],[32,10],[65,195,1],[16, builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[16, builtin('__Porffor_allocate')],[184],[65,7],[16, builtin('__Porffor_object_set')],[26],[26],[32,3],[33,9],[65,128,128,4],[34,11],[65,9],[54,1,0],[32,11],[65,240,0],[58,0,4],[32,11],[65,242,0],[58,0,5],[32,11],[65,239,0],[58,0,6],[32,11],[65,244,0],[58,0,7],[32,11],[65,239,0],[58,0,8],[32,11],[65,244,0],[58,0,9],[32,11],[65,249,0],[58,0,10],[32,11],[65,240,0],[58,0,11],[32,11],[65,229,0],[58,0,12],[32,11],[184],[33,13],[32,9],[252,3],[65,7],[32,13],[65,195,1],[16, builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[16, builtin('__Porffor_object_get')],[33,6],[33,9],[16, builtin('__Porffor_allocate')],[34,11],[65,11],[54,1,0],[32,11],[65,227,0],[58,0,4],[32,11],[65,239,0],[58,0,5],[32,11],[65,238,0],[58,0,6],[32,11],[65,243,0],[58,0,7],[32,11],[65,244,0],[58,0,8],[32,11],[65,242,0],[58,0,9],[32,11],[65,245,0],[58,0,10],[32,11],[65,227,0],[58,0,11],[32,11],[65,244,0],[58,0,12],[32,11],[65,239,0],[58,0,13],[32,11],[65,242,0],[58,0,14],[32,11],[184],[33,10],[32,6],[33,16],[2,124],[32,16],[65,6],[70],[4,64,"TYPESWITCH|Function"],[32,9],[252,3],[32,6],[32,10],[65,195,1],[16, builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[32,0],[32,1],[16, builtin('__Porffor_object_set')],[26],[12,1],[11],[32,16],[65,7],[70],[4,64,"TYPESWITCH|Object"],[32,9],[252,3],[32,6],[32,10],[65,195,1],[16, builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[32,0],[32,1],[16, builtin('__Porffor_object_set')],[26],[12,1],[11],[32,16],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,9],[252,3],[32,10],[252,3],[65,9],[108],[106],[34,8],[32,0],[34,7],[57,0,4],[32,8],[32,1],[58,0,12],[32,7],[12,1],[11],[32,16],[65,216,0],[70],[4,64,"TYPESWITCH|Uint8Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[106],[32,0],[34,7],[252,3],[58,0,4],[32,7],[12,1],[11],[32,16],[65,217,0],[70],[4,64,"TYPESWITCH|Int8Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[106],[32,0],[34,7],[252,2],[58,0,4],[32,7],[12,1],[11],[32,16],[65,218,0],[70],[4,64,"TYPESWITCH|Uint8ClampedArray"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[106],[32,0],[34,7],[68,0,0,0,0,0,0,0,0],[165],[68,0,0,0,0,0,224,111,64],[164],[252,3],[58,0,4],[32,7],[12,1],[11],[32,16],[65,219,0],[70],[4,64,"TYPESWITCH|Uint16Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,2],[108],[106],[32,0],[34,7],[252,3],[59,0,4],[32,7],[12,1],[11],[32,16],[65,220,0],[70],[4,64,"TYPESWITCH|Int16Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,2],[108],[106],[32,0],[34,7],[252,2],[59,0,4],[32,7],[12,1],[11],[32,16],[65,221,0],[70],[4,64,"TYPESWITCH|Uint32Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,4],[108],[106],[32,0],[34,7],[252,3],[54,0,4],[32,7],[12,1],[11],[32,16],[65,222,0],[70],[4,64,"TYPESWITCH|Int32Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,4],[108],[106],[32,0],[34,7],[252,2],[54,0,4],[32,7],[12,1],[11],[32,16],[65,223,0],[70],[4,64,"TYPESWITCH|Float32Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,4],[108],[106],[32,0],[34,7],[182],[56,0,4],[32,7],[12,1],[11],[32,16],[65,224,0],[70],[4,64,"TYPESWITCH|Float64Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,8],[108],[106],[32,0],[34,7],[57,0,4],[32,7],[12,1],[11],[32,16],[65,128,1],[70],[4,64,"TYPESWITCH|undefined"],...internalThrow(scope, 'TypeError', `Cannot set property of undefined`),[68,0,0,0,0,0,0,0,0],[12,1],[11],[32,0],[11,"TYPESWITCH_end"],[26],...glbl(35, 'underlyingFuncObjs', 124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[32,3],[65,7],[16, builtin('__Map_prototype_set')],[33,6],[26],[11],[32,3],[65,7],[15],[11],[32,0],[32,1],[15]],
|
7
7
|
params: [124,127], typedParams: 1,
|
8
8
|
returns: [124,127], typedReturns: 1,
|
9
|
-
locals: [124,124,124,127,127], localNames: ["obj","obj#type","funcI32","underlying","#proto_target","#proto_target#type","#last_type"],
|
9
|
+
locals: [124,124,124,127,127,124,127,124,124,127,127,124,127,127,127], localNames: ["obj","obj#type","funcI32","underlying","#proto_target","#proto_target#type","#last_type","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#makearray_pointer_tmp","#swap","#member_prop","#loadArray_offset","#member_allocd","#typeswitch_tmp1"],
|
10
10
|
globalInits: {underlyingFuncObjs: (scope, {glbl,builtin}) => [[68,0,0,0,0,0,0,240,63],[65,6],[16, builtin('__Porffor_allocate')],[184],[65,7],[68,0,0,0,0,0,0,0,0],[65,128,1],[16, builtin('Map')],[26],...glbl(36, 'underlyingFuncObjs', 124)]},
|
11
11
|
};
|
12
12
|
this.__Porffor_object_preventExtensions = {
|
package/compiler/prefs.js
CHANGED
@@ -1,35 +1,27 @@
|
|
1
1
|
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'passiveData', 'rmUnusedTypes' ];
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
})();
|
21
|
-
|
22
|
-
// do not cache in web demo as args are changed live
|
23
|
-
if (!globalThis.document) cache[p] = ret;
|
24
|
-
return ret;
|
25
|
-
},
|
26
|
-
|
27
|
-
set(_, p, v) {
|
28
|
-
cache[p] = v;
|
29
|
-
return true;
|
3
|
+
const nameToKey = x => x.replace(/[a-z]\-[a-z]/g, y => `${y[0]}${y[2].toUpperCase()}`);
|
4
|
+
|
5
|
+
let prefs = {};
|
6
|
+
const getPrefs = () => {
|
7
|
+
prefs = {};
|
8
|
+
for (const x of onByDefault) prefs[x] = true;
|
9
|
+
|
10
|
+
for (const x of process.argv) {
|
11
|
+
if (x[0] !== '-') continue;
|
12
|
+
|
13
|
+
let flag = x.slice(x[1] === '-' ? 2 : 1);
|
14
|
+
if (flag.startsWith('no-')) {
|
15
|
+
prefs[nameToKey(flag.slice(3))] = false;
|
16
|
+
} else {
|
17
|
+
const [ name, value ] = flag.split('=');
|
18
|
+
prefs[nameToKey(name)] = value ?? true;
|
19
|
+
}
|
30
20
|
}
|
31
|
-
}
|
21
|
+
};
|
22
|
+
getPrefs();
|
32
23
|
|
33
|
-
export
|
24
|
+
export default prefs;
|
34
25
|
|
35
|
-
export
|
26
|
+
export const uncache = () => getPrefs();
|
27
|
+
globalThis.argvChanged = uncache;
|
package/compiler/wrap.js
CHANGED
@@ -65,6 +65,8 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type, override = undefin
|
|
65
65
|
const kValue = kRaw & 0x3fffffff;
|
66
66
|
const k = porfToJSValue({ memory, funcs, pages }, kValue, kType);
|
67
67
|
|
68
|
+
if (k === '__proto__') continue;
|
69
|
+
|
68
70
|
const tail = read(Uint16Array, memory, value + offset + 12, 1)[0];
|
69
71
|
|
70
72
|
const vValue = read(Float64Array, memory, value + offset + 4, 1)[0];
|
@@ -324,7 +326,8 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
324
326
|
max = func.wasm.length;
|
325
327
|
}
|
326
328
|
|
327
|
-
const decomp = decompile(func.wasm.slice(min, max), func.name, 0, func.locals, func.params, func.returns, funcs, globals, exceptions)
|
329
|
+
const decomp = decompile(func.wasm.slice(min, max), func.name, 0, func.locals, func.params, func.returns, funcs, globals, exceptions)
|
330
|
+
.slice(0, -1).split('\n').filter(x => !x.startsWith('\x1B[90m;;'));
|
328
331
|
|
329
332
|
const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
|
330
333
|
let longest = 0;
|
@@ -340,35 +343,18 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
340
343
|
if (min != 0) console.log('\x1B[90m...\x1B[0m');
|
341
344
|
console.log(decomp.join('\n'));
|
342
345
|
if (max > func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
|
343
|
-
}
|
346
|
+
};
|
344
347
|
|
345
348
|
const backtrace = (funcInd, blobOffset) => {
|
346
349
|
if (funcInd == null || blobOffset == null ||
|
347
350
|
Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
|
348
351
|
|
349
|
-
// convert blob offset -> function wasm offset
|
350
|
-
// this is not good code and is somewhat duplicated
|
351
|
-
// I just want it to work for debugging, I don't care about perf/yes
|
352
|
+
// convert blob offset -> function wasm offset
|
352
353
|
const func = funcs.find(x => x.index === funcInd);
|
353
354
|
if (!func) return false;
|
354
355
|
|
355
|
-
const
|
356
|
-
|
357
|
-
let localDecl = [], typeCount = 0, lastType;
|
358
|
-
for (let i = 0; i < locals.length; i++) {
|
359
|
-
const local = locals[i];
|
360
|
-
if (i !== 0 && local.type !== lastType) {
|
361
|
-
localDecl.push(encodeLocal(typeCount, lastType));
|
362
|
-
typeCount = 0;
|
363
|
-
}
|
364
|
-
|
365
|
-
typeCount++;
|
366
|
-
lastType = local.type;
|
367
|
-
}
|
368
|
-
|
369
|
-
if (typeCount !== 0) localDecl.push(encodeLocal(typeCount, lastType));
|
370
|
-
|
371
|
-
const toFind = encodeVector(localDecl).concat(func.wasm.flat().filter(x => x != null && x <= 0xff).slice(0, 60));
|
356
|
+
const { wasm: assembledWasmFlat, wasmNonFlat: assembledWasmOps, localDecl } = func.assembled;
|
357
|
+
const toFind = encodeVector(localDecl).concat(assembledWasmFlat.slice(0, 100));
|
372
358
|
|
373
359
|
let i = 0;
|
374
360
|
for (; i < wasm.length; i++) {
|
@@ -388,24 +374,21 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
388
374
|
return false;
|
389
375
|
}
|
390
376
|
|
391
|
-
const offset = (blobOffset - i)
|
377
|
+
const offset = (blobOffset - i) - encodeVector(localDecl).length;
|
392
378
|
|
393
379
|
let cumLen = 0;
|
394
380
|
i = 0;
|
395
|
-
for (; i <
|
396
|
-
cumLen +=
|
381
|
+
for (; i < assembledWasmOps.length; i++) {
|
382
|
+
cumLen += assembledWasmOps[i].filter(x => x != null && x <= 0xff).length;
|
397
383
|
if (cumLen === offset) break;
|
398
384
|
}
|
399
385
|
|
400
|
-
if (cumLen !== offset)
|
386
|
+
if (cumLen !== offset) {
|
401
387
|
printDecomp(-1, func, funcs, globals, exceptions);
|
402
388
|
return false;
|
403
389
|
}
|
404
390
|
|
405
|
-
i
|
406
|
-
|
407
|
-
printDecomp(i, func, funcs, globals, exceptions);
|
408
|
-
|
391
|
+
printDecomp(i + 1, func, funcs, globals, exceptions);
|
409
392
|
return true;
|
410
393
|
};
|
411
394
|
|
package/package.json
CHANGED