porffor 0.2.0-94ef1ca → 0.2.0-964b4c2
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/encoding.js +2 -116
- 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/encoding.js
CHANGED
@@ -105,119 +105,5 @@ export const read_unsignedLEB128 = _input => {
|
|
105
105
|
};
|
106
106
|
|
107
107
|
// ieee 754 binary64
|
108
|
-
|
109
|
-
|
110
|
-
// BSD 3-Clause. Copyright 2008 Fair Oaks Labs, Inc. (https://github.com/feross/ieee754/blob/master/LICENSE)
|
111
|
-
export const ieee754_binary64 = value => {
|
112
|
-
return [...new Uint8Array(new Float64Array([ value ]).buffer)];
|
113
|
-
|
114
|
-
let isLE = true, mLen = 52, nBytes = 8, offset = 0;
|
115
|
-
let buffer = new Array(nBytes).fill(0);
|
116
|
-
|
117
|
-
let e, m, c
|
118
|
-
let eLen = (nBytes * 8) - mLen - 1
|
119
|
-
const eMax = (1 << eLen) - 1
|
120
|
-
const eBias = eMax >> 1
|
121
|
-
const rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
122
|
-
let i = isLE ? 0 : (nBytes - 1)
|
123
|
-
const d = isLE ? 1 : -1
|
124
|
-
const s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
125
|
-
|
126
|
-
value = Math.abs(value)
|
127
|
-
|
128
|
-
if (isNaN(value) || value === Infinity) {
|
129
|
-
m = isNaN(value) ? 1 : 0
|
130
|
-
e = eMax
|
131
|
-
} else {
|
132
|
-
e = Math.floor(Math.log(value) / Math.LN2)
|
133
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
134
|
-
e--
|
135
|
-
c *= 2
|
136
|
-
}
|
137
|
-
if (e + eBias >= 1) {
|
138
|
-
value += rt / c
|
139
|
-
} else {
|
140
|
-
value += rt * Math.pow(2, 1 - eBias)
|
141
|
-
}
|
142
|
-
if (value * c >= 2) {
|
143
|
-
e++
|
144
|
-
c /= 2
|
145
|
-
}
|
146
|
-
|
147
|
-
if (e + eBias >= eMax) {
|
148
|
-
m = 0
|
149
|
-
e = eMax
|
150
|
-
} else if (e + eBias >= 1) {
|
151
|
-
m = ((value * c) - 1) * Math.pow(2, mLen)
|
152
|
-
e = e + eBias
|
153
|
-
} else {
|
154
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
155
|
-
e = 0
|
156
|
-
}
|
157
|
-
}
|
158
|
-
|
159
|
-
while (mLen >= 8) {
|
160
|
-
buffer[offset + i] = m & 0xff
|
161
|
-
i += d
|
162
|
-
m /= 256
|
163
|
-
mLen -= 8
|
164
|
-
}
|
165
|
-
|
166
|
-
e = (e << mLen) | m
|
167
|
-
eLen += mLen
|
168
|
-
while (eLen > 0) {
|
169
|
-
buffer[offset + i] = e & 0xff
|
170
|
-
i += d
|
171
|
-
e /= 256
|
172
|
-
eLen -= 8
|
173
|
-
}
|
174
|
-
|
175
|
-
buffer[offset + i - d] |= s * 128
|
176
|
-
|
177
|
-
return buffer;
|
178
|
-
};
|
179
|
-
|
180
|
-
export const read_ieee754_binary64 = buffer => {
|
181
|
-
return new Float64Array(new Uint8Array(buffer).buffer)[0];
|
182
|
-
|
183
|
-
let isLE = true, mLen = 52, nBytes = 8, offset = 0;
|
184
|
-
|
185
|
-
let e, m
|
186
|
-
const eLen = (nBytes * 8) - mLen - 1
|
187
|
-
const eMax = (1 << eLen) - 1
|
188
|
-
const eBias = eMax >> 1
|
189
|
-
let nBits = -7
|
190
|
-
let i = isLE ? (nBytes - 1) : 0
|
191
|
-
const d = isLE ? -1 : 1
|
192
|
-
let s = buffer[offset + i]
|
193
|
-
|
194
|
-
i += d
|
195
|
-
|
196
|
-
e = s & ((1 << (-nBits)) - 1)
|
197
|
-
s >>= (-nBits)
|
198
|
-
nBits += eLen
|
199
|
-
while (nBits > 0) {
|
200
|
-
e = (e * 256) + buffer[offset + i]
|
201
|
-
i += d
|
202
|
-
nBits -= 8
|
203
|
-
}
|
204
|
-
|
205
|
-
m = e & ((1 << (-nBits)) - 1)
|
206
|
-
e >>= (-nBits)
|
207
|
-
nBits += mLen
|
208
|
-
while (nBits > 0) {
|
209
|
-
m = (m * 256) + buffer[offset + i]
|
210
|
-
i += d
|
211
|
-
nBits -= 8
|
212
|
-
}
|
213
|
-
|
214
|
-
if (e === 0) {
|
215
|
-
e = 1 - eBias
|
216
|
-
} else if (e === eMax) {
|
217
|
-
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
218
|
-
} else {
|
219
|
-
m = m + Math.pow(2, mLen)
|
220
|
-
e = e - eBias
|
221
|
-
}
|
222
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
223
|
-
};
|
108
|
+
export const ieee754_binary64 = value => [...new Uint8Array(new Float64Array([ value ]).buffer)];
|
109
|
+
export const read_ieee754_binary64 = buffer => new Float64Array(new Uint8Array(buffer).buffer)[0];
|
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
|
+
|