porffor 0.16.0-6572d1c74 → 0.16.0-79cd8c0c8
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/codegen.js +3 -3
- package/compiler/index.js +16 -3
- package/compiler/pgo.js +8 -8
- package/compiler/wrap.js +1 -1
- package/package.json +2 -2
package/compiler/codegen.js
CHANGED
@@ -3270,7 +3270,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3270
3270
|
firstAssign = true;
|
3271
3271
|
|
3272
3272
|
// todo: can we just have 1 undeclared array? probably not? but this is not really memory efficient
|
3273
|
-
const uniqueName = name === '$undeclared' ? name +
|
3273
|
+
const uniqueName = name === '$undeclared' ? name + randId() : name;
|
3274
3274
|
|
3275
3275
|
let page;
|
3276
3276
|
if (Prefs.scopedPageNames) page = allocPage(scope, `${getAllocType(itemType)}: ${scope.name}/${uniqueName}`, itemType);
|
@@ -3658,7 +3658,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
3658
3658
|
});
|
3659
3659
|
};
|
3660
3660
|
|
3661
|
-
const randId = () => Math.random().toString(16).slice(
|
3661
|
+
const randId = () => Math.random().toString(16).slice(1, -2).padEnd(12, '0');
|
3662
3662
|
|
3663
3663
|
const objectHack = node => {
|
3664
3664
|
if (!node) return node;
|
@@ -3710,7 +3710,7 @@ const generateFunc = (scope, decl) => {
|
|
3710
3710
|
if (decl.async) return todo(scope, 'async functions are not supported');
|
3711
3711
|
if (decl.generator) return todo(scope, 'generator functions are not supported');
|
3712
3712
|
|
3713
|
-
const name = decl.id ? decl.id.name : `
|
3713
|
+
const name = decl.id ? decl.id.name : `anonymous${randId()}`;
|
3714
3714
|
const params = decl.params ?? [];
|
3715
3715
|
|
3716
3716
|
// TODO: share scope/locals between !!!
|
package/compiler/index.js
CHANGED
@@ -158,10 +158,23 @@ export default (code, flags) => {
|
|
158
158
|
|
159
159
|
if (process.version) {
|
160
160
|
if (Prefs.native) {
|
161
|
-
const
|
162
|
-
|
161
|
+
const cleanup = () => {
|
162
|
+
try {
|
163
|
+
fs.unlinkSync(outFile);
|
164
|
+
} catch {}
|
165
|
+
};
|
166
|
+
|
167
|
+
process.on('exit', cleanup);
|
168
|
+
process.on('beforeExit', cleanup);
|
169
|
+
process.on('SIGINT', () => {
|
170
|
+
cleanup();
|
171
|
+
process.exit();
|
172
|
+
});
|
163
173
|
|
164
|
-
|
174
|
+
const runArgs = process.argv.slice(2).filter(x => !x.startsWith('-'));
|
175
|
+
try {
|
176
|
+
execSync([ outFile, ...runArgs.slice(1) ].join(' '), { stdio: 'inherit' });
|
177
|
+
} catch {}
|
165
178
|
}
|
166
179
|
|
167
180
|
process.exit();
|
package/compiler/pgo.js
CHANGED
@@ -11,7 +11,7 @@ export const setup = () => {
|
|
11
11
|
|
12
12
|
// enable these prefs by default for pgo
|
13
13
|
Prefs.typeswitchUniqueTmp = Prefs.typeswitchUniqueTmp === false ? false : true;
|
14
|
-
Prefs.cyclone = Prefs.cyclone === false ? false : true
|
14
|
+
Prefs.cyclone = Prefs.cyclone === false ? false : true;
|
15
15
|
};
|
16
16
|
|
17
17
|
export const run = obj => {
|
@@ -131,16 +131,18 @@ export const run = obj => {
|
|
131
131
|
func.localValues = localValues;
|
132
132
|
|
133
133
|
let counts = new Array(10).fill(0);
|
134
|
-
const consistents = localData[i].map(x => {
|
135
|
-
if (
|
134
|
+
const consistents = localData[i].map((x, j) => {
|
135
|
+
if (j < func.params.length) return false; // param
|
136
|
+
if (x.length === 0 || !x.every((y, i) => i < 1 ? true : y === x[i - 1])) return false; // not consistent
|
136
137
|
|
137
138
|
counts[0]++;
|
138
139
|
return x[0];
|
139
140
|
});
|
140
141
|
|
141
142
|
const integerOnlyF64s = localData[i].map((x, j) => {
|
143
|
+
if (j < func.params.length) return false; // param
|
142
144
|
if (localValues[j].type === Valtype.i32) return false; // already i32
|
143
|
-
if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false;
|
145
|
+
if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false; // not all integer values
|
144
146
|
|
145
147
|
counts[1]++;
|
146
148
|
return true;
|
@@ -151,14 +153,14 @@ export const run = obj => {
|
|
151
153
|
|
152
154
|
log += ` ${func.name}: identified ${counts[0]}/${total} locals as consistent${Prefs.verbosePgo ? ':' : ''}\n`;
|
153
155
|
if (Prefs.verbosePgo) {
|
154
|
-
for (let j =
|
156
|
+
for (let j = func.params.length; j < localData[i].length; j++) {
|
155
157
|
log += ` ${consistents[j] !== false ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m: ${new Set(localData[i][j]).size} unique values set\n`;
|
156
158
|
}
|
157
159
|
}
|
158
160
|
|
159
161
|
log += ` ${func.name}: identified ${counts[1]}/${localValues.reduce((acc, x) => acc + (x.type === Valtype.f64 ? 1 : 0), 0)} f64 locals as integer usage only${Prefs.verbosePgo ? ':' : ''}\n`;
|
160
162
|
if (Prefs.verbosePgo) {
|
161
|
-
for (let j =
|
163
|
+
for (let j = func.params.length; j < localData[i].length; j++) {
|
162
164
|
if (localValues[j].type !== Valtype.f64) continue;
|
163
165
|
log += ` ${integerOnlyF64s[j] ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m\n`;
|
164
166
|
}
|
@@ -178,7 +180,6 @@ export const run = obj => {
|
|
178
180
|
for (let i = 0; i < x.integerOnlyF64s.length; i++) {
|
179
181
|
const c = x.integerOnlyF64s[i];
|
180
182
|
if (c === false) continue;
|
181
|
-
if (i < x.params.length) continue;
|
182
183
|
|
183
184
|
targets.push(i);
|
184
185
|
}
|
@@ -191,7 +192,6 @@ export const run = obj => {
|
|
191
192
|
for (let i = 0; i < x.consistents.length; i++) {
|
192
193
|
const c = x.consistents[i];
|
193
194
|
if (c === false) continue;
|
194
|
-
if (i < x.params.length) continue;
|
195
195
|
|
196
196
|
targets.push(i);
|
197
197
|
|
package/compiler/wrap.js
CHANGED
@@ -128,7 +128,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
128
128
|
|
129
129
|
if (source.includes?.('export ')) flags.push('module');
|
130
130
|
|
131
|
-
fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
131
|
+
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
132
132
|
|
133
133
|
times.push(performance.now() - t1);
|
134
134
|
if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "porffor",
|
3
3
|
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
|
4
|
-
"version": "0.16.0-
|
4
|
+
"version": "0.16.0-79cd8c0c8",
|
5
5
|
"author": "CanadaHonk",
|
6
6
|
"license": "MIT",
|
7
7
|
"scripts": {
|
@@ -28,5 +28,5 @@
|
|
28
28
|
"bugs": {
|
29
29
|
"url": "https://github.com/CanadaHonk/porffor/issues"
|
30
30
|
},
|
31
|
-
"homepage": "https://porffor.
|
31
|
+
"homepage": "https://porffor.dev"
|
32
32
|
}
|