porffor 0.2.0-fde989a → 0.2.0-fdf0fc5

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.
Files changed (58) hide show
  1. package/CONTRIBUTING.md +256 -0
  2. package/LICENSE +20 -20
  3. package/README.md +123 -85
  4. package/asur/README.md +2 -0
  5. package/asur/index.js +1262 -0
  6. package/byg/index.js +237 -0
  7. package/compiler/2c.js +1 -1
  8. package/compiler/{sections.js → assemble.js} +63 -15
  9. package/compiler/builtins/annexb_string.js +72 -0
  10. package/compiler/builtins/annexb_string.ts +18 -0
  11. package/compiler/builtins/array.ts +149 -0
  12. package/compiler/builtins/base64.ts +76 -0
  13. package/compiler/builtins/boolean.ts +20 -0
  14. package/compiler/builtins/crypto.ts +120 -0
  15. package/compiler/builtins/date.ts +2070 -0
  16. package/compiler/builtins/escape.ts +141 -0
  17. package/compiler/builtins/function.ts +7 -0
  18. package/compiler/builtins/int.ts +147 -0
  19. package/compiler/builtins/number.ts +534 -0
  20. package/compiler/builtins/object.ts +6 -0
  21. package/compiler/builtins/porffor.d.ts +59 -0
  22. package/compiler/builtins/set.ts +5 -0
  23. package/compiler/builtins/string.ts +1080 -0
  24. package/compiler/builtins.js +435 -279
  25. package/compiler/{codeGen.js → codegen.js} +1034 -404
  26. package/compiler/decompile.js +0 -1
  27. package/compiler/embedding.js +22 -22
  28. package/compiler/encoding.js +108 -10
  29. package/compiler/generated_builtins.js +1526 -0
  30. package/compiler/index.js +25 -34
  31. package/compiler/log.js +6 -3
  32. package/compiler/opt.js +50 -36
  33. package/compiler/parse.js +33 -23
  34. package/compiler/precompile.js +128 -0
  35. package/compiler/prefs.js +27 -0
  36. package/compiler/prototype.js +27 -42
  37. package/compiler/types.js +38 -0
  38. package/compiler/wasmSpec.js +28 -8
  39. package/compiler/wrap.js +51 -46
  40. package/package.json +9 -5
  41. package/porf +2 -0
  42. package/rhemyn/compile.js +46 -27
  43. package/rhemyn/parse.js +322 -320
  44. package/rhemyn/test/parse.js +58 -58
  45. package/runner/compare.js +34 -34
  46. package/runner/debug.js +122 -0
  47. package/runner/index.js +78 -11
  48. package/runner/profiler.js +102 -0
  49. package/runner/repl.js +42 -9
  50. package/runner/sizes.js +37 -37
  51. package/compiler/builtins/base64.js +0 -92
  52. package/filesize.cmd +0 -2
  53. package/runner/info.js +0 -89
  54. package/runner/profile.js +0 -46
  55. package/runner/results.json +0 -1
  56. package/runner/transform.js +0 -15
  57. package/tmp.c +0 -661
  58. package/util/enum.js +0 -20
@@ -110,7 +110,6 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
110
110
 
111
111
  out += '\n';
112
112
  lastInst = inst;
113
- i++;
114
113
  }
115
114
 
116
115
  return highlightAsm(out);
@@ -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
  ] ];
@@ -7,15 +7,22 @@ export const codifyString = str => {
7
7
  return out;
8
8
  };
9
9
 
10
- export const encodeString = str => [
11
- str.length,
12
- ...codifyString(str)
13
- ];
14
-
15
- export const encodeVector = data => [
16
- ...unsignedLEB128(data.length),
17
- ...data.flat()
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));