porffor 0.50.27 → 0.50.29

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,7 +1,10 @@
1
1
  export default () => {
2
2
  let out = '';
3
3
 
4
- const error = name => out += `export const ${name} = function (message: any) {
4
+ const errors = [];
5
+ const error = name => {
6
+ errors.push(name);
7
+ out += `export const ${name} = function (message: any) {
5
8
  if (message === undefined) message = '';
6
9
  else message = ecma262.ToString(message);
7
10
 
@@ -25,6 +28,7 @@ export const __${name}_prototype_toString = (_this: ${name}) => {
25
28
 
26
29
  return obj.name + ': ' + message;
27
30
  };`;
31
+ };
28
32
 
29
33
  error('Error');
30
34
  error('AggregateError');
@@ -38,7 +42,12 @@ export const __${name}_prototype_toString = (_this: ${name}) => {
38
42
  error('Test262Error');
39
43
  error('TodoError');
40
44
 
41
- out += `\nexport const __Test262Error_thrower = message => { throw new Test262Error(message); };`;
45
+ out += `
46
+ export const __Test262Error_thrower = message => {
47
+ throw new Test262Error(message);
48
+ };
49
+
50
+ export const __Error_isError = (x: unknown): boolean => Porffor.fastOr(${errors.map(x => `Porffor.rawType(x) == Porffor.TYPES.${x.toLowerCase()}`).join(', ')});`;
42
51
 
43
52
  return out;
44
53
  };
@@ -14,4 +14,9 @@ export const __Function_prototype_toLocaleString = (_this: Function) => __Functi
14
14
  export const __Function_prototype_apply = (_this: Function, thisArg: any, argsArray: any) => {
15
15
  argsArray = Array.from(argsArray ?? []);
16
16
  return Reflect.apply(_this, thisArg, argsArray);
17
+ };
18
+
19
+ export const __Function_prototype_bind = (_this: Function, thisArg: any, argsArray: any) => {
20
+ // todo: no good way to bind without dynamic functions or closure yet, just return function
21
+ return _this;
17
22
  };
@@ -364,13 +364,13 @@ export const BuiltinFuncs = function() {
364
364
  const prngSeed0 = (Math.random() * (2 ** 30)) | 0, prngSeed1 = (Math.random() * (2 ** 30)) | 0;
365
365
 
366
366
  const prng = ({
367
- 'lcg32_glibc': {
367
+ 'lcg32': {
368
368
  globals: [ Valtype.i32 ],
369
369
  locals: [],
370
370
  returns: Valtype.i32,
371
371
  wasm: [
372
+ // use glibc/musl's constants
372
373
  // seed = (MULTIPLIER * seed + INCREMENT) % MODULUS
373
- // MULTIPLIER * state0
374
374
  [ Opcodes.global_get, 0 ],
375
375
  number(1103515245, Valtype.i32),
376
376
  [ Opcodes.i32_mul ],
@@ -380,30 +380,8 @@ export const BuiltinFuncs = function() {
380
380
  [ Opcodes.i32_add ],
381
381
 
382
382
  // % MODULUS
383
- number(2 ** 31, Valtype.i32),
384
- [ Opcodes.i32_rem_s ],
385
-
386
- // state0 =
387
- [ Opcodes.global_set, 0 ],
388
-
389
- // state0
390
- [ Opcodes.global_get, 0 ],
391
- ],
392
- },
393
- 'lcg32_minstd': {
394
- globals: [ Valtype.i32 ],
395
- locals: [],
396
- returns: Valtype.i32,
397
- wasm: [
398
- // seed = (MULTIPLIER * seed + INCREMENT) % MODULUS
399
- // MULTIPLIER * state0
400
- [ Opcodes.global_get, 0 ],
401
- number(48271, Valtype.i32),
402
- [ Opcodes.i32_mul ],
403
-
404
- // % MODULUS
405
- number((2 ** 31) - 1, Valtype.i32),
406
- [ Opcodes.i32_rem_s ],
383
+ number(0x7fffffff, Valtype.i32),
384
+ [ Opcodes.i32_and ],
407
385
 
408
386
  // state0 =
409
387
  [ Opcodes.global_set, 0 ],
@@ -484,11 +462,6 @@ export const BuiltinFuncs = function() {
484
462
  // state0 = s1
485
463
  [ Opcodes.global_set, 0 ],
486
464
 
487
- // // s1 * 0x2545F4914F6CDD1D
488
- // [ Opcodes.local_get, 0 ],
489
- // [ Opcodes.i64_const, 0x9d, 0xba, 0xb3, 0xfb, 0x94, 0x92, 0xfd, 0xa2, 0x25 ],
490
- // [ Opcodes.i64_mul ]
491
-
492
465
  // s1
493
466
  [ Opcodes.local_get, 0 ],
494
467
  ],
@@ -1691,6 +1691,11 @@ params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
1691
1691
  locals:[],localNames:["message","message#type"],
1692
1692
  usesTag:1,
1693
1693
  }
1694
+ this.__Error_isError = {
1695
+ wasm:()=>[[32,1],[184],[68,40],[97],[32,1],[184],[68,41],[97],[114],[32,1],[184],[68,42],[97],[114],[32,1],[184],[68,43],[97],[114],[32,1],[184],[68,44],[97],[114],[32,1],[184],[68,45],[97],[114],[32,1],[184],[68,46],[97],[114],[32,1],[184],[68,47],[97],[114],[32,1],[184],[68,48],[97],[114],[32,1],[184],[68,49],[97],[114],[184],[65,2],[15]],
1696
+ params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
1697
+ locals:[],localNames:["x","x#type"],
1698
+ }
1694
1699
  this.escape = {
1695
1700
  wasm:(_,{i32ify,makeString,builtin})=>[...i32ify(makeString(_,"\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0001\\u0000\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0001\\u0000\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0001\\u0000\\u0000\\u0000\\u0000\\u0000",1)),[33,2],[32,0],[40,1,0],[34,3],[33,4],[32,0],[33,5],[32,1],[65,195,1],[70],[4,64],[32,5],[32,3],[106],[33,6],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[34,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[12,3],[26],[11],[11],[32,4],[65,2],[106],[33,4],[12,1],[11],[11],[32,4],[32,3],[70],[4,64],[32,0],[32,1],[15],[26],[11],[16,builtin('__Porffor_allocate')],[34,8],[32,4],[54,1,0],[32,0],[33,5],[32,8],[33,9],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[34,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[32,9],[32,9],[65,1],[106],[33,9],[32,7],[58,0,4],[12,3],[26],[11],[11],[32,9],[32,9],[65,1],[106],[33,9],[65,37],[58,0,4],[32,7],[65,15],[113],[65,48],[106],[34,10],[65,57],[74],[4,64],[32,10],[65,7],[106],[33,10],[11],[32,7],[65,4],[117],[65,48],[106],[34,11],[65,57],[74],[4,64],[32,11],[65,7],[106],[33,11],[11],[32,9],[32,9],[65,1],[106],[33,9],[32,11],[58,0,4],[32,9],[32,9],[65,1],[106],[33,9],[32,10],[58,0,4],[12,1],[11],[11],[32,8],[65,195,1],[15],[26],[11],[32,5],[32,3],[65,2],[108],[106],[33,6],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[47,0,4],[33,7],[32,5],[65,2],[106],[33,5],[32,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[12,3],[26],[11],[11],[32,7],[65,128,2],[72],[4,64],[32,4],[65,2],[106],[33,4],[5],[32,4],[65,5],[106],[33,4],[11],[12,1],[11],[11],[32,4],[32,3],[70],[4,64],[32,0],[32,1],[15],[26],[11],[16,builtin('__Porffor_allocate')],[34,8],[32,4],[54,1,0],[32,0],[33,5],[32,8],[33,9],[3,64],[32,5],[32,6],[72],[4,64],[32,5],[47,0,4],[33,7],[32,5],[65,2],[106],[33,5],[32,7],[65,128,1],[72],[4,64],[32,2],[32,7],[106],[45,0,4],[4,64],[32,9],[32,9],[65,1],[106],[33,9],[32,7],[58,0,4],[12,3],[26],[11],[11],[32,7],[65,128,2],[72],[4,64],[32,9],[32,9],[65,1],[106],[33,9],[65,37],[58,0,4],[32,7],[65,15],[113],[65,48],[106],[34,10],[65,57],[74],[4,64],[32,10],[65,7],[106],[33,10],[11],[32,7],[65,4],[117],[65,48],[106],[34,11],[65,57],[74],[4,64],[32,11],[65,7],[106],[33,11],[11],[32,9],[32,9],[65,1],[106],[33,9],[32,11],[58,0,4],[32,9],[32,9],[65,1],[106],[33,9],[32,10],[58,0,4],[5],[32,9],[65,165,234,1],[59,0,4],[32,9],[65,2],[106],[33,9],[32,7],[65,12],[117],[65,15],[113],[65,48],[106],[34,12],[65,57],[74],[4,64],[32,12],[65,7],[106],[33,12],[11],[32,9],[32,9],[65,1],[106],[33,9],[32,12],[58,0,4],[32,7],[65,8],[117],[65,15],[113],[65,48],[106],[34,12],[65,57],[74],[4,64],[32,12],[65,7],[106],[33,12],[11],[32,9],[32,9],[65,1],[106],[33,9],[32,12],[58,0,4],[32,7],[65,4],[117],[65,15],[113],[65,48],[106],[34,12],[65,57],[74],[4,64],[32,12],[65,7],[106],[33,12],[11],[32,9],[32,9],[65,1],[106],[33,9],[32,12],[58,0,4],[32,7],[65,15],[113],[65,48],[106],[34,12],[65,57],[74],[4,64],[32,12],[65,7],[106],[33,12],[11],[32,9],[32,9],[65,1],[106],[33,9],[32,12],[58,0,4],[11],[12,1],[11],[11],[32,8],[65,195,1],[15]],
1696
1701
  params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
@@ -1717,6 +1722,12 @@ locals:[124,124,127,127],localNames:["_this","_this#type","thisArg","thisArg#typ
1717
1722
  usedTypes:[80],
1718
1723
  usesTag:1,
1719
1724
  }
1725
+ this.__Function_prototype_bind = {
1726
+ wasm:(_,{internalThrow})=>[[32,1],[65,6],[71],[4,64],...internalThrow(_,'TypeError',`Function.prototype.bind expects 'this' to be a Function`),[11],[32,0],[65,6],[15]],
1727
+ params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
1728
+ locals:[],localNames:["_this","_this#type","thisArg","thisArg#type","argsArray","argsArray#type"],
1729
+ usesTag:1,
1730
+ }
1720
1731
  this.__Porffor_Generator = {
1721
1732
  wasm:()=>[[32,0],[34,2],[65,50],[15]],
1722
1733
  params:[124,127],typedParams:1,returns:[124,127],typedReturns: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.50.27",
4
+ "version": "0.50.29",
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.50.27';
3
+ globalThis.version = '0.50.29';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
@@ -63,7 +63,7 @@ if (process.argv.includes('--help')) {
63
63
  pgo: 'Enable PGO (profile-guided optimization)',
64
64
  'profile-compiler': 'Log general compiler performance (on by default when compiling to a file)',
65
65
  valtype: 'Valtype to use (i32|i64|\x1B[1mf64\x1B[0m)',
66
- prng: 'PRNG algorithm to use (lcg32_glibc|lcg32_minstd|xorshift32+|xorshift64+|\x1B[1mxorshift128+\x1B[0m|xoroshiro128+|xoshiro128+)',
66
+ prng: 'PRNG algorithm to use (lcg32|xorshift32+|xorshift64+|\x1B[1mxorshift128+\x1B[0m|xoroshiro128+|xoshiro128+)',
67
67
  allocator: 'Allocator to use (oneshot|\x1B[1mchunk\x1B[0m)',
68
68
  'exception-mode': 'Exception mode to use (lut|\x1B[1mstack\x1B[0m)',
69
69
  fastLength: 'Spec non-compliant optimization to make .length faster',
@@ -162,7 +162,7 @@ if (process.argv.length >= 4) {
162
162
  }
163
163
  }
164
164
 
165
- if (file.startsWith('https://')) { // https only :)
165
+ if (file && file.startsWith('https://')) { // https only :)
166
166
  // rce warning, make user confirm (disabled)
167
167
  // const rl = (await import('readline')).createInterface({ input: process.stdin, output: process.stdout });
168
168
  // const ans = await new Promise(resolve => rl.question(`\u001b[1mAre you sure you want to download this URL:\u001b[0m ${file} (y/n)? `, ans => {