porffor 0.2.0-dcc06c8 → 0.2.0-de394c3

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 (56) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +113 -62
  3. package/asur/README.md +2 -0
  4. package/asur/index.js +1262 -0
  5. package/byg/index.js +237 -0
  6. package/compiler/2c.js +1 -1
  7. package/compiler/{sections.js → assemble.js} +58 -11
  8. package/compiler/builtins/annexb_string.js +72 -0
  9. package/compiler/builtins/annexb_string.ts +19 -0
  10. package/compiler/builtins/array.ts +145 -0
  11. package/compiler/builtins/base64.ts +103 -40
  12. package/compiler/builtins/crypto.ts +120 -0
  13. package/compiler/builtins/date.ts +1370 -0
  14. package/compiler/builtins/escape.ts +141 -0
  15. package/compiler/builtins/int.ts +147 -0
  16. package/compiler/builtins/number.ts +527 -0
  17. package/compiler/builtins/porffor.d.ts +33 -1
  18. package/compiler/builtins/string.ts +1055 -0
  19. package/compiler/builtins/tostring.ts +45 -0
  20. package/compiler/builtins.js +454 -243
  21. package/compiler/{codeGen.js → codegen.js} +833 -290
  22. package/compiler/embedding.js +22 -22
  23. package/compiler/encoding.js +108 -10
  24. package/compiler/generated_builtins.js +1259 -0
  25. package/compiler/index.js +16 -14
  26. package/compiler/log.js +6 -3
  27. package/compiler/opt.js +23 -22
  28. package/compiler/parse.js +31 -25
  29. package/compiler/precompile.js +66 -22
  30. package/compiler/prefs.js +5 -1
  31. package/compiler/prototype.js +4 -20
  32. package/compiler/types.js +37 -0
  33. package/compiler/wasmSpec.js +28 -8
  34. package/compiler/wrap.js +51 -47
  35. package/fib.js +7 -0
  36. package/package.json +9 -5
  37. package/porf +2 -0
  38. package/rhemyn/compile.js +3 -2
  39. package/rhemyn/parse.js +323 -320
  40. package/rhemyn/test/parse.js +58 -58
  41. package/runner/compare.js +34 -34
  42. package/runner/debug.js +122 -0
  43. package/runner/index.js +48 -9
  44. package/runner/profiler.js +102 -0
  45. package/runner/repl.js +40 -7
  46. package/runner/sizes.js +37 -37
  47. package/demo.js +0 -3
  48. package/demo.ts +0 -1
  49. package/filesize.cmd +0 -2
  50. package/hello +0 -0
  51. package/runner/info.js +0 -89
  52. package/runner/profile.js +0 -46
  53. package/runner/results.json +0 -1
  54. package/runner/transform.js +0 -15
  55. package/tmp.c +0 -152
  56. package/util/enum.js +0 -20
@@ -1,15 +0,0 @@
1
- import compile from '../compiler/wrap.js';
2
- import fs from 'node:fs';
3
-
4
- const file = process.argv.slice(2).find(x => x[0] !== '-');
5
-
6
- const source = fs.readFileSync(file, 'utf8');
7
-
8
- const { wasm } = await compile(source);
9
-
10
- // const out = `(async () => { const print = str => process.stdout.write(str); (await WebAssembly.instantiate(Uint8Array.from([${wasm.toString()}]), {'': { p: i => print(i.toString()), c: i => print(String.fromCharCode(i))}})).instance.exports.m()})()`;
11
- // const out = `new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([${wasm.toString()}])),{'':{p:i=>process.stdout.write(i.toString())}}).exports.m()`;
12
- const out = `const a=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([${wasm.toString()}])));const b=a.exports.m();console.log(Array.from(new Uint16Array(a.exports.$.buffer,b+4,new Int32Array(a.exports.$.buffer,b,1))).map(x=>String.fromCharCode(x)).join(''))`;
13
-
14
- console.log(out);
15
- eval(out);
package/tmp.c DELETED
@@ -1,152 +0,0 @@
1
- #include <stdint.h>
2
- #include <string.h>
3
- #include <stdio.h>
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
-
16
- struct ReturnValue {
17
- f64 value;
18
- i32 type;
19
- };
20
-
21
- char _memory[65536];
22
-
23
- i32 i32_load(i32 align, i32 offset, i32 pointer) {
24
- i32 out;
25
- memcpy(&out, _memory + offset + pointer, sizeof(out));
26
- return out;
27
- }
28
-
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;
33
- }
34
-
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:;
143
- printf("%c", (int)(1e+1));
144
- }
145
-
146
- int main() {
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);
148
-
149
- __console_log(0e+0, 2);
150
-
151
- return 0;
152
- }
package/util/enum.js DELETED
@@ -1,20 +0,0 @@
1
- export const enumify = (...args) => {
2
- const obj = {};
3
-
4
- for (let i = 0; i < args.length; i++) {
5
- obj[i] = args[i];
6
- obj[args[i]] = i;
7
- }
8
-
9
- return obj;
10
- };
11
-
12
- // a procedural enum ;)
13
- export const procEnum = () => {
14
- let n = 0;
15
- return new Proxy({}, {
16
- get(target, p) {
17
- return target[p] ?? (target[p] = n++);
18
- }
19
- });
20
- };