porffor 0.2.0-a759814 → 0.2.0-a910bd0

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/CONTRIBUTING.md +256 -0
  2. package/LICENSE +20 -20
  3. package/README.md +156 -87
  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 +317 -72
  8. package/compiler/{sections.js → assemble.js} +64 -16
  9. package/compiler/builtins/annexb_string.js +72 -0
  10. package/compiler/builtins/annexb_string.ts +18 -0
  11. package/compiler/builtins/array.ts +147 -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 +2069 -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 +531 -0
  20. package/compiler/builtins/object.ts +6 -0
  21. package/compiler/builtins/porffor.d.ts +60 -0
  22. package/compiler/builtins/set.ts +190 -0
  23. package/compiler/builtins/string.ts +1080 -0
  24. package/compiler/builtins.js +580 -272
  25. package/compiler/{codeGen.js → codegen.js} +1311 -467
  26. package/compiler/decompile.js +3 -4
  27. package/compiler/embedding.js +22 -22
  28. package/compiler/encoding.js +108 -10
  29. package/compiler/generated_builtins.js +1625 -0
  30. package/compiler/index.js +36 -34
  31. package/compiler/log.js +6 -3
  32. package/compiler/opt.js +57 -31
  33. package/compiler/parse.js +33 -23
  34. package/compiler/precompile.js +120 -0
  35. package/compiler/prefs.js +27 -0
  36. package/compiler/prototype.js +182 -42
  37. package/compiler/types.js +38 -0
  38. package/compiler/wasmSpec.js +31 -7
  39. package/compiler/wrap.js +176 -65
  40. package/package.json +9 -5
  41. package/porf +4 -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 +91 -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/runner/info.js +0 -89
  53. package/runner/profile.js +0 -46
  54. package/runner/results.json +0 -1
  55. package/runner/transform.js +0 -15
  56. package/util/enum.js +0 -20
@@ -0,0 +1,190 @@
1
+ // @porf --funsafe-no-unlikely-proto-checks
2
+
3
+ // dark wasm magic for dealing with memory, sorry.
4
+ export const __Porffor_allocate = (): number => {
5
+ Porffor.wasm`i32.const 1
6
+ memory.grow 0
7
+ drop
8
+ memory.size 0
9
+ i32.const 1
10
+ i32.sub
11
+ i32.const 65536
12
+ i32.mul
13
+ i32.from_u
14
+ return`;
15
+ };
16
+
17
+ export const __Porffor_set_read = (_this: Set, index: number): any => {
18
+ Porffor.wasm`
19
+ local offset i32
20
+ local.get ${index}
21
+ i32.to_u
22
+ i32.const 9
23
+ i32.mul
24
+ local.get ${_this}
25
+ i32.to_u
26
+ i32.add
27
+ local.set offset
28
+
29
+ local.get offset
30
+ f64.load 0 4
31
+
32
+ local.get offset
33
+ i32.load8_u 0 12
34
+ return`;
35
+ };
36
+
37
+ export const __Porffor_set_write = (_this: Set, index: number, value: any): boolean => {
38
+ Porffor.wasm`
39
+ local offset i32
40
+ local.get ${index}
41
+ i32.to_u
42
+ i32.const 9
43
+ i32.mul
44
+ local.get ${_this}
45
+ i32.to_u
46
+ i32.add
47
+ local.set offset
48
+
49
+ local.get offset
50
+ local.get ${value}
51
+ f64.store 0 4
52
+
53
+ local.get offset
54
+ local.get ${value+1}
55
+ i32.store8 0 12`;
56
+
57
+ return true;
58
+ };
59
+
60
+
61
+ // todo: this should be a getter somehow not a method
62
+ export const __Set_prototype_size = (_this: Set) => {
63
+ return Porffor.wasm.i32.load(_this, 0, 0);
64
+ };
65
+
66
+ export const __Set_prototype_values = (_this: Set) => {
67
+ // todo: this should return an iterator not array
68
+ const size: number = __Set_prototype_size(_this);
69
+
70
+ const out: any[] = __Porffor_allocate();
71
+ for (let i: number = 0; i < size; i++) {
72
+ const val: any = __Porffor_set_read(_this, i);
73
+ out.push(val);
74
+ }
75
+
76
+ return out;
77
+ };
78
+
79
+ export const __Set_prototype_keys = (_this: Set) => {
80
+ return __Set_prototype_values(_this);
81
+ };
82
+
83
+ export const __Set_prototype_has = (_this: Set, value: any) => {
84
+ const size: number = __Set_prototype_size(_this);
85
+
86
+ for (let i: number = 0; i < size; i++) {
87
+ if (__Porffor_set_read(_this, i) === value) return true;
88
+ }
89
+
90
+ return false;
91
+ };
92
+
93
+ export const __Set_prototype_add = (_this: Set, value: any) => {
94
+ const size: number = __Set_prototype_size(_this);
95
+
96
+ // check if already in set
97
+ for (let i: number = 0; i < size; i++) {
98
+ if (__Porffor_set_read(_this, i) === value) return _this;
99
+ }
100
+
101
+ // not, add it
102
+ // increment size by 1
103
+ Porffor.wasm.i32.store(_this, size + 1, 0, 0);
104
+
105
+ // write new value at end
106
+ __Porffor_set_write(_this, size, value);
107
+
108
+ return _this;
109
+ };
110
+
111
+ export const __Set_prototype_delete = (_this: Set, value: any) => {
112
+ const size: number = __Set_prototype_size(_this);
113
+
114
+ // check if already in set
115
+ for (let i: number = 0; i < size; i++) {
116
+ if (__Porffor_set_read(_this, i) === value) {
117
+ // found, remove
118
+ // decrement size by 1
119
+ Porffor.wasm.i32.store(_this, size - 1, 0, 0);
120
+
121
+ // offset all elements after by -1 ind
122
+ Porffor.wasm`
123
+ local offset i32
124
+ local.get ${i}
125
+ i32.to_u
126
+ i32.const 9
127
+ i32.mul
128
+ local.get ${_this}
129
+ i32.to_u
130
+ i32.add
131
+ i32.const 4
132
+ i32.add
133
+ local.set offset
134
+
135
+ ;; dst = offset (this element)
136
+ local.get offset
137
+
138
+ ;; src = offset + 9 (this element + 1 element)
139
+ local.get offset
140
+ i32.const 9
141
+ i32.add
142
+
143
+ ;; size = (size - i - 1) * 9
144
+ local.get ${size}
145
+ local.get ${i}
146
+ f64.sub
147
+ i32.to_u
148
+ i32.const 1
149
+ i32.sub
150
+ i32.const 9
151
+ i32.mul
152
+
153
+ memory.copy 0 0
154
+ `;
155
+
156
+ return true;
157
+ }
158
+ }
159
+
160
+ // not, return false
161
+ return false;
162
+ };
163
+
164
+ export const __Set_prototype_clear = (_this: Set) => {
165
+ // just set size to 0
166
+ // do not need to remove as will not be accessed anymore,
167
+ // and will be overwritten with new add
168
+ Porffor.wasm.i32.store(_this, 0, 0, 0);
169
+ };
170
+
171
+ export const Set = () => {
172
+ throw new TypeError("Constructor Set requires 'new'");
173
+ };
174
+
175
+ export const Set$constructor = (iterable: any): Set => {
176
+ const out: Set = __Porffor_allocate();
177
+
178
+ const type: number = Porffor.rawType(iterable);
179
+ if (Porffor.fastOr(
180
+ type == Porffor.TYPES.array,
181
+ type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
182
+ type == Porffor.TYPES.set
183
+ )) {
184
+ for (const x of iterable) {
185
+ __Set_prototype_add(out, x);
186
+ }
187
+ }
188
+
189
+ return out;
190
+ };