porffor 0.30.10 → 0.30.11

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.
@@ -309,7 +309,8 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
309
309
 
310
310
  // todo: move const, call transforms here too?
311
311
 
312
- const wasm = [];
312
+ const makeAssembled = Prefs.d;
313
+ let wasm = [], wasmNonFlat = [];
313
314
  for (let i = 0; i < x.wasm.length; i++) {
314
315
  let o = x.wasm[i];
315
316
 
@@ -323,10 +324,20 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
323
324
  unsignedLEB128_into(n, o);
324
325
  }
325
326
 
326
- wasm.push(...o);
327
+ for (let j = 0; j < o.length; j++) {
328
+ const x = o[j];
329
+ if (x == null || !(x <= 0xff)) continue;
330
+ wasm.push(x);
331
+ }
332
+
333
+ if (makeAssembled) wasmNonFlat.push(o);
334
+ }
335
+
336
+ if (makeAssembled) {
337
+ x.assembled = { localDecl, wasm, wasmNonFlat };
327
338
  }
328
339
 
329
- return encodeVector([ ...encodeVector(localDecl), ...wasm.flat().filter(x => x != null && x <= 0xff), Opcodes.end ]);
340
+ return encodeVector([ ...encodeVector(localDecl), ...wasm, Opcodes.end ]);
330
341
  }))
331
342
  );
332
343
 
package/compiler/prefs.js CHANGED
@@ -1,35 +1,27 @@
1
1
  const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'passiveData', 'rmUnusedTypes' ];
2
2
 
3
- let cache = {};
4
- const obj = new Proxy({}, {
5
- get(_, p) {
6
- if (cache[p] != null) return cache[p];
7
-
8
- const ret = (() => {
9
- // fooBar -> foo-bar
10
- const name = p[0] === '_' ? p : p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
11
- const prefix = name.length === 1 ? '-' : '--';
12
- if (process.argv.includes(prefix + name)) return true;
13
- if (process.argv.includes(prefix + 'no-' + name)) return false;
14
-
15
- const valArg = process.argv.find(x => x.startsWith(`${prefix}${name}=`));
16
- if (valArg) return valArg.slice(name.length + 1 + prefix.length);
17
-
18
- if (onByDefault.includes(p)) return true;
19
- return undefined;
20
- })();
21
-
22
- // do not cache in web demo as args are changed live
23
- if (!globalThis.document) cache[p] = ret;
24
- return ret;
25
- },
26
-
27
- set(_, p, v) {
28
- cache[p] = v;
29
- return true;
3
+ const nameToKey = x => x.replace(/[a-z]\-[a-z]/g, y => `${y[0]}${y[2].toUpperCase()}`);
4
+
5
+ let prefs = {};
6
+ const getPrefs = () => {
7
+ prefs = {};
8
+ for (const x of onByDefault) prefs[x] = true;
9
+
10
+ for (const x of process.argv) {
11
+ if (x[0] !== '-') continue;
12
+
13
+ let flag = x.slice(x[1] === '-' ? 2 : 1);
14
+ if (flag.startsWith('no-')) {
15
+ prefs[nameToKey(flag.slice(3))] = false;
16
+ } else {
17
+ const [ name, value ] = flag.split('=');
18
+ prefs[nameToKey(name)] = value ?? true;
19
+ }
30
20
  }
31
- });
21
+ };
22
+ getPrefs();
32
23
 
33
- export const uncache = () => cache = {};
24
+ export default prefs;
34
25
 
35
- export default obj;
26
+ export const uncache = () => getPrefs();
27
+ globalThis.argvChanged = uncache;
package/compiler/wrap.js CHANGED
@@ -326,7 +326,8 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
326
326
  max = func.wasm.length;
327
327
  }
328
328
 
329
- const decomp = decompile(func.wasm.slice(min, max), func.name, 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
329
+ const decomp = decompile(func.wasm.slice(min, max), func.name, 0, func.locals, func.params, func.returns, funcs, globals, exceptions)
330
+ .slice(0, -1).split('\n').filter(x => !x.startsWith('\x1B[90m;;'));
330
331
 
331
332
  const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
332
333
  let longest = 0;
@@ -342,35 +343,18 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
342
343
  if (min != 0) console.log('\x1B[90m...\x1B[0m');
343
344
  console.log(decomp.join('\n'));
344
345
  if (max > func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
345
- }
346
+ };
346
347
 
347
348
  const backtrace = (funcInd, blobOffset) => {
348
349
  if (funcInd == null || blobOffset == null ||
349
350
  Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
350
351
 
351
- // convert blob offset -> function wasm offset.
352
- // this is not good code and is somewhat duplicated
353
- // I just want it to work for debugging, I don't care about perf/yes
352
+ // convert blob offset -> function wasm offset
354
353
  const func = funcs.find(x => x.index === funcInd);
355
354
  if (!func) return false;
356
355
 
357
- const locals = Object.values(func.locals).sort((a, b) => a.idx - b.idx).slice(func.params.length).sort((a, b) => a.idx - b.idx);
358
-
359
- let localDecl = [], typeCount = 0, lastType;
360
- for (let i = 0; i < locals.length; i++) {
361
- const local = locals[i];
362
- if (i !== 0 && local.type !== lastType) {
363
- localDecl.push(encodeLocal(typeCount, lastType));
364
- typeCount = 0;
365
- }
366
-
367
- typeCount++;
368
- lastType = local.type;
369
- }
370
-
371
- if (typeCount !== 0) localDecl.push(encodeLocal(typeCount, lastType));
372
-
373
- const toFind = encodeVector(localDecl).concat(func.wasm.flat().filter(x => x != null && x <= 0xff).slice(0, 60));
356
+ const { wasm: assembledWasmFlat, wasmNonFlat: assembledWasmOps, localDecl } = func.assembled;
357
+ const toFind = encodeVector(localDecl).concat(assembledWasmFlat.slice(0, 100));
374
358
 
375
359
  let i = 0;
376
360
  for (; i < wasm.length; i++) {
@@ -390,24 +374,21 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
390
374
  return false;
391
375
  }
392
376
 
393
- const offset = (blobOffset - i) + encodeVector(localDecl).length;
377
+ const offset = (blobOffset - i) - encodeVector(localDecl).length;
394
378
 
395
379
  let cumLen = 0;
396
380
  i = 0;
397
- for (; i < func.wasm.length; i++) {
398
- cumLen += func.wasm[i].filter(x => x != null && x <= 0xff).length;
381
+ for (; i < assembledWasmOps.length; i++) {
382
+ cumLen += assembledWasmOps[i].filter(x => x != null && x <= 0xff).length;
399
383
  if (cumLen === offset) break;
400
384
  }
401
385
 
402
- if (cumLen !== offset) {
386
+ if (cumLen !== offset) {
403
387
  printDecomp(-1, func, funcs, globals, exceptions);
404
388
  return false;
405
389
  }
406
390
 
407
- i -= 1;
408
-
409
- printDecomp(i, func, funcs, globals, exceptions);
410
-
391
+ printDecomp(i + 1, func, funcs, globals, exceptions);
411
392
  return true;
412
393
  };
413
394
 
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.30.10+1ed8b1535",
4
+ "version": "0.30.11+5ee60c5c3",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.30.10+1ed8b1535';
3
+ globalThis.version = '0.30.11+5ee60c5c3';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {