porffor 0.55.21 → 0.55.23

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.
@@ -15,8 +15,8 @@ export const PrototypeFuncs = function() {
15
15
 
16
16
  this[TYPES.array] = {
17
17
  // lX = local accessor of X ({ get, set }), iX = local index of X, wX = wasm ops of X
18
- at: (pointer, length, wIndex, wType, iTmp) => [
19
- ...wIndex,
18
+ at: ({ pointer, length, arg, iTmp, setType }) => [
19
+ ...arg,
20
20
  Opcodes.i32_to,
21
21
  [ Opcodes.local_tee, iTmp ],
22
22
 
@@ -24,10 +24,10 @@ export const PrototypeFuncs = function() {
24
24
  number(0, Valtype.i32),
25
25
  [ Opcodes.i32_lt_s ],
26
26
  [ Opcodes.if, Blocktype.void ],
27
- [ Opcodes.local_get, iTmp ],
28
- ...length.getCachedI32(),
29
- [ Opcodes.i32_add ],
30
- [ Opcodes.local_set, iTmp ],
27
+ [ Opcodes.local_get, iTmp ],
28
+ ...length.getCachedI32(),
29
+ [ Opcodes.i32_add ],
30
+ [ Opcodes.local_set, iTmp ],
31
31
  [ Opcodes.end ],
32
32
 
33
33
  // if still < 0 or >= length: return undefined
@@ -41,8 +41,9 @@ export const PrototypeFuncs = function() {
41
41
  [ Opcodes.i32_or ],
42
42
 
43
43
  [ Opcodes.if, Blocktype.void ],
44
- number(UNDEFINED),
45
- [ Opcodes.br, 1 ],
44
+ number(UNDEFINED),
45
+ ...setType(TYPES.undefined),
46
+ [ Opcodes.br, 1 ],
46
47
  [ Opcodes.end ],
47
48
 
48
49
  [ Opcodes.local_get, iTmp ],
@@ -57,18 +58,20 @@ export const PrototypeFuncs = function() {
57
58
  [ Opcodes.load, 0, ValtypeSize.i32 ],
58
59
 
59
60
  [ Opcodes.local_get, iTmp ],
60
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
61
+ [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
62
+ ...setType()
61
63
  ],
62
64
 
63
- pop: (pointer, length, _1, _2, iTmp, _3, _4, unusedValue) => [
65
+ pop: ({ pointer, length, iTmp, unusedValue, setType }) => [
64
66
  // if length == 0, noop
65
67
  ...length.getCachedI32(),
66
68
  [ Opcodes.i32_eqz ],
67
69
  [ Opcodes.if, Blocktype.void ],
68
- ...(unusedValue() ? [] : [
69
- number(UNDEFINED),
70
- ]),
71
- [ Opcodes.br, 1 ],
70
+ ...(unusedValue() ? [] : [
71
+ number(UNDEFINED),
72
+ ...setType(TYPES.undefined)
73
+ ]),
74
+ [ Opcodes.br, 1 ],
72
75
  [ Opcodes.end ],
73
76
 
74
77
  // todo: should we store 0/undefined in "removed" element?
@@ -99,17 +102,19 @@ export const PrototypeFuncs = function() {
99
102
  [ Opcodes.load, 0, ValtypeSize.i32 ],
100
103
 
101
104
  [ Opcodes.local_get, iTmp ],
102
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
105
+ [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
106
+ ...setType()
103
107
  ])
104
108
  ],
105
109
 
106
- shift: (pointer, length) => [
110
+ shift: ({ pointer, length, setType }) => [
107
111
  // if length == 0, noop
108
112
  ...length.getCachedI32(),
109
113
  [ Opcodes.i32_eqz ],
110
114
  [ Opcodes.if, Blocktype.void ],
111
- number(UNDEFINED),
112
- [ Opcodes.br, 1 ],
115
+ number(UNDEFINED),
116
+ ...setType(TYPES.undefined),
117
+ [ Opcodes.br, 1 ],
113
118
  [ Opcodes.end ],
114
119
 
115
120
  // todo: should we store 0/undefined in "removed" element?
@@ -131,6 +136,7 @@ export const PrototypeFuncs = function() {
131
136
 
132
137
  ...pointer,
133
138
  [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
139
+ ...setType(),
134
140
 
135
141
  // offset page by -1 ind
136
142
  // number(pointer + ValtypeSize.i32, Valtype.i32), // dst = base array index + length size
@@ -175,17 +181,17 @@ export const PrototypeFuncs = function() {
175
181
  this[TYPES.array].pop.local = Valtype.i32;
176
182
 
177
183
  this[TYPES.string] = {
178
- at: (pointer, length, wIndex, wType, iTmp, iOut, alloc) => [
179
- // setup new/out array and use pointer for store
184
+ at: ({ pointer, length, arg, iTmp, iTmp2, alloc, setType }) => [
185
+ // setup out string and use pointer for store
180
186
  ...alloc(8),
181
- [ Opcodes.local_tee, iOut ],
187
+ [ Opcodes.local_tee, iTmp2 ],
182
188
 
183
189
  // out.length = 1
184
- [ Opcodes.local_get, iOut ],
190
+ [ Opcodes.local_get, iTmp2 ],
185
191
  number(1, Valtype.i32),
186
192
  [ Opcodes.i32_store, 0, 0 ],
187
193
 
188
- ...wIndex,
194
+ ...arg,
189
195
  Opcodes.i32_to_u,
190
196
  [ Opcodes.local_tee, iTmp ],
191
197
 
@@ -193,10 +199,10 @@ export const PrototypeFuncs = function() {
193
199
  number(0, Valtype.i32),
194
200
  [ Opcodes.i32_lt_s ],
195
201
  [ Opcodes.if, Blocktype.void ],
196
- [ Opcodes.local_get, iTmp ],
197
- ...length.getCachedI32(),
198
- [ Opcodes.i32_add ],
199
- [ Opcodes.local_set, iTmp ],
202
+ [ Opcodes.local_get, iTmp ],
203
+ ...length.getCachedI32(),
204
+ [ Opcodes.i32_add ],
205
+ [ Opcodes.local_set, iTmp ],
200
206
  [ Opcodes.end ],
201
207
 
202
208
  // if still < 0 or >= length: return undefined
@@ -210,8 +216,9 @@ export const PrototypeFuncs = function() {
210
216
  [ Opcodes.i32_or ],
211
217
 
212
218
  [ Opcodes.if, Blocktype.void ],
213
- number(UNDEFINED),
214
- [ Opcodes.br, 1 ],
219
+ number(UNDEFINED),
220
+ ...setType(TYPES.undefined),
221
+ [ Opcodes.br, 1 ],
215
222
  [ Opcodes.end ],
216
223
 
217
224
  [ Opcodes.local_get, iTmp ],
@@ -228,13 +235,15 @@ export const PrototypeFuncs = function() {
228
235
  [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
229
236
 
230
237
  // return new string (pointer)
231
- [ Opcodes.local_get, iOut ],
232
- Opcodes.i32_from_u
238
+ [ Opcodes.local_get, iTmp2 ],
239
+ Opcodes.i32_from_u,
240
+
241
+ ...setType(TYPES.string)
233
242
  ],
234
243
 
235
244
  // todo: out of bounds properly
236
- charAt: (pointer, length, wIndex, wType, iTmp, _, alloc) => [
237
- // setup new/out array and use as pointer for store
245
+ charAt: ({ pointer, arg, iTmp, alloc, setType }) => [
246
+ // setup out string and use as pointer for store
238
247
  ...alloc(8),
239
248
  [ Opcodes.local_tee, iTmp ],
240
249
 
@@ -243,7 +252,7 @@ export const PrototypeFuncs = function() {
243
252
  number(1, Valtype.i32),
244
253
  [ Opcodes.i32_store, 0, 0 ],
245
254
 
246
- ...wIndex,
255
+ ...arg,
247
256
  Opcodes.i32_to,
248
257
 
249
258
  number(ValtypeSize.i16, Valtype.i32),
@@ -260,11 +269,15 @@ export const PrototypeFuncs = function() {
260
269
 
261
270
  // return new string (page)
262
271
  [ Opcodes.local_get, iTmp ],
263
- Opcodes.i32_from_u
272
+ Opcodes.i32_from_u,
273
+
274
+ ...setType(TYPES.string)
264
275
  ],
265
276
 
266
- charCodeAt: (pointer, length, wIndex, wType, iTmp) => [
267
- ...wIndex,
277
+ charCodeAt: ({ pointer, length, arg, iTmp, setType }) => [
278
+ ...setType(TYPES.number),
279
+
280
+ ...arg,
268
281
  Opcodes.i32_to,
269
282
 
270
283
  ...(zeroChecks.charcodeat ? [] : [
@@ -284,8 +297,8 @@ export const PrototypeFuncs = function() {
284
297
 
285
298
  ...(noUnlikelyChecks ? [] : [ [ Opcodes.i32_or ] ]),
286
299
  [ Opcodes.if, Blocktype.void ],
287
- number(valtype === 'i32' ? -1 : NaN),
288
- [ Opcodes.br, 1 ],
300
+ number(valtype === 'i32' ? -1 : NaN),
301
+ [ Opcodes.br, 1 ],
289
302
  [ Opcodes.end ],
290
303
 
291
304
  [ Opcodes.local_get, iTmp ],
@@ -305,25 +318,22 @@ export const PrototypeFuncs = function() {
305
318
 
306
319
  this[TYPES.string].at.local = Valtype.i32;
307
320
  this[TYPES.string].at.local2 = Valtype.i32;
308
- this[TYPES.string].at.returnType = TYPES.string;
309
321
  this[TYPES.string].charAt.local = Valtype.i32;
310
- this[TYPES.string].charAt.returnType = TYPES.string;
311
- this[TYPES.string].charCodeAt.returnType = TYPES.number;
312
322
  this[TYPES.string].charCodeAt.local = Valtype.i32;
313
323
  this[TYPES.string].charCodeAt.noPointerCache = zeroChecks.charcodeat;
314
324
 
315
325
  this[TYPES.bytestring] = {
316
- at: (pointer, length, wIndex, wType, iTmp, iOut, alloc) => [
317
- // setup new/out array and use pointer for store
326
+ at: ({ pointer, length, arg, iTmp, iTmp2, alloc, setType }) => [
327
+ // setup out string and use pointer for store
318
328
  ...alloc(8),
319
- [ Opcodes.local_tee, iOut ],
329
+ [ Opcodes.local_tee, iTmp2 ],
320
330
 
321
331
  // out.length = 1
322
- [ Opcodes.local_get, iOut ],
332
+ [ Opcodes.local_get, iTmp2 ],
323
333
  number(1, Valtype.i32),
324
334
  [ Opcodes.i32_store, 0, 0 ],
325
335
 
326
- ...wIndex,
336
+ ...arg,
327
337
  Opcodes.i32_to_u,
328
338
  [ Opcodes.local_tee, iTmp ],
329
339
 
@@ -331,10 +341,10 @@ export const PrototypeFuncs = function() {
331
341
  number(0, Valtype.i32),
332
342
  [ Opcodes.i32_lt_s ],
333
343
  [ Opcodes.if, Blocktype.void ],
334
- [ Opcodes.local_get, iTmp ],
335
- ...length.getCachedI32(),
336
- [ Opcodes.i32_add ],
337
- [ Opcodes.local_set, iTmp ],
344
+ [ Opcodes.local_get, iTmp ],
345
+ ...length.getCachedI32(),
346
+ [ Opcodes.i32_add ],
347
+ [ Opcodes.local_set, iTmp ],
338
348
  [ Opcodes.end ],
339
349
 
340
350
  // if still < 0 or >= length: return undefined
@@ -348,8 +358,9 @@ export const PrototypeFuncs = function() {
348
358
  [ Opcodes.i32_or ],
349
359
 
350
360
  [ Opcodes.if, Blocktype.void ],
351
- number(UNDEFINED),
352
- [ Opcodes.br, 1 ],
361
+ number(UNDEFINED),
362
+ ...setType(TYPES.undefined),
363
+ [ Opcodes.br, 1 ],
353
364
  [ Opcodes.end ],
354
365
 
355
366
  [ Opcodes.local_get, iTmp ],
@@ -364,13 +375,15 @@ export const PrototypeFuncs = function() {
364
375
  [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
365
376
 
366
377
  // return new string (pointer)
367
- [ Opcodes.local_get, iOut ],
368
- Opcodes.i32_from_u
378
+ [ Opcodes.local_get, iTmp2 ],
379
+ Opcodes.i32_from_u,
380
+
381
+ ...setType(TYPES.bytestring)
369
382
  ],
370
383
 
371
384
  // todo: out of bounds properly
372
- charAt: (pointer, length, wIndex, wType, iTmp, _, alloc) => [
373
- // setup new/out array and use as pointer for store
385
+ charAt: ({ pointer, arg, iTmp, alloc, setType }) => [
386
+ // setup out string and use as pointer for store
374
387
  ...alloc(8),
375
388
  [ Opcodes.local_tee, iTmp ],
376
389
 
@@ -379,7 +392,7 @@ export const PrototypeFuncs = function() {
379
392
  number(1, Valtype.i32),
380
393
  [ Opcodes.i32_store, 0, 0 ],
381
394
 
382
- ...wIndex,
395
+ ...arg,
383
396
  Opcodes.i32_to,
384
397
 
385
398
  ...pointer,
@@ -393,11 +406,15 @@ export const PrototypeFuncs = function() {
393
406
 
394
407
  // return new string (page)
395
408
  [ Opcodes.local_get, iTmp ],
396
- Opcodes.i32_from_u
409
+ Opcodes.i32_from_u,
410
+
411
+ ...setType(TYPES.bytestring)
397
412
  ],
398
413
 
399
- charCodeAt: (pointer, length, wIndex, wType, iTmp) => [
400
- ...wIndex,
414
+ charCodeAt: ({ pointer, length, arg, iTmp, setType }) => [
415
+ ...setType(TYPES.number),
416
+
417
+ ...arg,
401
418
  Opcodes.i32_to,
402
419
 
403
420
  ...(zeroChecks.charcodeat ? [] : [
@@ -417,8 +434,8 @@ export const PrototypeFuncs = function() {
417
434
 
418
435
  ...(noUnlikelyChecks ? [] : [ [ Opcodes.i32_or ] ]),
419
436
  [ Opcodes.if, Blocktype.void ],
420
- number(valtype === 'i32' ? -1 : NaN),
421
- [ Opcodes.br, 1 ],
437
+ number(valtype === 'i32' ? -1 : NaN),
438
+ [ Opcodes.br, 1 ],
422
439
  [ Opcodes.end ],
423
440
 
424
441
  [ Opcodes.local_get, iTmp ],
@@ -435,10 +452,7 @@ export const PrototypeFuncs = function() {
435
452
 
436
453
  this[TYPES.bytestring].at.local = Valtype.i32;
437
454
  this[TYPES.bytestring].at.local2 = Valtype.i32;
438
- this[TYPES.bytestring].at.returnType = TYPES.bytestring;
439
455
  this[TYPES.bytestring].charAt.local = Valtype.i32;
440
- this[TYPES.bytestring].charAt.returnType = TYPES.bytestring;
441
- this[TYPES.bytestring].charCodeAt.returnType = TYPES.number;
442
456
  this[TYPES.bytestring].charCodeAt.local = Valtype.i32;
443
457
  this[TYPES.bytestring].charCodeAt.noPointerCache = zeroChecks.charcodeat;
444
458
  };
package/compiler/wrap.js CHANGED
@@ -48,11 +48,11 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type, override = undefin
48
48
  case TYPES.object: {
49
49
  if (value === 0 || checkOOB(memory, value)) return null;
50
50
 
51
- const size = read(Uint32Array, memory, value, 1)[0];
51
+ const size = read(Uint16Array, memory, value, 1)[0];
52
52
 
53
53
  const out = {};
54
54
  for (let i = 0; i < size; i++) {
55
- const offset = 5 + (i * 14);
55
+ const offset = 8 + (i * 18) + 4;
56
56
 
57
57
  const kRaw = read(Uint32Array, memory, value + offset, 1)[0];
58
58
  let kType = TYPES.bytestring;
@@ -65,11 +65,10 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type, override = undefin
65
65
  kType = TYPES.symbol;
66
66
  break;
67
67
  }
68
+
68
69
  const kValue = kRaw & 0x3fffffff;
69
70
  const k = porfToJSValue({ memory, funcs, pages }, kValue, kType);
70
71
 
71
- if (k === '__proto__') continue;
72
-
73
72
  const tail = read(Uint16Array, memory, value + offset + 12, 1)[0];
74
73
 
75
74
  const vValue = read(Float64Array, memory, value + offset + 4, 1)[0];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.55.21",
4
+ "version": "0.55.23",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/r.cjs CHANGED
@@ -1,4 +1,33 @@
1
+ // let { 1n: a } = { "1": "foo" };
2
+ // console.log(a);
3
+ let obj = { "1": "foo" };
4
+ console.log(obj, obj[1], obj[1n]);
1
5
 
6
+ // let x = {};
7
+ // x.__proto__ = { wow() { console.log(0); } };
8
+ // Object.defineProperty(x, '__proto__', { value: { wow() { console.log(1); } } });
9
+ // // x.__proto__ = { wow() { console.log(2); } };
10
+ // x.wow();
11
+
12
+ // var stringSet;
13
+
14
+ // class C {
15
+ // get #_() { console.log('get'); return 'get string'; }
16
+ // set #_(param) { console.log('set', param); stringSet = param; }
17
+
18
+ // getPrivateReference() {
19
+ // return this.#_;
20
+ // }
21
+
22
+ // setPrivateReference(value) {
23
+ // this.#_ = value;
24
+ // }
25
+ // };
26
+
27
+ // var inst = new C();
28
+ // console.log(inst.getPrivateReference());
29
+ // inst.setPrivateReference('set string');
30
+ // console.log(stringSet);
2
31
 
3
32
  // let o = { set foo(x) { console.log('set foo', x); }, __proto__: { set bar(x) { console.log('set bar', x); } } };
4
33
 
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.55.21';
3
+ globalThis.version = '0.55.23';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {