porffor 0.17.0-c2af76d41 → 0.17.0-c2dd8f88f

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.
@@ -119,7 +119,7 @@ ${funcs.map(x => {
119
119
  locals: ${JSON.stringify(Object.values(x.locals).slice(x.params.length).map(x => x.type))},
120
120
  localNames: ${JSON.stringify(Object.keys(x.locals))},
121
121
  ${x.data && x.data.length > 0 ? ` data: ${JSON.stringify(x.data)},` : ''}
122
- ${x.table ? ` table: true` : ''}
122
+ ${x.table ? ` table: true,` : ''}${x.constr ? ` constr: true,` : ''}
123
123
  };`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n');
124
124
  }).join('\n')}
125
125
  };`;
@@ -208,72 +208,6 @@ export const PrototypeFuncs = function() {
208
208
  // ...number(1, Valtype.i32),
209
209
  // [ Opcodes.i32_sub ]
210
210
  // ]),
211
- ],
212
-
213
- fill: (pointer, length, wElement, wType, iTmp, iTmp2) => [
214
- ...wElement,
215
- [ Opcodes.local_set, iTmp ],
216
-
217
- // use cached length i32 as pointer
218
- ...length.getCachedI32(),
219
-
220
- // length - 1 for indexes
221
- ...number(1, Valtype.i32),
222
- [ Opcodes.i32_sub ],
223
-
224
- // * sizeof value
225
- ...number(ValtypeSize[valtype] + 1, Valtype.i32),
226
- [ Opcodes.i32_mul ],
227
-
228
- ...length.setCachedI32(),
229
-
230
- ...(noUnlikelyChecks ? [] : [
231
- ...length.getCachedI32(),
232
- ...number(0, Valtype.i32),
233
- [ Opcodes.i32_lt_s ],
234
- [ Opcodes.if, Blocktype.void ],
235
- ...pointer,
236
- Opcodes.i32_from_u,
237
- [ Opcodes.br, 1 ],
238
- [ Opcodes.end ]
239
- ]),
240
-
241
- [ Opcodes.loop, Blocktype.void ],
242
-
243
- // calculate offset
244
- ...length.getCachedI32(),
245
- ...pointer,
246
- [ Opcodes.i32_add ],
247
- [ Opcodes.local_set, iTmp2 ],
248
-
249
- // store value
250
- [ Opcodes.local_get, iTmp2 ],
251
- [ Opcodes.local_get, iTmp ],
252
- [ Opcodes.store, 0, ValtypeSize.i32 ],
253
-
254
- // store type
255
- [ Opcodes.local_get, iTmp2 ],
256
- ...wType,
257
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
258
-
259
- // pointer - sizeof value
260
- ...length.getCachedI32(),
261
- ...number(ValtypeSize[valtype] + 1, Valtype.i32),
262
- [ Opcodes.i32_sub ],
263
-
264
- ...length.setCachedI32(),
265
-
266
- // if pointer >= 0, loop
267
- ...length.getCachedI32(),
268
- ...number(0, Valtype.i32),
269
- [ Opcodes.i32_ge_s ],
270
- [ Opcodes.br_if, 0 ],
271
-
272
- [ Opcodes.end ],
273
-
274
- // return this array
275
- ...pointer,
276
- Opcodes.i32_from_u,
277
211
  ]
278
212
  };
279
213
 
@@ -282,9 +216,6 @@ export const PrototypeFuncs = function() {
282
216
  this[TYPES.array].push.noArgRetLength = true;
283
217
  this[TYPES.array].push.local = Valtype.i32;
284
218
  this[TYPES.array].pop.local = Valtype.i32;
285
- this[TYPES.array].fill.local = valtypeBinary;
286
- this[TYPES.array].fill.local2 = Valtype.i32;
287
- this[TYPES.array].fill.returnType = TYPES.array;
288
219
 
289
220
  this[TYPES.string] = {
290
221
  at: (pointer, length, wIndex, wType, iTmp, _, arrayShell) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.17.0-c2af76d41",
4
+ "version": "0.17.0-c2dd8f88f",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/rhemyn/compile.js CHANGED
@@ -12,15 +12,36 @@ const Length = 4;
12
12
  const Tmp = 5;
13
13
  const QuantifierTmp = 6; // the temporary variable used for quanitifers
14
14
 
15
+ const doesSucceedZero = (node) => {
16
+ for (const n of node.body) {
17
+ if (n.type === "Group") {
18
+ if (!doesSucceedZero(node)) return false;
19
+ }
20
+ if (!n.quantifier || n.quantifier[0] > 0) {
21
+ return false;
22
+ }
23
+ }
24
+ return true;
25
+ }
26
+
15
27
  const generate = (node, negated = false, get = true, stringSize = 2, func = 'test') => {
16
28
  let out = [];
17
29
  switch (node.type) {
18
30
  case 'Expression':
31
+ let succeedsZero = doesSucceedZero(node);
32
+
19
33
  out = [
20
34
  // set length local
21
35
  [ Opcodes.local_get, BasePointer ],
22
36
  [ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
23
- [ Opcodes.local_set, Length ],
37
+ [ Opcodes.local_tee, Length ],
38
+
39
+ ...number(0, Valtype.i32),
40
+ [ Opcodes.i32_eq ],
41
+ [ Opcodes.if, Blocktype.void ],
42
+ ...number(succeedsZero ? 1 : 0, Valtype.i32),
43
+ [ Opcodes.return ],
44
+ [ Opcodes.end ],
24
45
 
25
46
  // pointer = base + sizeof i32
26
47
  [ Opcodes.local_get, BasePointer ],
@@ -43,14 +64,15 @@ const generate = (node, negated = false, get = true, stringSize = 2, func = 'tes
43
64
  [ Opcodes.return ],
44
65
  [ Opcodes.end ],
45
66
 
46
- // increment counter by 1, check if eq length, if not loop
67
+ // counter++, if length > counter, loop
68
+ [ Opcodes.local_get, Length ],
69
+
47
70
  [ Opcodes.local_get, Counter ],
48
71
  ...number(1, Valtype.i32),
49
72
  [ Opcodes.i32_add ],
50
73
  [ Opcodes.local_tee, Counter ],
51
74
 
52
- [ Opcodes.local_get, Length ],
53
- [ Opcodes.i32_ne ],
75
+ [ Opcodes.i32_gt_s ],
54
76
 
55
77
  [ Opcodes.br_if, 0 ],
56
78
  [ Opcodes.end ],
@@ -122,6 +144,18 @@ const wrapQuantifier = (node, method, get, stringSize) => {
122
144
  ...number(0, Valtype.i32),
123
145
  [Opcodes.local_set, QuantifierTmp],
124
146
 
147
+ // if len - counter == 0, if min == 0, succeed, else fail
148
+ [ Opcodes.local_get, Length ],
149
+ [ Opcodes.local_get, Counter ],
150
+ [ Opcodes.i32_sub ],
151
+ ...number(0, Valtype.i32),
152
+ [ Opcodes.i32_eq ],
153
+ ...(min == 0 ? [
154
+ [ Opcodes.if, Blocktype.void ],
155
+ ] : [
156
+ [ Opcodes.br_if, 0 ],
157
+ ]),
158
+
125
159
  // start loop
126
160
  [Opcodes.loop, Blocktype.void],
127
161
  [ Opcodes.block, Blocktype.void ],
@@ -166,13 +200,7 @@ const wrapQuantifier = (node, method, get, stringSize) => {
166
200
  [Opcodes.i32_lt_s],
167
201
  ...(get ? checkFailure(): []),
168
202
 
169
- // counter += tmp - 1
170
- [ Opcodes.local_get, QuantifierTmp ],
171
- ...number(1, Valtype.i32),
172
- [ Opcodes.i32_sub ],
173
- [ Opcodes.local_get, Counter ],
174
- [ Opcodes.i32_add ],
175
- [ Opcodes.local_set, Counter ]
203
+ ...(min == 0 ? [ [ Opcodes.end ] ] : []),
176
204
  ];
177
205
  }
178
206
 
@@ -190,7 +218,7 @@ const generateChar = (node, negated, get, stringSize) => {
190
218
 
191
219
  return [
192
220
  ...out,
193
- ...(get ? checkFailure(): [])
221
+ ...(get ? checkFailure(): []),
194
222
  ];
195
223
  };
196
224
 
@@ -225,7 +253,7 @@ const generateSet = (node, negated, get, stringSize) => {
225
253
 
226
254
  return [
227
255
  ...out,
228
- ...checkFailure()
256
+ ...checkFailure(),
229
257
  ];
230
258
  };
231
259