porffor 0.60.2 → 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 +17 -0
- package/compiler/builtins/json.ts +1 -1
- package/compiler/builtins_precompiled.js +433 -433
- package/compiler/index.js +43 -1
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/index.js
CHANGED
@@ -200,7 +200,7 @@ export default (code, module = Prefs.module) => {
|
|
200
200
|
const out = { funcs, globals, tags, exceptions, pages, data, times: [ t0, t1, t2, t3 ] };
|
201
201
|
if (globalThis.precompile) return out;
|
202
202
|
|
203
|
-
|
203
|
+
let wasm = out.wasm = assemble(funcs, globals, tags, pages, data);
|
204
204
|
if (logProgress) progressDone('assembled', t3);
|
205
205
|
|
206
206
|
if (Prefs.optFuncs || Prefs.f) logFuncs(funcs, globals, exceptions);
|
@@ -212,6 +212,48 @@ export default (code, module = Prefs.module) => {
|
|
212
212
|
console.log([...pages.keys()].map(x => `\x1B[36m - ${x}\x1B[0m`).join('\n') + '\n');
|
213
213
|
}
|
214
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
|
+
|
215
257
|
if (target === 'wasm' && outFile) {
|
216
258
|
fs.writeFileSync(outFile, Buffer.from(wasm));
|
217
259
|
|
package/package.json
CHANGED