porffor 0.2.0-fde989a → 0.14.0-4057a18e9

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