porffor 0.55.23 → 0.55.25
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/2c.js +2 -2
- package/compiler/allocator.js +2 -3
- package/compiler/builtins/_internal_object.ts +24 -22
- package/compiler/builtins/console.ts +1 -1
- package/compiler/builtins/object.ts +15 -11
- package/compiler/builtins/object_prototypeWithHidden.js +1 -1
- package/compiler/builtins.js +6 -6
- package/compiler/builtins_objects.js +1 -1
- package/compiler/builtins_precompiled.js +23 -21
- package/compiler/codegen.js +20 -74
- package/compiler/index.js +2 -1
- package/package.json +1 -1
- package/r.cjs +5 -4
- package/runner/flamegraph.js +13 -13
- package/runner/index.js +1 -1
- package/runner/repl.js +1 -2
package/compiler/codegen.js
CHANGED
@@ -848,13 +848,6 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
|
|
848
848
|
] ] ] : []),
|
849
849
|
|
850
850
|
[ 'default', def ]
|
851
|
-
|
852
|
-
// [ [ TYPES.boolean, TYPES.number, TYPES.object, TYPES.undefined, TYPES.empty ], def ],
|
853
|
-
// [ 'default', [
|
854
|
-
// // other types are always truthy
|
855
|
-
// ...(!useTmp ? [ [ Opcodes.drop ] ] : []),
|
856
|
-
// number(1, intOut ? Valtype.i32 : valtypeBinary)
|
857
|
-
// ] ]
|
858
851
|
], intOut ? Valtype.i32 : valtypeBinary)
|
859
852
|
];
|
860
853
|
};
|
@@ -921,13 +914,6 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode
|
|
921
914
|
] ] ] : []),
|
922
915
|
|
923
916
|
[ 'default', def ]
|
924
|
-
|
925
|
-
// [ [ TYPES.boolean, TYPES.number, TYPES.object, TYPES.undefined, TYPES.empty ], def ],
|
926
|
-
// [ 'default', [
|
927
|
-
// // other types are always truthy
|
928
|
-
// ...(!useTmp ? [ [ Opcodes.drop ] ] : []),
|
929
|
-
// number(0, intOut ? Valtype.i32 : valtypeBinary)
|
930
|
-
// ] ]
|
931
917
|
], intOut ? Valtype.i32 : valtypeBinary)
|
932
918
|
];
|
933
919
|
};
|
@@ -1723,7 +1709,6 @@ const getNodeType = (scope, node) => {
|
|
1723
1709
|
if (guess != null) out.guess = typeof guess === 'number' ? [ number(guess, Valtype.i32) ] : guess;
|
1724
1710
|
|
1725
1711
|
typeUsed(scope, knownType(scope, out));
|
1726
|
-
|
1727
1712
|
return out;
|
1728
1713
|
};
|
1729
1714
|
|
@@ -1891,8 +1876,6 @@ const aliasPrimObjsBC = bc => {
|
|
1891
1876
|
const add = (x, y) => {
|
1892
1877
|
if (bc[x] == null) return;
|
1893
1878
|
|
1894
|
-
// bc[`${x},${y}`] = original;
|
1895
|
-
|
1896
1879
|
// intentionally duplicate to avoid extra bc for prim objs as rarely used
|
1897
1880
|
bc[y] = bc[x];
|
1898
1881
|
};
|
@@ -3124,8 +3107,6 @@ const extractTypeAnnotation = decl => {
|
|
3124
3107
|
const typeName = type;
|
3125
3108
|
type = typeAnnoToPorfType(type);
|
3126
3109
|
|
3127
|
-
// if (decl.name) console.log(decl.name, { type, elementType });
|
3128
|
-
|
3129
3110
|
return { type, typeName, elementType };
|
3130
3111
|
};
|
3131
3112
|
|
@@ -3551,6 +3532,8 @@ const memberTmpNames = scope => {
|
|
3551
3532
|
|
3552
3533
|
// COCTC: cross-object compile-time cache
|
3553
3534
|
const coctcOffset = prop => {
|
3535
|
+
if (!Prefs.coctc) return 0;
|
3536
|
+
|
3554
3537
|
if (typeof prop === 'object') {
|
3555
3538
|
if (
|
3556
3539
|
prop.computed || prop.optional ||
|
@@ -3562,7 +3545,7 @@ const coctcOffset = prop => {
|
|
3562
3545
|
|
3563
3546
|
let offset = coctc.get(prop);
|
3564
3547
|
if (offset == null) {
|
3565
|
-
offset = (coctc.lastOffset ??
|
3548
|
+
offset = (coctc.lastOffset ?? Prefs.coctcOffset ?? 16300) - 9;
|
3566
3549
|
if (offset < 0) return 0;
|
3567
3550
|
|
3568
3551
|
coctc.lastOffset = offset;
|
@@ -3691,7 +3674,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3691
3674
|
// todo/perf: use i32 object (and prop?) locals
|
3692
3675
|
const { objectTmp, propertyTmp, objectGet, propertyGet } = memberTmpNames(scope);
|
3693
3676
|
|
3694
|
-
const useCoctc =
|
3677
|
+
const useCoctc = coctcOffset(decl.left) > 0;
|
3695
3678
|
if (useCoctc) valueUnused = false;
|
3696
3679
|
|
3697
3680
|
// opt: do not mark prototype funcs as referenced to optimize this in them
|
@@ -4137,7 +4120,7 @@ const generateUnary = (scope, decl) => {
|
|
4137
4120
|
const property = getProperty(decl.argument);
|
4138
4121
|
if (property.value === 'length' || property.value === 'name') scope.noFastFuncMembers = true;
|
4139
4122
|
|
4140
|
-
const useCoctc =
|
4123
|
+
const useCoctc = coctcOffset(decl.argument) > 0;
|
4141
4124
|
const objectTmp = useCoctc && localTmp(scope, '#coctc_object', Valtype.i32);
|
4142
4125
|
|
4143
4126
|
const out = [
|
@@ -5658,7 +5641,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5658
5641
|
|
5659
5642
|
const out = [
|
5660
5643
|
...generate(scope, object),
|
5661
|
-
Opcodes.i32_to_u
|
5644
|
+
Opcodes.i32_to_u
|
5662
5645
|
];
|
5663
5646
|
|
5664
5647
|
if (Prefs.fastLength) {
|
@@ -5685,7 +5668,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5685
5668
|
...out,
|
5686
5669
|
[ Opcodes.local_set, tmp ],
|
5687
5670
|
|
5688
|
-
...
|
5671
|
+
...type,
|
5689
5672
|
number(TYPE_FLAGS.length, Valtype.i32),
|
5690
5673
|
[ Opcodes.i32_and ],
|
5691
5674
|
[ Opcodes.if, valtypeBinary ],
|
@@ -5707,6 +5690,8 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5707
5690
|
|
5708
5691
|
// todo/perf: use i32 object (and prop?) locals
|
5709
5692
|
const { objectTmp, propertyTmp, objectGet, propertyGet } = memberTmpNames(scope);
|
5693
|
+
const type = getNodeType(scope, object);
|
5694
|
+
const known = knownType(scope, type);
|
5710
5695
|
|
5711
5696
|
// todo: generate this array procedurally during builtinFuncs creation
|
5712
5697
|
if (['size', 'description', 'byteLength', 'byteOffset', 'buffer', 'detached', 'resizable', 'growable', 'maxByteLength'].includes(decl.property.name)) {
|
@@ -5714,7 +5699,6 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5714
5699
|
const bc = {};
|
5715
5700
|
const cands = Object.keys(builtinFuncs).filter(x => x.startsWith('__') && x.endsWith('_prototype_' + decl.property.name + '$get'));
|
5716
5701
|
|
5717
|
-
const known = knownType(scope, getNodeType(scope, object));
|
5718
5702
|
if (cands.length > 0) {
|
5719
5703
|
for (const x of cands) {
|
5720
5704
|
const type = TYPES[x.split('_prototype_')[0].slice(2).toLowerCase()];
|
@@ -5750,10 +5734,10 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5750
5734
|
if (known == null) extraBC = bc;
|
5751
5735
|
}
|
5752
5736
|
|
5753
|
-
const useCoctc =
|
5737
|
+
const useCoctc = coctcOffset(decl) > 0;
|
5754
5738
|
const coctcObjTmp = useCoctc && localTmp(scope, '#coctc_obj' + uniqId(), Valtype.i32);
|
5755
5739
|
|
5756
|
-
const out = typeSwitch(scope,
|
5740
|
+
const out = typeSwitch(scope, type, {
|
5757
5741
|
...(decl.computed ? {
|
5758
5742
|
[TYPES.array]: () => [
|
5759
5743
|
propertyGet,
|
@@ -5921,20 +5905,15 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5921
5905
|
|
5922
5906
|
[TYPES.undefined]: internalThrow(scope, 'TypeError', `Cannot read property of undefined`, true),
|
5923
5907
|
|
5924
|
-
// default: internalThrow(scope, 'TypeError', 'Unsupported member expression object', true)
|
5925
5908
|
default: () => [
|
5926
|
-
|
5927
|
-
|
5928
|
-
|
5929
|
-
|
5930
|
-
|
5931
|
-
|
5932
|
-
|
5933
|
-
|
5934
|
-
|
5935
|
-
objectGet,
|
5936
|
-
Opcodes.i32_to,
|
5937
|
-
...getNodeType(scope, object),
|
5909
|
+
...(useCoctc && known === TYPES.object ? [
|
5910
|
+
[ Opcodes.local_get, coctcObjTmp ],
|
5911
|
+
number(TYPES.object, Valtype.i32)
|
5912
|
+
] : [
|
5913
|
+
objectGet,
|
5914
|
+
Opcodes.i32_to,
|
5915
|
+
...type
|
5916
|
+
]),
|
5938
5917
|
|
5939
5918
|
...toPropertyKey(scope, [ propertyGet ], getNodeType(scope, property), decl.computed, true),
|
5940
5919
|
|
@@ -5954,7 +5933,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
5954
5933
|
...generate(scope, object),
|
5955
5934
|
[ Opcodes.local_tee, objectTmp ],
|
5956
5935
|
|
5957
|
-
...nullish(scope, [],
|
5936
|
+
...nullish(scope, [], type, false, true),
|
5958
5937
|
[ Opcodes.if, Blocktype.void ],
|
5959
5938
|
...setLastType(scope, TYPES.undefined),
|
5960
5939
|
number(0),
|
@@ -6959,39 +6938,6 @@ export default program => {
|
|
6959
6938
|
f.wasm = f.returns.map(x => number(0, x));
|
6960
6939
|
}
|
6961
6940
|
|
6962
|
-
// // remove never generated functions
|
6963
|
-
// let indexDelta = 0;
|
6964
|
-
// const funcRemap = new Map();
|
6965
|
-
// for (let i = 0; i < funcs.length; i++) {
|
6966
|
-
// const f = funcs[i];
|
6967
|
-
// if (f.internal || f.wasm) {
|
6968
|
-
// if (indexDelta) {
|
6969
|
-
// funcRemap.set(f.index, f.index - indexDelta);
|
6970
|
-
// f.index -= indexDelta;
|
6971
|
-
// }
|
6972
|
-
// continue;
|
6973
|
-
// }
|
6974
|
-
|
6975
|
-
// funcs.splice(i--, 1);
|
6976
|
-
// indexDelta++;
|
6977
|
-
// }
|
6978
|
-
|
6979
|
-
// // remap call ops
|
6980
|
-
// if (indexDelta) for (let i = 0; i < funcs.length; i++) {
|
6981
|
-
// const wasm = funcs[i].wasm;
|
6982
|
-
// for (let j = 0; j < wasm.length; j++) {
|
6983
|
-
// const op = wasm[j];
|
6984
|
-
// if (op[0] === Opcodes.call) {
|
6985
|
-
// let idx = op[1];
|
6986
|
-
// wasm[j] = [ Opcodes.call, funcRemap.get(idx) ?? idx ];
|
6987
|
-
// }
|
6988
|
-
|
6989
|
-
// if (op[0] === Opcodes.const && op[2] === 'funcref') {
|
6990
|
-
// wasm[j] = [ Opcodes.const, funcRemap.get(op[1] + importedFuncs.length) - importedFuncs.length ];
|
6991
|
-
// }
|
6992
|
-
// }
|
6993
|
-
// }
|
6994
|
-
|
6995
6941
|
// add indirect funcs to end of funcs
|
6996
6942
|
for (let i = 0; i < indirectFuncs.length; i++) {
|
6997
6943
|
const f = indirectFuncs[i];
|
package/compiler/index.js
CHANGED
@@ -73,7 +73,8 @@ export default (code, module = undefined) => {
|
|
73
73
|
globalThis.valtype = Prefs.valtype ?? 'f64';
|
74
74
|
globalThis.valtypeBinary = Valtype[valtype];
|
75
75
|
|
76
|
-
|
76
|
+
// use smaller page sizes internally (65536 / 4 = 16384)
|
77
|
+
globalThis.pageSize = Prefs.pageSize ?? (PageSize / 4);
|
77
78
|
|
78
79
|
// change some prefs by default for c/native
|
79
80
|
if (target !== 'wasm') {
|
package/package.json
CHANGED
package/r.cjs
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
let a = { b: { } };
|
2
|
+
a.b.foo = () => {};
|
3
|
+
a.b.bar = function () {};
|
4
|
+
a.b.baz = function baz() {};
|
5
5
|
|
6
|
+
console.log(a.b);
|
6
7
|
// let x = {};
|
7
8
|
// x.__proto__ = { wow() { console.log(0); } };
|
8
9
|
// Object.defineProperty(x, '__proto__', { value: { wow() { console.log(1); } } });
|
package/runner/flamegraph.js
CHANGED
@@ -55,7 +55,7 @@ const render = () => {
|
|
55
55
|
text += `${' '.repeat(32 - text.length)}┃ render: ${lastRenderTime.toFixed(2)}ms`;
|
56
56
|
|
57
57
|
if (end != null || Prefs.live) {
|
58
|
-
const btHeight =
|
58
|
+
const btHeight = 40;
|
59
59
|
const fgBottom = termHeight - btHeight - 10;
|
60
60
|
|
61
61
|
let lastEnds = [];
|
@@ -115,11 +115,11 @@ const render = () => {
|
|
115
115
|
(() => {
|
116
116
|
const perTime = 18;
|
117
117
|
let text = ' ' + 'name';
|
118
|
-
text += `${' '.repeat(
|
119
|
-
text += `${' '.repeat(
|
120
|
-
text += `${' '.repeat(
|
121
|
-
text += `${' '.repeat(
|
122
|
-
text += `${' '.repeat(
|
118
|
+
text += `${' '.repeat(60 - text.length)}┃ total`;
|
119
|
+
text += `${' '.repeat(60 + 5 + perTime - text.length)}┃ min`;
|
120
|
+
text += `${' '.repeat(60 + 5 + (perTime * 2) - text.length)}┃ avg`;
|
121
|
+
text += `${' '.repeat(60 + 5 + (perTime * 3) - text.length)}┃ max`;
|
122
|
+
text += `${' '.repeat(60 + 5 + (perTime * 4) - text.length)}┃ count`;
|
123
123
|
process.stdout.write(`\x1b[0m\x1b[2m${text.replaceAll('┃', '\x1b[0m\x1b[90m┃\x1b[0m\x1b[2m')}${' '.repeat(termWidth - text.length)}\x1b[0m`);
|
124
124
|
})();
|
125
125
|
|
@@ -134,13 +134,13 @@ const render = () => {
|
|
134
134
|
|
135
135
|
const perTime = 18;
|
136
136
|
let text = ' \x1b[1m' + func.name + '\x1b[22m';
|
137
|
-
text += `${' '.repeat(
|
138
|
-
text += `${' '.repeat(
|
139
|
-
text += `${' '.repeat(
|
140
|
-
text += `${' '.repeat(
|
141
|
-
text += `${' '.repeat(
|
142
|
-
text += `${' '.repeat(
|
143
|
-
process.stdout.write(`\x1b[${termHeight - btHeight + 2 + i};1H\x1b[0m${text.replaceAll('┃', '\x1b[90m┃\x1b[0m').replaceAll(
|
137
|
+
text += `${' '.repeat(69 - text.length)}┃ ${total.toFixed(2)}ms`;
|
138
|
+
text += `${' '.repeat(69 + perTime - text.length)}${((total / _total) * 100).toFixed(0)}%`;
|
139
|
+
text += `${' '.repeat(69 + 5 + perTime - text.length)}┃ ${min.toFixed(2)}ms`;
|
140
|
+
text += `${' '.repeat(69 + 5 + (perTime * 2) - text.length)}┃ ${avg.toFixed(2)}ms`;
|
141
|
+
text += `${' '.repeat(69 + 5 + (perTime * 3) - text.length)}┃ ${max.toFixed(2)}ms`;
|
142
|
+
text += `${' '.repeat(69 + 5 + (perTime * 4) - text.length)}┃ ${count}`;
|
143
|
+
process.stdout.write(`\x1b[${termHeight - btHeight + 2 + i};1H\x1b[0m${text.replaceAll('┃', '\x1b[90m┃\x1b[0m').replaceAll(/(\.[0-9][0-9])ms/g, '\x1b[2m$1ms\x1b[22m').replaceAll('%', '\x1b[2m%\x1b[22m')}${' '.repeat(termWidth - noAnsi(text).length)}`);
|
144
144
|
}
|
145
145
|
}
|
146
146
|
|
package/runner/index.js
CHANGED
package/runner/repl.js
CHANGED
@@ -34,10 +34,9 @@ console.log(`Welcome to \x1B[1m\x1B[35mPorffor\x1B[0m \x1B[2m(${globalThis.versi
|
|
34
34
|
console.log();
|
35
35
|
|
36
36
|
let lastMemory, lastPages;
|
37
|
-
const PageSize = 65536;
|
38
37
|
const memoryToString = mem => {
|
39
38
|
let out = '';
|
40
|
-
const wasmPages = mem.buffer.byteLength /
|
39
|
+
const wasmPages = mem.buffer.byteLength / 65536;
|
41
40
|
|
42
41
|
out += `\x1B[1mallocated ${mem.buffer.byteLength / 1024}KiB\x1B[0m (using ${wasmPages} Wasm page${wasmPages === 1 ? '' : 's'})\n\n`;
|
43
42
|
|