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/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
- const wasm = out.wasm = assemble(funcs, globals, tags, pages, data);
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.60.2",
4
+ "version": "0.60.3",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runtime/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.60.2';
3
+ globalThis.version = '0.60.3';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {