porffor 0.18.13 → 0.18.14

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/types.js CHANGED
@@ -9,6 +9,16 @@ export const TYPES = {
9
9
  bigint: 0x07
10
10
  };
11
11
 
12
+ // flags
13
+ export const TYPE_FLAGS = {
14
+ // iterable: 0b10000000,
15
+ parity: 0b10000000,
16
+ length: 0b01000000,
17
+ };
18
+
19
+ // TYPES.string |= TYPE_FLAGS.iterable;
20
+ TYPES.string |= TYPE_FLAGS.length;
21
+
12
22
  export const TYPE_NAMES = {
13
23
  [TYPES.number]: 'Number',
14
24
  [TYPES.boolean]: 'Boolean',
@@ -20,23 +30,14 @@ export const TYPE_NAMES = {
20
30
  [TYPES.bigint]: 'BigInt'
21
31
  };
22
32
 
23
- // flags
24
- export const TYPE_FLAGS = {
25
- // iterable: 0b10000000,
26
- length: 0b01000000,
27
- };
28
-
29
- // TYPES.string |= TYPE_FLAGS.iterable;
30
- TYPES.string |= TYPE_FLAGS.length;
31
-
32
33
  export const typeHasFlag = (type, flag) => (type & flag) !== 0;
33
34
 
34
35
  export const INTERNAL_TYPE_BASE = 0x10;
35
36
  let internalTypeIndex = INTERNAL_TYPE_BASE;
36
- const registerInternalType = (name, flags = []) => {
37
- let n = internalTypeIndex++;
37
+ const registerInternalType = (name, flags = [], overrideType = undefined) => {
38
+ let n = overrideType ?? internalTypeIndex++;
38
39
 
39
- for (const x of flags) {
40
+ if (!overrideType) for (const x of flags) {
40
41
  if (TYPE_FLAGS[x]) n |= TYPE_FLAGS[x];
41
42
  }
42
43
 
@@ -49,7 +50,7 @@ const registerInternalType = (name, flags = []) => {
49
50
 
50
51
  registerInternalType('Array', ['iterable', 'length']);
51
52
  registerInternalType('RegExp');
52
- registerInternalType('ByteString', ['iterable', 'length']);
53
+ registerInternalType('ByteString', ['iterable', 'length'], TYPES.string | TYPE_FLAGS.parity);
53
54
  registerInternalType('Date');
54
55
  registerInternalType('Set', ['iterable']);
55
56
 
package/compiler/wrap.js CHANGED
@@ -150,7 +150,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
150
150
  const printDecomp = (middleIndex, func, funcs, globals, exceptions) => {
151
151
  console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
152
152
  console.log('\x1B[4m' + func.name + '\x1B[0m');
153
-
153
+
154
154
  const surrounding = Prefs.backtraceSurrounding ?? 5;
155
155
  let min = middleIndex - surrounding;
156
156
  let max = middleIndex + surrounding + 1;
@@ -158,7 +158,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
158
158
  min = 0;
159
159
  max = func.wasm.length;
160
160
  }
161
-
161
+
162
162
  const decomp = decompile(func.wasm.slice(min, max), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
163
163
 
164
164
  const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
@@ -166,15 +166,15 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
166
166
  for (let j = 0; j < decomp.length; j++) {
167
167
  longest = Math.max(longest, noAnsi(decomp[j]).length);
168
168
  }
169
-
169
+
170
170
  if (middleIndex != -1) {
171
171
  const middle = Math.floor(decomp.length / 2);
172
172
  decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
173
173
  }
174
-
174
+
175
175
  if (min != 0) console.log('\x1B[90m...\x1B[0m');
176
176
  console.log(decomp.join('\n'));
177
- if (max >= func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
177
+ if (max > func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
178
178
  }
179
179
 
180
180
  const backtrace = (funcInd, blobOffset) => {
@@ -288,8 +288,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
288
288
  }
289
289
  });
290
290
  } catch (e) {
291
- // only backtrace for runner, not test262/etc
292
- if (!process.argv[1].includes('/runner')) throw e;
291
+ if (!process.argv.includes('-i')) throw e;
293
292
  if (!(e instanceof WebAssembly.CompileError)) throw e;
294
293
 
295
294
  const funcInd = parseInt(e.message.match(/function #([0-9]+) /)?.[1]);
@@ -384,8 +383,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
384
383
  }
385
384
 
386
385
  if (e instanceof WebAssembly.RuntimeError) {
387
- // only backtrace for runner, not test262/etc
388
- if (!process.argv[1].includes('/runner')) throw e;
386
+ if (!process.argv.includes('-i')) throw e;
389
387
 
390
388
  const match = e.stack.match(/wasm-function\[([0-9]+)\]:([0-9a-z]+)/) ?? [];
391
389
  const funcInd = parseInt(match[1]);
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.18.13+5501d0132",
4
+ "version": "0.18.14+d7ef62736",
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.18.13+5501d0132';
3
+ globalThis.version = '0.18.14+d7ef62736';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {