porffor 0.55.14 → 0.55.16

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.
@@ -1,15 +1,14 @@
1
1
  import { Blocktype, Opcodes, Valtype, ValtypeSize } from './wasmSpec.js';
2
- import { ieee754_binary64, signedLEB128, unsignedLEB128, encodeVector, read_signedLEB128 } from './encoding.js';
2
+ import { number, ieee754_binary64, signedLEB128, unsignedLEB128, encodeVector, read_signedLEB128 } from './encoding.js';
3
3
  import { operatorOpcode } from './expression.js';
4
4
  import { BuiltinFuncs, BuiltinVars, importedFuncs, NULL, UNDEFINED } from './builtins.js';
5
5
  import { PrototypeFuncs } from './prototype.js';
6
- import { number } from './embedding.js';
7
6
  import { TYPES, TYPE_FLAGS, TYPE_NAMES, typeHasFlag } from './types.js';
8
7
  import * as Rhemyn from '../rhemyn/compile.js';
9
8
  import parse from './parse.js';
10
9
  import { log } from './log.js';
11
- import './prefs.js';
12
10
  import { allocPage, allocStr } from './allocator.js';
11
+ import './prefs.js';
13
12
 
14
13
  let globals = {};
15
14
  let tags = [];
@@ -1,7 +1,6 @@
1
1
  // cyclone: wasm partial constant evaluator (it is fast and dangerous hence "cyclone")
2
- import { signedLEB128, ieee754_binary64, read_ieee754_binary64, read_signedLEB128 } from './encoding.js';
2
+ import { number, signedLEB128, ieee754_binary64, read_ieee754_binary64, read_signedLEB128 } from './encoding.js';
3
3
  import { Opcodes, Valtype } from './wasmSpec.js';
4
- import { number } from './embedding.js';
5
4
 
6
5
  const f64ToI32Op = {
7
6
  [Opcodes.f64_eq]: Opcodes.i32_eq,
@@ -1,3 +1,13 @@
1
+ import { Opcodes, Valtype } from './wasmSpec.js';
2
+ export const number = (n, valtype = valtypeBinary) => {
3
+ if (valtype === Valtype.f64) return [ Opcodes.f64_const, n ];
4
+
5
+ const out = [ valtype === Valtype.i32 ? Opcodes.i32_const : Opcodes.i64_const ];
6
+ signedLEB128_into(n, out);
7
+
8
+ return out;
9
+ };
10
+
1
11
  export const codifyString = str => {
2
12
  let out = [];
3
13
  for (let i = 0; i < str.length; i++) {
package/compiler/opt.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Opcodes, Valtype } from './wasmSpec.js';
2
- import { number } from './embedding.js';
3
- import { read_signedLEB128, read_ieee754_binary64 } from './encoding.js';
2
+ import { number, read_signedLEB128, read_ieee754_binary64 } from './encoding.js';
4
3
  import { log } from './log.js';
5
4
  import './prefs.js';
6
5
 
package/compiler/pgo.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Opcodes, Valtype } from './wasmSpec.js';
2
- import { number } from './embedding.js';
2
+ import { number } from './encoding.js';
3
3
  import { importedFuncs } from './builtins.js';
4
- import './prefs.js';
5
4
  import assemble from './assemble.js';
6
5
  import wrap, { writeByteStr } from './wrap.js';
7
6
  import * as Havoc from './havoc.js';
7
+ import './prefs.js';
8
8
 
9
9
  export const setup = () => {
10
10
  importedFuncs[importedFuncs.profile2].params = [ Valtype.i32, valtypeBinary ];
@@ -216,7 +216,7 @@ const precompile = async () => {
216
216
  };
217
217
 
218
218
  return `// autogenerated by compiler/precompile.js
219
- import { number } from './embedding.js';
219
+ import { number } from './encoding.js';
220
220
 
221
221
  export const BuiltinFuncs = function() {
222
222
  ${funcs.map(x => {
@@ -230,7 +230,7 @@ ${funcs.map(x => {
230
230
  .replace(/\"local","(.*?)",(.*?)\]/g, (_, name, valtype) => `loc('${name}',${valtype})]`)
231
231
  .replace(/\[16,"(.*?)"]/g, (_, name) => `[16,builtin('${name}')]`)
232
232
  .replace(/\[(68|65),"funcref","(.*?)"]/g, (_1, op, name) => op === '65' ? `...i32ify(funcRef('${name}'))` : `...funcRef('${name}')`)
233
- .replace(/\[(68|65),"str","(.*?)",(.*?)]/g, (_1, op, str, forceBytestring) => op === '65' ? `...i32ify(makeString(_,${JSON.stringify(str)},${forceBytestring ? 1 : 0}))` : `...makeString(_,${JSON.stringify(str)},${forceBytestring ? 1 : 0})`)
233
+ .replace(/\[(68|65),"str","(.*?)",(.*?)]/g, (_1, op, str, forceBytestring) => op === '65' ? `...i32ify(makeString(_,"${str}",${forceBytestring ? 1 : 0}))` : `...makeString(_,"${str}",${forceBytestring ? 1 : 0})`)
234
234
  .replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(_,'${constructor}',\`${message}\`)`)
235
235
  .replace(/\["get object","(.*?)"\]/g, (_, objName) => `...generateIdent(_,{name:'${objName}'})`)
236
236
  .replace(/\[null,"typeswitch case start",\[(.*?)\]\],/g, (_, types) => `...t([${types}],()=>[`)
@@ -1,5 +1,5 @@
1
1
  import { Opcodes, Blocktype, Valtype, ValtypeSize } from './wasmSpec.js';
2
- import { number } from './embedding.js';
2
+ import { number } from './encoding.js';
3
3
  import { UNDEFINED } from './builtins.js';
4
4
  import { TYPES } from './types.js';
5
5
  import './prefs.js';
package/compiler/types.js CHANGED
@@ -58,15 +58,9 @@ registerInternalType('Map');
58
58
  registerInternalType('ArrayBuffer');
59
59
  registerInternalType('SharedArrayBuffer');
60
60
  registerInternalType('DataView');
61
- registerInternalType('Uint8Array', ['iterable', 'length']);
62
- registerInternalType('Int8Array', ['iterable', 'length']);
63
- registerInternalType('Uint8ClampedArray', ['iterable', 'length']);
64
- registerInternalType('Uint16Array', ['iterable', 'length']);
65
- registerInternalType('Int16Array', ['iterable', 'length']);
66
- registerInternalType('Uint32Array', ['iterable', 'length']);
67
- registerInternalType('Int32Array', ['iterable', 'length']);
68
- registerInternalType('Float32Array', ['iterable', 'length']);
69
- registerInternalType('Float64Array', ['iterable', 'length']);
61
+
62
+ for (const x of [ 'Uint8', 'Int8', 'Uint8Clamped', 'Uint16', 'Int16', 'Uint32', 'Int32', 'Float32', 'Float64' ])
63
+ registerInternalType(`${x}Array`, ['iterable', 'length']);
70
64
 
71
65
  registerInternalType('WeakRef');
72
66
  registerInternalType('WeakSet');
@@ -78,16 +72,8 @@ registerInternalType('BooleanObject');
78
72
  registerInternalType('NumberObject');
79
73
  registerInternalType('StringObject');
80
74
 
81
- registerInternalType('Error');
82
- registerInternalType('AggregateError');
83
- registerInternalType('TypeError');
84
- registerInternalType('ReferenceError');
85
- registerInternalType('SyntaxError');
86
- registerInternalType('RangeError');
87
- registerInternalType('EvalError');
88
- registerInternalType('URIError');
89
- registerInternalType('Test262Error');
90
- registerInternalType('TodoError');
75
+ for (const x of [ '', 'Aggregate', 'Type', 'Reference', 'Syntax', 'Range', 'Eval', 'URI', 'Test262', 'Todo' ])
76
+ registerInternalType(`${x}Error`);
91
77
 
92
78
  registerInternalType('__Porffor_Generator');
93
79
  registerInternalType('__Porffor_AsyncGenerator');
package/compiler/wrap.js CHANGED
@@ -335,6 +335,20 @@ ${flags & 0b0001 ? ` get func idx: ${get}
335
335
  return out;
336
336
  }
337
337
 
338
+ case TYPES.bigint: {
339
+ const negative = read(Uint8Array, memory, value, 1)[0] !== 0;
340
+ const len = read(Uint16Array, memory, value + 2, 1)[0];
341
+ const digits = read(Uint32Array, memory, value + 4, len);
342
+
343
+ console.log(digits);
344
+
345
+ let result = 0n;
346
+ for (let i = 0; i < digits.length; i++) {
347
+ result = result * 0x100000000n + BigInt(digits[i]);
348
+ }
349
+ return negative ? -result : result;
350
+ }
351
+
338
352
  default: return value;
339
353
  }
340
354
  };
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.55.14",
4
+ "version": "0.55.16",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/r.cjs CHANGED
@@ -1,14 +1,3 @@
1
- // 'use strict';
2
- function foo() {
3
- 'use strict';
4
- console.log(this);
5
- eval('console.log(this)');
6
- (0, eval)('console.log(this)');
7
- eval?.('console.log(this)');
8
- }
9
-
10
- foo();
11
-
12
1
  // let o = { set foo(x) { console.log('set foo', x); }, __proto__: { set bar(x) { console.log('set bar', x); } } };
13
2
 
14
3
  // o.foo = 1;
package/rhemyn/compile.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Blocktype, Opcodes, Valtype, ValtypeSize } from '../compiler/wasmSpec.js';
2
- import { number } from '../compiler/embedding.js';
2
+ import { number } from '../compiler/encoding.js';
3
3
  import parse from './parse.js';
4
- import '../compiler/prefs.js';
5
4
  import { TYPES } from '../compiler/types.js';
5
+ import '../compiler/prefs.js';
6
6
 
7
7
  // local indexes
8
8
  const BasePointer = 0; // base string pointer
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { Opcodes, Valtype } from '../compiler/wasmSpec.js';
3
- import { number } from '../compiler/embedding.js';
3
+ import { number } from '../compiler/encoding.js';
4
4
  import { importedFuncs } from '../compiler/builtins.js';
5
5
  import compile from '../compiler/wrap.js';
6
6
  import fs from 'node:fs';
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.55.14';
3
+ globalThis.version = '0.55.16';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
package/.fails.cjs DELETED
@@ -1,20 +0,0 @@
1
- const all = require('./all.json').map(x => x.slice(21));
2
- const { passes } = require('./test262/results.json');
3
- const fails = all.filter(x => !passes.includes(x));
4
- {
5
- const dirs = Object.groupBy(fails, x => x.split('/').slice(0, 2).join('/'));
6
- const top = Object.keys(dirs).sort((a, b) => dirs[b].length - dirs[a].length);
7
- console.log(top.slice(0, 20).map(x => `${x}: ${dirs[x].length} (${((dirs[x].length / all.length) * 100).toFixed(2)}%)`).join('\n'));
8
- }
9
- console.log()
10
- {
11
- const dirs = Object.groupBy(fails, x => x.split('/').slice(0, 3).join('/'));
12
- const top = Object.keys(dirs).sort((a, b) => dirs[b].length - dirs[a].length);
13
- console.log(top.slice(0, 20).map(x => `${x}: ${dirs[x].length} (${((dirs[x].length / all.length) * 100).toFixed(2)}%)`).join('\n'));
14
- }
15
- console.log()
16
- {
17
- const dirs = Object.groupBy(fails, x => x.split('/').slice(0, 4).join('/'));
18
- const top = Object.keys(dirs).sort((a, b) => dirs[b].length - dirs[a].length);
19
- console.log(top.slice(0, 20).map(x => `${x}: ${dirs[x].length} (${((dirs[x].length / all.length) * 100).toFixed(2)}%)`).join('\n'));
20
- }