porffor 0.2.0-eaee2da → 0.2.0-ef043de
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/LICENSE +20 -20
- package/README.md +159 -88
- package/asur/README.md +2 -0
- package/asur/index.js +1262 -0
- package/byg/index.js +237 -0
- package/compiler/2c.js +317 -72
- package/compiler/{sections.js → assemble.js} +63 -15
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +19 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +151 -0
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/date.ts +1370 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/int.ts +147 -0
- package/compiler/builtins/number.ts +527 -0
- package/compiler/builtins/porffor.d.ts +42 -0
- package/compiler/builtins/string.ts +1055 -0
- package/compiler/builtins/tostring.ts +45 -0
- package/compiler/builtins.js +470 -269
- package/compiler/{codeGen.js → codegen.js} +999 -378
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +1262 -0
- package/compiler/index.js +36 -34
- package/compiler/log.js +6 -3
- package/compiler/opt.js +51 -36
- package/compiler/parse.js +35 -27
- package/compiler/precompile.js +123 -0
- package/compiler/prefs.js +26 -0
- package/compiler/prototype.js +13 -28
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +28 -8
- package/compiler/wrap.js +54 -46
- package/fib.js +7 -0
- package/package.json +9 -5
- package/porf +4 -0
- package/rhemyn/compile.js +5 -3
- package/rhemyn/parse.js +323 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +34 -34
- package/runner/debug.js +122 -0
- package/runner/index.js +62 -10
- package/runner/profiler.js +102 -0
- package/runner/repl.js +40 -7
- package/runner/sizes.js +37 -37
- package/compiler/builtins/base64.js +0 -92
- package/runner/info.js +0 -89
- package/runner/profile.js +0 -46
- package/runner/results.json +0 -1
- package/runner/transform.js +0 -15
- package/util/enum.js +0 -20
package/compiler/embedding.js
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
import { Opcodes, Valtype } from "./wasmSpec.js";
|
2
|
-
import { signedLEB128, ieee754_binary64 } from "./encoding.js";
|
3
|
-
|
4
|
-
export const number = (n, valtype = valtypeBinary) => {
|
5
|
-
switch (valtype) {
|
6
|
-
case Valtype.i32: return [ [ Opcodes.i32_const, ...signedLEB128(n) ] ];
|
7
|
-
case Valtype.i64: return [ [ Opcodes.i64_const, ...signedLEB128(n) ] ];
|
8
|
-
case Valtype.f64: return [ [ Opcodes.f64_const, ...ieee754_binary64(n) ] ];
|
9
|
-
}
|
10
|
-
};
|
11
|
-
|
12
|
-
export const enforceOneByte = arr => [ arr[0] ?? 0 ];
|
13
|
-
export const enforceTwoBytes = arr => [ arr[0] ?? 0, arr[1] ?? 0 ];
|
14
|
-
export const enforceFourBytes = arr => [ arr[0] ?? 0, arr[1] ?? 0, arr[2] ?? 0, arr[3] ?? 0 ];
|
15
|
-
export const enforceEightBytes = arr => [ arr[0] ?? 0, arr[1] ?? 0, arr[2] ?? 0, arr[3] ?? 0, arr[4] ?? 0, arr[5] ?? 0, arr[6] ?? 0, arr[7] ?? 0 ];
|
16
|
-
|
17
|
-
export const i32x4 = (a, b, c, d) => [ [
|
18
|
-
...Opcodes.v128_const,
|
19
|
-
...enforceFourBytes(signedLEB128(a)),
|
20
|
-
...enforceFourBytes(signedLEB128(b)),
|
21
|
-
...enforceFourBytes(signedLEB128(c)),
|
22
|
-
...enforceFourBytes(signedLEB128(d))
|
1
|
+
import { Opcodes, Valtype } from "./wasmSpec.js";
|
2
|
+
import { signedLEB128, ieee754_binary64 } from "./encoding.js";
|
3
|
+
|
4
|
+
export const number = (n, valtype = valtypeBinary) => {
|
5
|
+
switch (valtype) {
|
6
|
+
case Valtype.i32: return [ [ Opcodes.i32_const, ...signedLEB128(n) ] ];
|
7
|
+
case Valtype.i64: return [ [ Opcodes.i64_const, ...signedLEB128(n) ] ];
|
8
|
+
case Valtype.f64: return [ [ Opcodes.f64_const, ...ieee754_binary64(n) ] ];
|
9
|
+
}
|
10
|
+
};
|
11
|
+
|
12
|
+
export const enforceOneByte = arr => [ arr[0] ?? 0 ];
|
13
|
+
export const enforceTwoBytes = arr => [ arr[0] ?? 0, arr[1] ?? 0 ];
|
14
|
+
export const enforceFourBytes = arr => [ arr[0] ?? 0, arr[1] ?? 0, arr[2] ?? 0, arr[3] ?? 0 ];
|
15
|
+
export const enforceEightBytes = arr => [ arr[0] ?? 0, arr[1] ?? 0, arr[2] ?? 0, arr[3] ?? 0, arr[4] ?? 0, arr[5] ?? 0, arr[6] ?? 0, arr[7] ?? 0 ];
|
16
|
+
|
17
|
+
export const i32x4 = (a, b, c, d) => [ [
|
18
|
+
...Opcodes.v128_const,
|
19
|
+
...enforceFourBytes(signedLEB128(a)),
|
20
|
+
...enforceFourBytes(signedLEB128(b)),
|
21
|
+
...enforceFourBytes(signedLEB128(c)),
|
22
|
+
...enforceFourBytes(signedLEB128(d))
|
23
23
|
] ];
|
package/compiler/encoding.js
CHANGED
@@ -7,15 +7,22 @@ export const codifyString = str => {
|
|
7
7
|
return out;
|
8
8
|
};
|
9
9
|
|
10
|
-
export const encodeString = str => [
|
11
|
-
|
12
|
-
|
13
|
-
];
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
// export const encodeString = str => [
|
11
|
+
// str.length,
|
12
|
+
// ...codifyString(str)
|
13
|
+
// ];
|
14
|
+
export const encodeString = str => unsignedLEB128(str.length).concat(codifyString(str));
|
15
|
+
|
16
|
+
// export const encodeVector = data => [
|
17
|
+
// ...unsignedLEB128(data.length),
|
18
|
+
// ...data.flat()
|
19
|
+
// ];
|
20
|
+
// export const encodeVector = data => {
|
21
|
+
// const out = data.flat();
|
22
|
+
// out.unshift.apply(out, unsignedLEB128(data.length));
|
23
|
+
// return out;
|
24
|
+
// };
|
25
|
+
export const encodeVector = data => unsignedLEB128(data.length).concat(data.flat());
|
19
26
|
|
20
27
|
export const encodeLocal = (count, type) => [
|
21
28
|
...unsignedLEB128(count),
|
@@ -24,6 +31,8 @@ export const encodeLocal = (count, type) => [
|
|
24
31
|
|
25
32
|
// todo: this only works with integers within 32 bit range
|
26
33
|
export const signedLEB128 = n => {
|
34
|
+
if (typeof n === 'bigint') return big_signedLEB128(n);
|
35
|
+
|
27
36
|
n |= 0;
|
28
37
|
|
29
38
|
// just input for small numbers (for perf as common)
|
@@ -50,6 +59,8 @@ export const signedLEB128 = n => {
|
|
50
59
|
};
|
51
60
|
|
52
61
|
export const unsignedLEB128 = n => {
|
62
|
+
if (typeof n === 'bigint') return big_unsignedLEB128(n);
|
63
|
+
|
53
64
|
n |= 0;
|
54
65
|
|
55
66
|
// just input for small numbers (for perf as common)
|
@@ -67,6 +78,46 @@ export const unsignedLEB128 = n => {
|
|
67
78
|
return buffer;
|
68
79
|
};
|
69
80
|
|
81
|
+
export const big_signedLEB128 = n => {
|
82
|
+
// just input for small numbers (for perf as common)
|
83
|
+
if (n >= 0n && n <= 63n) return [ Number(n) ];
|
84
|
+
if (n >= -64n && n <= 0n) return [ 128 + Number(n) ];
|
85
|
+
|
86
|
+
const buffer = [];
|
87
|
+
|
88
|
+
while (true) {
|
89
|
+
let byte = Number(n & 0x7fn);
|
90
|
+
n >>= 7n;
|
91
|
+
|
92
|
+
if ((n === 0n && (byte & 0x40) === 0) || (n === -1n && (byte & 0x40) !== 0)) {
|
93
|
+
buffer.push(byte);
|
94
|
+
break;
|
95
|
+
} else {
|
96
|
+
byte |= 0x80n;
|
97
|
+
}
|
98
|
+
|
99
|
+
buffer.push(byte);
|
100
|
+
}
|
101
|
+
|
102
|
+
return buffer;
|
103
|
+
};
|
104
|
+
|
105
|
+
export const big_unsignedLEB128 = n => {
|
106
|
+
// just input for small numbers (for perf as common)
|
107
|
+
if (n >= 0n && n <= 127n) return [ n ];
|
108
|
+
|
109
|
+
const buffer = [];
|
110
|
+
do {
|
111
|
+
let byte = Number(n & 0x7fn);
|
112
|
+
n >>>= 7n;
|
113
|
+
if (n !== 0n) {
|
114
|
+
byte |= 0x80;
|
115
|
+
}
|
116
|
+
buffer.push(byte);
|
117
|
+
} while (n !== 0n);
|
118
|
+
return buffer;
|
119
|
+
};
|
120
|
+
|
70
121
|
export const read_signedLEB128 = _input => {
|
71
122
|
const input = [..._input];
|
72
123
|
let result = 0, shift = 0;
|
@@ -105,5 +156,52 @@ export const read_unsignedLEB128 = _input => {
|
|
105
156
|
};
|
106
157
|
|
107
158
|
// ieee 754 binary64
|
159
|
+
// const ieee754Cache = {};
|
160
|
+
// export const ieee754_binary64 = value => {
|
161
|
+
// if (ieee754Cache[value]) return ieee754Cache[value];
|
162
|
+
// return ieee754Cache[value] = [...new Uint8Array(new Float64Array([ value ]).buffer)];
|
163
|
+
// };
|
108
164
|
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];
|
165
|
+
export const read_ieee754_binary64 = buffer => new Float64Array(new Uint8Array(buffer).buffer)[0];
|
166
|
+
|
167
|
+
|
168
|
+
// into funcs append to a given existing buffer instead of creating our own for perf
|
169
|
+
export const signedLEB128_into = (n, buffer) => {
|
170
|
+
n |= 0;
|
171
|
+
|
172
|
+
// just input for small numbers (for perf as common)
|
173
|
+
if (n >= 0 && n <= 63) return buffer.push(n);
|
174
|
+
if (n >= -64 && n <= 0) return buffer.push(128 + n);
|
175
|
+
|
176
|
+
while (true) {
|
177
|
+
let byte = n & 0x7f;
|
178
|
+
n >>= 7;
|
179
|
+
|
180
|
+
if ((n === 0 && (byte & 0x40) === 0) || (n === -1 && (byte & 0x40) !== 0)) {
|
181
|
+
buffer.push(byte);
|
182
|
+
break;
|
183
|
+
} else {
|
184
|
+
byte |= 0x80;
|
185
|
+
}
|
186
|
+
|
187
|
+
buffer.push(byte);
|
188
|
+
}
|
189
|
+
};
|
190
|
+
|
191
|
+
export const unsignedLEB128_into = (n, buffer) => {
|
192
|
+
n |= 0;
|
193
|
+
|
194
|
+
// just input for small numbers (for perf as common)
|
195
|
+
if (n >= 0 && n <= 127) return buffer.push(n);
|
196
|
+
|
197
|
+
do {
|
198
|
+
let byte = n & 0x7f;
|
199
|
+
n >>>= 7;
|
200
|
+
if (n !== 0) {
|
201
|
+
byte |= 0x80;
|
202
|
+
}
|
203
|
+
buffer.push(byte);
|
204
|
+
} while (n !== 0);
|
205
|
+
};
|
206
|
+
|
207
|
+
export const ieee754_binary64_into = (value, buffer) => buffer.push(...new Uint8Array(new Float64Array([ value ]).buffer));
|