porffor 0.60.1 → 0.60.3
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 +20 -0
- package/compiler/2c.js +18 -2
- package/compiler/builtins/console.ts +27 -6
- package/compiler/builtins/json.ts +1 -1
- package/compiler/builtins_precompiled.js +443 -443
- package/compiler/codegen.js +14 -0
- package/compiler/index.js +45 -2
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -5361,6 +5361,20 @@ const ensureTag = (exceptionMode = Prefs.exceptionMode ?? 'stack') => {
|
|
5361
5361
|
};
|
5362
5362
|
|
5363
5363
|
const generateThrow = (scope, decl) => {
|
5364
|
+
if (Prefs.unreachableExceptions) {
|
5365
|
+
return [
|
5366
|
+
...generate(scope, {
|
5367
|
+
type: 'CallExpression',
|
5368
|
+
callee: {
|
5369
|
+
type: 'Identifier',
|
5370
|
+
name: '__console_log'
|
5371
|
+
},
|
5372
|
+
arguments: [ decl.argument ]
|
5373
|
+
}),
|
5374
|
+
[ Opcodes.unreachable ]
|
5375
|
+
];
|
5376
|
+
}
|
5377
|
+
|
5364
5378
|
if (Prefs.wasmExceptions === false) {
|
5365
5379
|
return [
|
5366
5380
|
...(scope.returns.length === 0 ? [] : [ number(0, scope.returns[0]) ]),
|
package/compiler/index.js
CHANGED
@@ -57,6 +57,7 @@ const progressClear = () => {
|
|
57
57
|
if (globalThis.onProgress) return;
|
58
58
|
if (!process.stdout.isTTY) return;
|
59
59
|
|
60
|
+
clearInterval(progressInterval);
|
60
61
|
process.stdout.write(`\u001b[${progressLines}F\u001b[0J`);
|
61
62
|
progressLines = 0;
|
62
63
|
};
|
@@ -199,7 +200,7 @@ export default (code, module = Prefs.module) => {
|
|
199
200
|
const out = { funcs, globals, tags, exceptions, pages, data, times: [ t0, t1, t2, t3 ] };
|
200
201
|
if (globalThis.precompile) return out;
|
201
202
|
|
202
|
-
|
203
|
+
let wasm = out.wasm = assemble(funcs, globals, tags, pages, data);
|
203
204
|
if (logProgress) progressDone('assembled', t3);
|
204
205
|
|
205
206
|
if (Prefs.optFuncs || Prefs.f) logFuncs(funcs, globals, exceptions);
|
@@ -211,6 +212,48 @@ export default (code, module = Prefs.module) => {
|
|
211
212
|
console.log([...pages.keys()].map(x => `\x1B[36m - ${x}\x1B[0m`).join('\n') + '\n');
|
212
213
|
}
|
213
214
|
|
215
|
+
if (Prefs.emscripten) {
|
216
|
+
const tmpFile = 'porffor_tmp.wasm';
|
217
|
+
const cO = Prefs._cO ?? 'Oz';
|
218
|
+
|
219
|
+
const args = [
|
220
|
+
'emcc',
|
221
|
+
'-xc', '-', // use stdin as c source in
|
222
|
+
'-s', 'STANDALONE_WASM=1',
|
223
|
+
'-s', 'NO_FILESYSTEM=1',
|
224
|
+
'-s', 'EXPORTED_FUNCTIONS=\'["_m"]\'',
|
225
|
+
'-nostartfiles',
|
226
|
+
'-Wl,--no-entry',
|
227
|
+
'-o', tmpFile,
|
228
|
+
'-' + cO,
|
229
|
+
Prefs.d ? '-g' : ''
|
230
|
+
];
|
231
|
+
|
232
|
+
if (Prefs.clangFast) args.push('-flto=thin', '-march=native', '-ffast-math', '-fno-asynchronous-unwind-tables');
|
233
|
+
|
234
|
+
if (Prefs.s) args.push('-s');
|
235
|
+
|
236
|
+
Prefs['2cWasmImports'] = true;
|
237
|
+
const c = toc(out)
|
238
|
+
.replace(`int main()`, `
|
239
|
+
void __wasi_proc_exit(int code) {
|
240
|
+
__builtin_trap();
|
241
|
+
}
|
242
|
+
|
243
|
+
int m()`);
|
244
|
+
Prefs['2cWasmImports'] = false;
|
245
|
+
|
246
|
+
// obvious command escape is obvious
|
247
|
+
execSync(args.join(' '), {
|
248
|
+
stdio: [ 'pipe', 'inherit', 'inherit' ],
|
249
|
+
input: c,
|
250
|
+
encoding: 'utf8'
|
251
|
+
});
|
252
|
+
|
253
|
+
out.wasm = wasm = fs.readFileSync(tmpFile, null);
|
254
|
+
fs.unlinkSync(tmpFile);
|
255
|
+
}
|
256
|
+
|
214
257
|
if (target === 'wasm' && outFile) {
|
215
258
|
fs.writeFileSync(outFile, Buffer.from(wasm));
|
216
259
|
|
@@ -281,7 +324,7 @@ export default (code, module = Prefs.module) => {
|
|
281
324
|
encoding: 'utf8'
|
282
325
|
});
|
283
326
|
|
284
|
-
if (logProgress)
|
327
|
+
if (logProgress) progressDone(`compiled C to native (using ${compiler})`, t5);
|
285
328
|
|
286
329
|
if (Prefs.native) {
|
287
330
|
const cleanup = () => {
|
package/package.json
CHANGED