porffor 0.2.0-fde989a → 0.14.0-032e4ad08

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