porffor 0.2.0-47b4f2e → 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.
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-47b4f2e",
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);
package/runner/repl.js CHANGED
@@ -45,9 +45,9 @@ let prev = '';
45
45
  const run = async (source, _context, _filename, callback, run = true) => {
46
46
  // hack: print "secret" before latest code ran to only enable printing for new code
47
47
 
48
- let toRun = prev + `;\nprint(-0x1337);\n` + source.trim();
48
+ let toRun = (prev ? (prev + `;\nprint(-0x1337);\n`) : '') + source.trim();
49
49
 
50
- let shouldPrint = false;
50
+ let shouldPrint = !prev;
51
51
  const { exports, wasm, pages } = await compile(toRun, [], {}, str => {
52
52
  if (shouldPrint) process.stdout.write(str);
53
53
  if (str === '-4919') shouldPrint = true;
@@ -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/tmp.c DELETED
@@ -1,69 +0,0 @@
1
-
2
- #include <stdio.h>
3
-
4
- struct ReturnValue {
5
- double value;
6
- long type;
7
- };
8
-
9
- double sum = 0;
10
- long sumdtype = 0;
11
- double counter = 0;
12
- long counterdtype = 0;
13
-
14
- double inline f64_f(double x, double y) {
15
- return (x - ((int)(x / y) * y));
16
- }
17
-
18
- struct ReturnValue isPrime(double number, long numberdtype) {
19
- double i = 0;
20
- long idtype = 0;
21
- double __tmpop_left = 0;
22
- double __tmpop_right = 0;
23
- long compare_left_pointer = 0;
24
- long compare_left_length = 0;
25
- long compare_right_pointer = 0;
26
- long compare_right_length = 0;
27
- long compare_index = 0;
28
- long compare_index_end = 0;
29
-
30
- if (number < 2e+0) {
31
- return (struct ReturnValue){ 1, 0e+0 };
32
- }
33
- i = 2e+0;
34
- idtype = 0;
35
- while (i < number) {
36
- if (f64_f(number, i) == 0e+0) {
37
- return (struct ReturnValue){ 1, 0e+0 };
38
- }
39
- i = i + 1e+0;
40
- }
41
- return (struct ReturnValue){ 1, 1e+0 };
42
- }
43
-
44
- double inline __console_log(double x) {
45
- printf("%f\n", x);
46
- printf("%c", (int)(1e+1));
47
- }
48
-
49
- int main() {
50
- long dlast_type = 0;
51
- double elogicinner_tmp = 0;
52
- long dtypeswitch_tmp = 0;
53
-
54
- sum = 0e+0;
55
- sumdtype = 0;
56
- counter = 0e+0;
57
- counterdtype = 0;
58
- while (counter <= 1e+5) {
59
- const struct ReturnValue _ = isPrime(counter, counterdtype);
60
- dlast_type = _.type;
61
- if ((unsigned long)(elogicinner_tmp = _.value) == 1e+0) {
62
- sum = sum + counter;
63
- sumdtype = 0;
64
- }
65
- counter = counter + 1e+0;
66
- }
67
- __console_log(sum);
68
- }
69
-