porffor 0.2.0-4035760 → 0.2.0-4b72c49

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.
@@ -62,13 +62,21 @@ export const Opcodes = {
62
62
  i32_load16_s: 0x2e,
63
63
  i32_load16_u: 0x2f,
64
64
 
65
- i32_store8: 0x3a,
66
- i32_store16: 0x3b,
65
+ i64_load8_s: 0x30,
66
+ i64_load8_u: 0x31,
67
+ i64_load16_s: 0x32,
68
+ i64_load16_u: 0x33,
67
69
 
68
70
  i32_store: 0x36,
69
71
  i64_store: 0x37,
70
72
  f64_store: 0x39,
71
73
 
74
+ i32_store8: 0x3a,
75
+ i32_store16: 0x3b,
76
+
77
+ i64_store8: 0x3c,
78
+ i64_store16: 0x3d,
79
+
72
80
  memory_grow: 0x40,
73
81
 
74
82
  i32_const: 0x41,
package/compiler/wrap.js CHANGED
@@ -191,7 +191,8 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
191
191
  case 'function': {
192
192
  // wasm func index, including all imports
193
193
  const func = funcs.find(x => (x.originalIndex ?? x.index) === ret);
194
- if (!func) return ret;
194
+ // if (!func) return ret;
195
+ if (!func) return function () {};
195
196
 
196
197
  // make fake empty func for repl/etc
197
198
  return {[func.name]() {}}[func.name];
package/demo.js ADDED
@@ -0,0 +1,15 @@
1
+ function isPrime(number) {
2
+ if (number < 2) return false;
3
+
4
+ for (let i = 2; i < number; i++) {
5
+ if (number % i == 0) return false;
6
+ }
7
+
8
+ return true;
9
+ }
10
+
11
+ let counter = 0;
12
+ while (counter <= 10000) {
13
+ if (isPrime(counter)) console.log(counter);
14
+ counter++;
15
+ }
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.2.0-4035760",
4
+ "version": "0.2.0-4b72c49",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "dependencies": {
package/porf ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node runner/index.js "$@"
package/rhemyn/compile.js CHANGED
@@ -2,6 +2,7 @@ import { Blocktype, Opcodes, Valtype, PageSize, ValtypeSize } from '../compiler/
2
2
  import { number } from '../compiler/embedding.js';
3
3
  import { signedLEB128, unsignedLEB128 } from '../compiler/encoding.js';
4
4
  import parse from './parse.js';
5
+ import Prefs from '../compiler/prefs.js';
5
6
 
6
7
  // local indexes
7
8
  const BasePointer = 0; // base string pointer
@@ -80,7 +81,7 @@ const generate = (node, negated = false, get = true, func = 'test') => {
80
81
  })[func], Valtype.i32)
81
82
  ];
82
83
 
83
- if (globalThis.regexLog) {
84
+ if (Prefs.regexLog) {
84
85
  const underline = x => `\u001b[4m\u001b[1m${x}\u001b[0m`;
85
86
  console.log(`\n${underline('ast')}`);
86
87
  console.log(node);
package/runner/index.js CHANGED
@@ -3,6 +3,8 @@
3
3
  import compile from '../compiler/wrap.js';
4
4
  import fs from 'node:fs';
5
5
 
6
+ const start = performance.now();
7
+
6
8
  if (process.argv.includes('-compile-hints')) {
7
9
  const v8 = await import('node:v8');
8
10
  v8.setFlagsFromString(`--experimental-wasm-compilation-hints`);
@@ -15,9 +17,22 @@ if (process.argv.includes('-compile-hints')) {
15
17
  // --experimental-wasm-return-call (on by default)
16
18
  }
17
19
 
18
- const file = process.argv.slice(2).find(x => x[0] !== '-');
20
+ let file = process.argv.slice(2).find(x => x[0] !== '-');
21
+ if (['run', 'wasm', 'native', 'c'].includes(file)) {
22
+ if (['wasm', 'native', 'c'].includes(file)) {
23
+ process.argv.push(`-target=${file}`);
24
+ }
25
+
26
+ file = process.argv.slice(process.argv.indexOf(file) + 1).find(x => x[0] !== '-');
27
+
28
+ const nonOptOutFile = process.argv.slice(process.argv.indexOf(file) + 1).find(x => x[0] !== '-');
29
+ if (nonOptOutFile) {
30
+ process.argv.push(`-o=${nonOptOutFile}`);
31
+ }
32
+ }
33
+
19
34
  if (!file) {
20
- if (process.argv.includes('-v')) {
35
+ if (process.argv.includes('-v') || process.argv.includes('--version')) {
21
36
  // just print version
22
37
  console.log((await import('./version.js')).default);
23
38
  process.exit(0);
@@ -52,4 +67,6 @@ try {
52
67
  } catch (e) {
53
68
  if (cache) process.stdout.write(cache);
54
69
  console.error(process.argv.includes('-i') ? e : `${e.constructor.name}: ${e.message}`);
55
- }
70
+ }
71
+
72
+ if (process.argv.includes('-t')) console.log(performance.now() - start);
@@ -1,92 +0,0 @@
1
- var btoa_a = str => {
2
- // todo: throw invalid character for unicode
3
-
4
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5
- const mask = (1 << 6) - 1;
6
-
7
- let out = '';
8
- let bits = 0, buffer = 0;
9
- for (let i = 0; i < str.length; i++) {
10
- buffer = (buffer << 8) | (0xff & str.charCodeAt(i));
11
- bits += 8;
12
-
13
- while (bits > 6) {
14
- bits -= 6;
15
- out += chars[mask & (buffer >> bits)];
16
- }
17
- }
18
-
19
- if (bits) {
20
- out += chars[mask & (buffer << (6 - bits))]
21
- }
22
-
23
- while ((out.length * 6) & 7) {
24
- out += '=';
25
- }
26
-
27
- return out;
28
- };
29
-
30
- var btoa = function (input) {
31
- // todo: throw invalid character for unicode
32
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
33
-
34
- let output = "";
35
- let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
36
- let i = 0;
37
-
38
- while (i < input.length) {
39
- chr1 = input.charCodeAt(i++);
40
- chr2 = input.charCodeAt(i++);
41
- chr3 = input.charCodeAt(i++);
42
-
43
- enc1 = chr1 >> 2;
44
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
45
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
46
- enc4 = chr3 & 63;
47
-
48
- if (isNaN(chr2)) {
49
- enc3 = enc4 = 64;
50
- } else if (isNaN(chr3)) {
51
- enc4 = 64;
52
- }
53
-
54
- output += keyStr.charAt(enc1);
55
- output += keyStr.charAt(enc2);
56
- output += keyStr.charAt(enc3);
57
- output += keyStr.charAt(enc4);
58
- }
59
-
60
- return output;
61
- };
62
-
63
- var atob_b = function (input) {
64
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
65
-
66
- let output = "";
67
- let chr1, chr2, chr3;
68
- let enc1, enc2, enc3, enc4;
69
- let i = 0;
70
-
71
- while (i < input.length) {
72
- enc1 = keyStr.indexOf(input.charAt(i++));
73
- enc2 = keyStr.indexOf(input.charAt(i++));
74
- enc3 = keyStr.indexOf(input.charAt(i++));
75
- enc4 = keyStr.indexOf(input.charAt(i++));
76
-
77
- chr1 = (enc1 << 2) | (enc2 >> 4);
78
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
79
- chr3 = ((enc3 & 3) << 6) | enc4;
80
-
81
- output += String.fromCharCode(chr1);
82
-
83
- if (enc3 != 64) {
84
- output += String.fromCharCode(chr2);
85
- }
86
- if (enc4 != 64) {
87
- output += String.fromCharCode(chr3);
88
- }
89
- }
90
-
91
- return output;
92
- };
package/r.js DELETED
@@ -1,45 +0,0 @@
1
-
2
- function assert(mustBeTrue) {
3
- if (mustBeTrue === true) {
4
- return;
5
- }
6
-
7
- throw new Test262Error('assert failed');
8
- }
9
-
10
- assert._isSameValue = function (a, b) {
11
- if (a === b) {
12
- // Handle +/-0 vs. -/+0
13
- return a !== 0 || 1 / a === 1 / b;
14
- }
15
-
16
- // Handle NaN vs. NaN
17
- return a !== a && b !== b;
18
-
19
- // return a === b;
20
- };
21
-
22
- assert.sameValue = function (actual, expected) {
23
- if (assert._isSameValue(actual, expected)) {
24
- return;
25
- }
26
-
27
- throw new Test262Error('assert.sameValue failed');
28
- };
29
-
30
- assert.notSameValue = function (actual, unexpected) {
31
- if (!assert._isSameValue(actual, unexpected)) {
32
- return;
33
- }
34
-
35
- throw new Test262Error('assert.notSameValue failed');
36
- };
37
- function $DONOTEVALUATE() {
38
- throw "Test262: This statement should not be evaluated.";
39
- }
40
-
41
- verifyProperty(this, "Infinity", {
42
- enumerable: false,
43
- writable: false,
44
- configurable: false
45
- });