porffor 0.2.0-94ef1ca → 0.2.0-c7b7423
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/2c.js +4 -1
- package/compiler/decompile.js +9 -10
- package/compiler/index.js +4 -0
- package/package.json +1 -1
- package/tmp.c +69 -0
package/compiler/2c.js
CHANGED
@@ -35,7 +35,10 @@ const todo = msg => {
|
|
35
35
|
throw new TodoError(`todo: ${msg}`);
|
36
36
|
};
|
37
37
|
|
38
|
-
const removeBrackets = str =>
|
38
|
+
const removeBrackets = str => {
|
39
|
+
if (str.startsWith('(long)(unsigned long)')) return '(long)(unsigned long)(' + removeBrackets(str.slice(22, -1)) + ')';
|
40
|
+
return str.startsWith('(') && str.endsWith(')') ? str.slice(1, -1) : str;
|
41
|
+
};
|
39
42
|
|
40
43
|
export default ({ funcs, globals, tags, exceptions, pages }) => {
|
41
44
|
const invOperatorOpcode = Object.values(operatorOpcode).reduce((acc, x) => {
|
package/compiler/decompile.js
CHANGED
@@ -116,13 +116,12 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
116
116
|
return highlightAsm(out);
|
117
117
|
};
|
118
118
|
|
119
|
-
export const highlightAsm = asm =>
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
.replace(/ ;;.*$/gm, _ => `\x1B[90m${_.replaceAll(/\x1B\[[0-9]+m/g, '')}\x1B[0m`);
|
119
|
+
export const highlightAsm = asm => asm
|
120
|
+
.replace(/(local|global|memory)\.[^\s]*/g, _ => `\x1B[31m${_}\x1B[0m`)
|
121
|
+
.replace(/(i(8|16|32|64)x[0-9]+|v128)(\.[^\s]*)?/g, _ => `\x1B[34m${_}\x1B[0m`)
|
122
|
+
.replace(/[^m](i32|i64|f32|f64|drop)(\.[^\s]*)?/g, _ => `${_[0]}\x1B[36m${_.slice(1)}\x1B[0m`)
|
123
|
+
.replace(/(return_call|call|br_if|br|return|rethrow|throw)/g, _ => `\x1B[35m${_}\x1B[0m`)
|
124
|
+
.replace(/(block|loop|if|end|else|try|catch_all|catch|delegate)/g, _ => `\x1B[95m${_}\x1B[0m`)
|
125
|
+
.replace(/unreachable/g, _ => `\x1B[91m${_}\x1B[0m`)
|
126
|
+
.replace(/ \-?[0-9\.]+/g, _ => ` \x1B[33m${_.slice(1)}\x1B[0m`)
|
127
|
+
.replace(/ ;;.*$/gm, _ => `\x1B[90m${_.replaceAll(/\x1B\[[0-9]+m/g, '')}\x1B[0m`);
|
package/compiler/index.js
CHANGED
@@ -82,6 +82,8 @@ export default (code, flags) => {
|
|
82
82
|
} else {
|
83
83
|
console.log(c);
|
84
84
|
}
|
85
|
+
|
86
|
+
if (process.version) process.exit();
|
85
87
|
}
|
86
88
|
|
87
89
|
if (target === 'native') {
|
@@ -96,6 +98,8 @@ export default (code, flags) => {
|
|
96
98
|
|
97
99
|
// obvious command escape is obvious
|
98
100
|
execSync(args.join(' '), { stdio: 'inherit' });
|
101
|
+
|
102
|
+
if (process.version) process.exit();
|
99
103
|
}
|
100
104
|
|
101
105
|
return out;
|
package/package.json
CHANGED
package/tmp.c
ADDED
@@ -0,0 +1,69 @@
|
|
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
|
+
|