porffor 0.2.0-c7b7423 → 0.2.0-dcc06c8
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/README.md +89 -47
- package/compiler/2c.js +321 -71
- package/compiler/builtins/base64.ts +88 -0
- package/compiler/builtins/porffor.d.ts +10 -0
- package/compiler/builtins.js +178 -60
- package/compiler/codeGen.js +537 -271
- package/compiler/decompile.js +3 -3
- package/compiler/encoding.js +2 -116
- package/compiler/generated_builtins.js +3 -0
- package/compiler/index.js +22 -22
- package/compiler/opt.js +61 -26
- package/compiler/parse.js +13 -12
- package/compiler/precompile.js +79 -0
- package/compiler/prefs.js +22 -0
- package/compiler/prototype.js +176 -20
- package/compiler/sections.js +8 -7
- package/compiler/wasmSpec.js +6 -2
- package/compiler/wrap.js +103 -9
- package/demo.js +3 -0
- package/demo.ts +1 -0
- package/filesize.cmd +2 -0
- package/hello +0 -0
- package/package.json +1 -1
- package/porf +2 -0
- package/rhemyn/compile.js +2 -1
- package/runner/index.js +20 -3
- package/runner/repl.js +2 -2
- package/tmp.c +136 -53
- package/compiler/builtins/base64.js +0 -92
package/tmp.c
CHANGED
@@ -1,69 +1,152 @@
|
|
1
|
-
|
1
|
+
#include <stdint.h>
|
2
|
+
#include <string.h>
|
2
3
|
#include <stdio.h>
|
3
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
|
+
|
4
16
|
struct ReturnValue {
|
5
|
-
|
6
|
-
|
17
|
+
f64 value;
|
18
|
+
i32 type;
|
7
19
|
};
|
8
20
|
|
9
|
-
|
10
|
-
long sumdtype = 0;
|
11
|
-
double counter = 0;
|
12
|
-
long counterdtype = 0;
|
21
|
+
char _memory[65536];
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
i32 i32_load(i32 align, i32 offset, i32 pointer) {
|
24
|
+
i32 out;
|
25
|
+
memcpy(&out, _memory + offset + pointer, sizeof(out));
|
26
|
+
return out;
|
16
27
|
}
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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 };
|
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;
|
42
33
|
}
|
43
34
|
|
44
|
-
|
45
|
-
|
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:;
|
46
143
|
printf("%c", (int)(1e+1));
|
47
144
|
}
|
48
145
|
|
49
146
|
int main() {
|
50
|
-
|
51
|
-
double elogicinner_tmp = 0;
|
52
|
-
long dtypeswitch_tmp = 0;
|
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);
|
53
148
|
|
54
|
-
|
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
|
-
}
|
149
|
+
__console_log(0e+0, 2);
|
69
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
|
-
};
|