porffor 0.2.0-1afe9b8 → 0.2.0-240f1c8

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/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,3 @@
1
+ // foo();
2
+
3
+ console.log('Hello, World!');
package/demo.ts ADDED
@@ -0,0 +1 @@
1
+ console.log("hello world");
package/filesize.cmd ADDED
@@ -0,0 +1,2 @@
1
+ @echo off
2
+ echo %~z1
package/hello ADDED
Binary file
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-1afe9b8",
4
+ "version": "0.2.0-240f1c8",
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/tmp.c ADDED
@@ -0,0 +1,152 @@
1
+ #include <stdint.h>
2
+ #include <string.h>
3
+ #include <stdio.h>
4
+
5
+ typedef uint8_t i8;
6
+ typedef uint16_t i16;
7
+ typedef int32_t i32;
8
+ typedef uint32_t u32;
9
+ typedef int64_t i64;
10
+ typedef uint64_t u64;
11
+ typedef float f32;
12
+ typedef double f64;
13
+
14
+ f64 NAN = 0e+0/0e+0;
15
+
16
+ struct ReturnValue {
17
+ f64 value;
18
+ i32 type;
19
+ };
20
+
21
+ char _memory[65536];
22
+
23
+ i32 i32_load(i32 align, i32 offset, i32 pointer) {
24
+ i32 out;
25
+ memcpy(&out, _memory + offset + pointer, sizeof(out));
26
+ return out;
27
+ }
28
+
29
+ i32 i32_load16_u(i32 align, i32 offset, i32 pointer) {
30
+ i16 out;
31
+ memcpy(&out, _memory + offset + pointer, sizeof(out));
32
+ return out;
33
+ }
34
+
35
+
36
+ void inline __console_log(f64 x, i32 y) {
37
+ i32 a = 0;
38
+ i32 b = 0;
39
+ i32 dtypeswitch_tmp = 0;
40
+
41
+ dtypeswitch_tmp = y;
42
+ // block
43
+ // if
44
+ if (dtypeswitch_tmp == 0) {
45
+ printf("%g\n", x);
46
+ goto j0;
47
+ }
48
+ // end
49
+ j1:;
50
+ // if
51
+ if (dtypeswitch_tmp == 1) {
52
+ // if
53
+ if (((u32)x) != 0) {
54
+ printf("%c", (int)(1.16e+2));
55
+ printf("%c", (int)(1.14e+2));
56
+ printf("%c", (int)(1.17e+2));
57
+ printf("%c", (int)(1.01e+2));
58
+ } else {
59
+ printf("%c", (int)(1.02e+2));
60
+ printf("%c", (int)(9.7e+1));
61
+ printf("%c", (int)(1.08e+2));
62
+ printf("%c", (int)(1.15e+2));
63
+ printf("%c", (int)(1.01e+2));
64
+ }
65
+ // end
66
+ j3:;
67
+ goto j0;
68
+ }
69
+ // end
70
+ j2:;
71
+ // if
72
+ if (dtypeswitch_tmp == 2) {
73
+ a = (u32)x;
74
+ b = (i32_load(1, 0, a) * 2) + a;
75
+ // loop
76
+ j5:;
77
+ printf("%c", (int)((f64)(i32_load16_u(0, 4, a))));
78
+ a = a + 2;
79
+ if (a != b) {
80
+ goto j5;
81
+ }
82
+ // end
83
+ goto j0;
84
+ }
85
+ // end
86
+ j4:;
87
+ // if
88
+ if (dtypeswitch_tmp == 3) {
89
+ printf("%c", (int)(1.17e+2));
90
+ printf("%c", (int)(1.1e+2));
91
+ printf("%c", (int)(1e+2));
92
+ printf("%c", (int)(1.01e+2));
93
+ printf("%c", (int)(1.02e+2));
94
+ printf("%c", (int)(1.05e+2));
95
+ printf("%c", (int)(1.1e+2));
96
+ printf("%c", (int)(1.01e+2));
97
+ printf("%c", (int)(1e+2));
98
+ goto j0;
99
+ }
100
+ // end
101
+ j6:;
102
+ // if
103
+ if (dtypeswitch_tmp == 4) {
104
+ // if
105
+ if (((u32)x) != 0) {
106
+ printf("%c", (int)(1.23e+2));
107
+ printf("%c", (int)(1.25e+2));
108
+ } else {
109
+ printf("%c", (int)(1.1e+2));
110
+ printf("%c", (int)(1.17e+2));
111
+ printf("%c", (int)(1.08e+2));
112
+ printf("%c", (int)(1.08e+2));
113
+ }
114
+ // end
115
+ j8:;
116
+ goto j0;
117
+ }
118
+ // end
119
+ j7:;
120
+ // if
121
+ if (dtypeswitch_tmp == 5) {
122
+ printf("%c", (int)(1.02e+2));
123
+ printf("%c", (int)(1.17e+2));
124
+ printf("%c", (int)(1.1e+2));
125
+ printf("%c", (int)(9.9e+1));
126
+ printf("%c", (int)(1.16e+2));
127
+ printf("%c", (int)(1.05e+2));
128
+ printf("%c", (int)(1.11e+2));
129
+ printf("%c", (int)(1.1e+2));
130
+ printf("%c", (int)(3.2e+1));
131
+ printf("%c", (int)(4e+1));
132
+ printf("%c", (int)(4.1e+1));
133
+ printf("%c", (int)(3.2e+1));
134
+ printf("%c", (int)(1.23e+2));
135
+ printf("%c", (int)(1.25e+2));
136
+ goto j0;
137
+ }
138
+ // end
139
+ j9:;
140
+ printf("%g\n", x);
141
+ // end
142
+ j0:;
143
+ printf("%c", (int)(1e+1));
144
+ }
145
+
146
+ int main() {
147
+ memcpy(_memory + 0, (unsigned char[]){13,0,0,0,72,0,101,0,108,0,108,0,111,0,44,0,32,0,87,0,111,0,114,0,108,0,100,0,33,0}, 30);
148
+
149
+ __console_log(0e+0, 2);
150
+
151
+ return 0;
152
+ }
@@ -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,4 +0,0 @@
1
- var supreme = 5
2
- var count;
3
-
4
- for(count=0;;) {console.log(count); if (count===supreme)break;else count++; }