porffor 0.55.31 → 0.55.33

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.
@@ -7,9 +7,9 @@ export const Object = function (value: any): any {
7
7
  }
8
8
 
9
9
  // primitives into primitive objects
10
- if ((Porffor.rawType(value) | 0b10000000) == Porffor.TYPES.bytestring) return new String(value);
11
- if (Porffor.rawType(value) == Porffor.TYPES.number) return new Number(value);
12
- if (Porffor.rawType(value) == Porffor.TYPES.boolean) return new Boolean(value);
10
+ if ((Porffor.type(value) | 0b10000000) == Porffor.TYPES.bytestring) return new String(value);
11
+ if (Porffor.type(value) == Porffor.TYPES.number) return new Number(value);
12
+ if (Porffor.type(value) == Porffor.TYPES.boolean) return new Boolean(value);
13
13
 
14
14
  // return input
15
15
  return value;
@@ -20,7 +20,7 @@ export const __Object_keys = (obj: any): any[] => {
20
20
  const out: any[] = Porffor.allocate();
21
21
 
22
22
  obj = __Porffor_object_underlying(obj);
23
- const t: i32 = Porffor.rawType(obj);
23
+ const t: i32 = Porffor.type(obj);
24
24
  if (t == Porffor.TYPES.object) {
25
25
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
26
26
  const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
@@ -76,7 +76,7 @@ export const __Object_values = (obj: any): any[] => {
76
76
  const out: any[] = Porffor.allocate();
77
77
 
78
78
  obj = __Porffor_object_underlying(obj);
79
- const t: i32 = Porffor.rawType(obj);
79
+ const t: i32 = Porffor.type(obj);
80
80
  if (t == Porffor.TYPES.object) {
81
81
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
82
82
  const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
@@ -146,13 +146,13 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
146
146
  if (_this == null) throw new TypeError('Argument is nullish, expected object');
147
147
  const p: any = ecma262.ToPropertyKey(prop);
148
148
 
149
- const t: i32 = Porffor.rawType(_this);
149
+ const t: i32 = Porffor.type(_this);
150
150
  if (t == Porffor.TYPES.object) {
151
151
  return Porffor.object.lookup(_this, p, __Porffor_object_hash(p)) != -1;
152
152
  }
153
153
 
154
154
  const obj: any = __Porffor_object_underlying(_this);
155
- if (Porffor.rawType(obj) == Porffor.TYPES.object) {
155
+ if (Porffor.type(obj) == Porffor.TYPES.object) {
156
156
  if (Porffor.object.lookup(obj, p, __Porffor_object_hash(p)) != -1) return true;
157
157
  }
158
158
 
@@ -173,7 +173,7 @@ export const __Porffor_object_in = (obj: any, prop: any): boolean => {
173
173
 
174
174
  let lastProto = obj;
175
175
  while (true) {
176
- obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
176
+ obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
177
177
  if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
178
178
 
179
179
  if (__Object_prototype_hasOwnProperty(obj, prop)) return true;
@@ -184,7 +184,7 @@ export const __Porffor_object_in = (obj: any, prop: any): boolean => {
184
184
  };
185
185
 
186
186
  export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: any): boolean => {
187
- if (Porffor.rawType(constr) != Porffor.TYPES.function) {
187
+ if (Porffor.type(constr) != Porffor.TYPES.function) {
188
188
  throw new TypeError('instanceof right-hand side is not a function');
189
189
  }
190
190
 
@@ -194,7 +194,7 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
194
194
 
195
195
  let lastProto = obj;
196
196
  while (true) {
197
- obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
197
+ obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
198
198
  if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
199
199
 
200
200
  if (obj === checkProto) return true;
@@ -240,7 +240,7 @@ export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) =
240
240
 
241
241
  const p: any = ecma262.ToPropertyKey(prop);
242
242
 
243
- if (Porffor.rawType(_this) == Porffor.TYPES.object) {
243
+ if (Porffor.type(_this) == Porffor.TYPES.object) {
244
244
  const entryPtr: i32 = Porffor.object.lookup(_this, p, __Porffor_object_hash(p));
245
245
  if (entryPtr == -1) return false;
246
246
 
@@ -248,7 +248,7 @@ export const __Object_prototype_propertyIsEnumerable = (_this: any, prop: any) =
248
248
  }
249
249
 
250
250
  const obj: any = __Porffor_object_underlying(_this);
251
- if (Porffor.rawType(obj) == Porffor.TYPES.object) {
251
+ if (Porffor.type(obj) == Porffor.TYPES.object) {
252
252
  const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
253
253
  if (entryPtr != -1) return Porffor.object.isEnumerable(entryPtr);
254
254
  }
@@ -269,7 +269,7 @@ export const __Object_is = (x: any, y: any): boolean => {
269
269
  }
270
270
 
271
271
  // check NaN
272
- if (Porffor.rawType(x) == Porffor.TYPES.number && Number.isNaN(x)) {
272
+ if (Porffor.type(x) == Porffor.TYPES.number && Number.isNaN(x)) {
273
273
  return Number.isNaN(y);
274
274
  }
275
275
 
@@ -347,7 +347,7 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
347
347
 
348
348
  const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
349
349
  if (entryPtr == -1) {
350
- if (Porffor.rawType(obj) == Porffor.TYPES.function) {
350
+ if (Porffor.type(obj) == Porffor.TYPES.function) {
351
351
  // hack: function .name and .length
352
352
  const v = obj[p];
353
353
  if (v != null) {
@@ -394,9 +394,9 @@ local.set ${value+1}`;
394
394
  export const __Object_getOwnPropertyDescriptors = (obj: any): object => {
395
395
  const out: object = {};
396
396
 
397
- if (Porffor.rawType(obj) != Porffor.TYPES.object) {
397
+ if (Porffor.type(obj) != Porffor.TYPES.object) {
398
398
  obj = __Porffor_object_underlying(obj);
399
- if (Porffor.rawType(obj) != Porffor.TYPES.object) return out;
399
+ if (Porffor.type(obj) != Porffor.TYPES.object) return out;
400
400
  }
401
401
 
402
402
  const keys: any[] = Reflect.ownKeys(obj);
@@ -413,7 +413,7 @@ export const __Object_getOwnPropertyNames = (obj: any): any[] => {
413
413
  const out: any[] = Porffor.allocate();
414
414
 
415
415
  obj = __Porffor_object_underlying(obj);
416
- const t: i32 = Porffor.rawType(obj);
416
+ const t: i32 = Porffor.type(obj);
417
417
  if (t == Porffor.TYPES.object) {
418
418
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
419
419
  const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
@@ -453,7 +453,7 @@ end
453
453
  i32.from_u
454
454
  local.set ${key}`;
455
455
 
456
- if (Porffor.rawType(key) == Porffor.TYPES.symbol) continue;
456
+ if (Porffor.type(key) == Porffor.TYPES.symbol) continue;
457
457
  out[i++] = key;
458
458
  }
459
459
 
@@ -468,7 +468,7 @@ export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
468
468
  const out: any[] = Porffor.allocate();
469
469
 
470
470
  obj = __Porffor_object_underlying(obj);
471
- const t: i32 = Porffor.rawType(obj);
471
+ const t: i32 = Porffor.type(obj);
472
472
  if (t == Porffor.TYPES.object) {
473
473
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
474
474
  const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
@@ -508,7 +508,7 @@ end
508
508
  i32.from_u
509
509
  local.set ${key}`;
510
510
 
511
- if (Porffor.rawType(key) != Porffor.TYPES.symbol) continue;
511
+ if (Porffor.type(key) != Porffor.TYPES.symbol) continue;
512
512
  out[i++] = key;
513
513
  }
514
514
 
@@ -523,7 +523,7 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any): any
523
523
  if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
524
524
  if (!Porffor.object.isObject(desc)) throw new TypeError('Descriptor is a non-object');
525
525
 
526
- if (Porffor.rawType(target) == Porffor.TYPES.array) {
526
+ if (Porffor.type(target) == Porffor.TYPES.array) {
527
527
  if (prop === 'length' && __Object_hasOwn(desc, 'value')) {
528
528
  const v: any = desc.value;
529
529
  const n: number = ecma262.ToNumber(v);
@@ -558,8 +558,8 @@ export const __Object_defineProperty = (target: any, prop: any, desc: any): any
558
558
 
559
559
  // todo: should check if has attributes not if undefined
560
560
  if (get !== undefined || set !== undefined) {
561
- if (get !== undefined && Porffor.rawType(get) != Porffor.TYPES.function) throw new TypeError('Getter must be a function');
562
- if (set !== undefined && Porffor.rawType(set) != Porffor.TYPES.function) throw new TypeError('Setter must be a function');
561
+ if (get !== undefined && Porffor.type(get) != Porffor.TYPES.function) throw new TypeError('Getter must be a function');
562
+ if (set !== undefined && Porffor.type(set) != Porffor.TYPES.function) throw new TypeError('Setter must be a function');
563
563
 
564
564
  if (value !== undefined || writable !== undefined) {
565
565
  throw new TypeError('Descriptor cannot define both accessor and data descriptor attributes');
@@ -640,7 +640,7 @@ export const __Object_groupBy = (items: any, callbackFn: any): object => {
640
640
 
641
641
  export const __Object_getPrototypeOf = (obj: any): any => {
642
642
  if (obj == null) throw new TypeError('Object is nullish, expected object');
643
- return Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
643
+ return Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
644
644
  };
645
645
 
646
646
  export const __Object_setPrototypeOf = (obj: any, proto: any): any => {
@@ -657,22 +657,22 @@ export const __Object_prototype_isPrototypeOf = (_this: any, obj: any) => {
657
657
  if (_this == null) throw new TypeError('This is nullish, expected object');
658
658
 
659
659
  if (!Porffor.object.isObject(obj)) return false;
660
- return _this == Porffor.object.getPrototypeWithHidden(obj, Porffor.rawType(obj));
660
+ return _this == Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
661
661
  };
662
662
 
663
663
 
664
664
  export const __Object_prototype_toString = (_this: any) => {
665
- if (Porffor.rawType(_this) == Porffor.TYPES.object) {
665
+ if (Porffor.type(_this) == Porffor.TYPES.object) {
666
666
  // todo: breaks with Foo.prototype
667
667
  const obj: object = _this;
668
668
  if (obj != null) {
669
669
  let ovr: any = obj.toString;
670
- if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_toString) return ovr.call(_this);
670
+ if (Porffor.type(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_toString) return ovr.call(_this);
671
671
 
672
672
  const entryPtr: i32 = Porffor.object.lookup(obj, 'toString', __Porffor_object_hash('toString')); // todo: comptime
673
673
  if (entryPtr != -1) {
674
674
  ovr = Porffor.object.readValue(entryPtr);
675
- if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
675
+ if (Porffor.type(ovr) == Porffor.TYPES.function) return ovr.call(_this);
676
676
  else return undefined;
677
677
  }
678
678
  }
@@ -686,7 +686,7 @@ export const __Object_prototype_toString = (_this: any) => {
686
686
 
687
687
  // todo: toStringTag support
688
688
 
689
- const t: i32 = Porffor.rawType(_this);
689
+ const t: i32 = Porffor.type(_this);
690
690
  if (t == Porffor.TYPES.array) return '[object Array]';
691
691
  if (t == Porffor.TYPES.function) return '[object Function]';
692
692
  if (Porffor.fastOr(
@@ -709,17 +709,17 @@ export const __Object_prototype_toLocaleString = (_this: any) => __Object_protot
709
709
 
710
710
  export const __Object_prototype_valueOf = (_this: any) => {
711
711
  // todo: ToObject
712
- if (Porffor.rawType(_this) == Porffor.TYPES.object) {
712
+ if (Porffor.type(_this) == Porffor.TYPES.object) {
713
713
  // todo: breaks with Foo.prototype
714
714
  const obj: object = _this;
715
715
  if (obj != null) {
716
716
  let ovr: any = obj.valueOf;
717
- if (Porffor.rawType(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_valueOf) return ovr.call(_this);
717
+ if (Porffor.type(ovr) == Porffor.TYPES.function && ovr != __Object_prototype_valueOf) return ovr.call(_this);
718
718
 
719
719
  const entryPtr: i32 = Porffor.object.lookup(obj, 'valueOf', __Porffor_object_hash('valueOf')); // todo: comptime
720
720
  if (entryPtr != -1) {
721
721
  ovr = Porffor.object.readValue(entryPtr);
722
- if (Porffor.rawType(ovr) == Porffor.TYPES.function) return ovr.call(_this);
722
+ if (Porffor.type(ovr) == Porffor.TYPES.function) return ovr.call(_this);
723
723
  else return undefined;
724
724
  }
725
725
  }
@@ -2,7 +2,7 @@ export default ({ TYPES, TYPE_NAMES }) => {
2
2
  let out = `// @porf --valtype=i32
3
3
  export const __Porffor_object_getPrototypeWithHidden = (obj: any, trueType: i32): any => {
4
4
  const objectProto: any = __Porffor_object_getPrototype(obj);
5
- if (Porffor.rawType(objectProto) == Porffor.TYPES.empty) {
5
+ if (Porffor.type(objectProto) == Porffor.TYPES.empty) {
6
6
  if (Porffor.comptime.flag\`hasFunc.#get___String_prototype\`) {
7
7
  if (Porffor.fastOr(
8
8
  trueType == Porffor.TYPES.string,
@@ -23,6 +23,7 @@ type PorfforGlobal = {
23
23
  f64: {
24
24
  load(pointer: any, align: i32, offset: i32): i32;
25
25
  store(pointer: any, value: f64, align: i32, offset: i32): f64;
26
+ eq(a: f64, b: f64): boolean;
26
27
  }
27
28
  }
28
29
 
@@ -57,7 +58,7 @@ type PorfforGlobal = {
57
58
  lookup(obj: object, target: any): i32;
58
59
  get(obj: any, key: any): any;
59
60
 
60
- writeKey(ptr: i32, key: any): void;
61
+ writeKey(ptr: i32, key: any, hash: i32): void;
61
62
  set(obj: object, key: any, value: any): any;
62
63
  define(obj: object, key: any, value: any, flags: i32): void;
63
64
  delete(obj: object, key: any): boolean;
@@ -97,8 +98,8 @@ type PorfforGlobal = {
97
98
 
98
99
  randomByte(): i32;
99
100
 
100
- type(x: any): bytestring;
101
- rawType(x: any): i32;
101
+ type(x: any): i32;
102
+ typeName(type: i32): bytestring;
102
103
  TYPES: {
103
104
  number: i32;
104
105
  boolean: i32;
@@ -31,7 +31,7 @@ export const __ecma262_TriggerPromiseReactions = (reactions: any[], argument: an
31
31
  // https://tc39.es/ecma262/#sec-ispromise
32
32
  export const __ecma262_IsPromise = (x: any): boolean => {
33
33
  // custom impl
34
- return Porffor.rawType(x) == Porffor.TYPES.promise;
34
+ return Porffor.type(x) == Porffor.TYPES.promise;
35
35
  };
36
36
 
37
37
  // 27.2.1.4 FulfillPromise (promise, value)
@@ -227,7 +227,7 @@ export const __Porffor_promise_rejectActive = (reason: any): void => __Porffor_p
227
227
 
228
228
  export const Promise = function (executor: any): Promise {
229
229
  if (!new.target) throw new TypeError("Constructor Promise requires 'new'");
230
- if (Porffor.rawType(executor) != Porffor.TYPES.function) throw new TypeError('Promise executor is not a function');
230
+ if (Porffor.type(executor) != Porffor.TYPES.function) throw new TypeError('Promise executor is not a function');
231
231
 
232
232
  const obj: any[] = __Porffor_promise_create();
233
233
  activePromise = obj;
@@ -279,8 +279,8 @@ export const __Promise_prototype_then = (_this: any, onFulfilled: any, onRejecte
279
279
  // 2. If IsPromise(promise) is false, throw a TypeError exception.
280
280
  if (!__ecma262_IsPromise(_this)) throw new TypeError('Promise.prototype.then called on non-Promise');
281
281
 
282
- if (Porffor.rawType(onFulfilled) != Porffor.TYPES.function) onFulfilled = __Porffor_promise_noop;
283
- if (Porffor.rawType(onRejected) != Porffor.TYPES.function) onRejected = __Porffor_promise_noop;
282
+ if (Porffor.type(onFulfilled) != Porffor.TYPES.function) onFulfilled = __Porffor_promise_noop;
283
+ if (Porffor.type(onRejected) != Porffor.TYPES.function) onRejected = __Porffor_promise_noop;
284
284
 
285
285
  const outPromise: any[] = __Porffor_promise_create();
286
286
 
@@ -304,7 +304,7 @@ export const __Promise_prototype_finally = (_this: any, onFinally: any) => {
304
304
  // custom impl based on then but also not (sorry)
305
305
  if (!__ecma262_IsPromise(_this)) throw new TypeError('Promise.prototype.then called on non-Promise');
306
306
 
307
- if (Porffor.rawType(onFinally) != Porffor.TYPES.function) onFinally = __Porffor_promise_noop;
307
+ if (Porffor.type(onFinally) != Porffor.TYPES.function) onFinally = __Porffor_promise_noop;
308
308
 
309
309
  const promise: any[] = _this;
310
310
  const state: i32 = promise[1];
@@ -472,7 +472,7 @@ export const __Promise_prototype_toLocaleString = (_this: any) => __Promise_prot
472
472
 
473
473
 
474
474
  export const __Porffor_promise_await = (value: any): any => {
475
- if (Porffor.rawType(value) != Porffor.TYPES.promise) return value;
475
+ if (Porffor.type(value) != Porffor.TYPES.promise) return value;
476
476
 
477
477
  // hack: peek value instead of awaiting
478
478
  const state: i32 = (value as any[])[1];
@@ -89,7 +89,7 @@ export const __Reflect_ownKeys = (target: any) => {
89
89
  const out: any[] = Porffor.allocate();
90
90
 
91
91
  target = __Porffor_object_underlying(target);
92
- const t: i32 = Porffor.rawType(target);
92
+ const t: i32 = Porffor.type(target);
93
93
  if (t == Porffor.TYPES.object) {
94
94
  let ptr: i32 = Porffor.wasm`local.get ${target}` + 8;
95
95
  const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(target, 0, 0) * 18;
@@ -172,7 +172,7 @@ export const Set = function (iterable: any): Set {
172
172
  };
173
173
 
174
174
  export const __Set_prototype_union = (_this: Set, other: any) => {
175
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
175
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
176
176
 
177
177
  const out: Set = new Set(_this);
178
178
  for (const x of other) {
@@ -183,7 +183,7 @@ export const __Set_prototype_union = (_this: Set, other: any) => {
183
183
  };
184
184
 
185
185
  export const __Set_prototype_intersection = (_this: Set, other: any) => {
186
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
186
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
187
187
 
188
188
  const out: Set = new Set(_this);
189
189
  for (const x of other) {
@@ -194,7 +194,7 @@ export const __Set_prototype_intersection = (_this: Set, other: any) => {
194
194
  };
195
195
 
196
196
  export const __Set_prototype_difference = (_this: Set, other: any) => {
197
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
197
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
198
198
 
199
199
  const out: Set = new Set(_this);
200
200
  for (const x of other) {
@@ -205,7 +205,7 @@ export const __Set_prototype_difference = (_this: Set, other: any) => {
205
205
  };
206
206
 
207
207
  export const __Set_prototype_symmetricDifference = (_this: Set, other: any) => {
208
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
208
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
209
209
 
210
210
  const out: Set = new Set(_this);
211
211
  for (const x of other) {
@@ -217,7 +217,7 @@ export const __Set_prototype_symmetricDifference = (_this: Set, other: any) => {
217
217
  };
218
218
 
219
219
  export const __Set_prototype_isSubsetOf = (_this: Set, other: any) => {
220
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
220
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
221
221
 
222
222
  for (const x of _this) {
223
223
  if (!other.has(x)) return false;
@@ -227,7 +227,7 @@ export const __Set_prototype_isSubsetOf = (_this: Set, other: any) => {
227
227
  };
228
228
 
229
229
  export const __Set_prototype_isSupersetOf = (_this: Set, other: any) => {
230
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
230
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
231
231
 
232
232
  for (const x of other) {
233
233
  if (!_this.has(x)) return false;
@@ -237,7 +237,7 @@ export const __Set_prototype_isSupersetOf = (_this: Set, other: any) => {
237
237
  };
238
238
 
239
239
  export const __Set_prototype_isDisjointFrom = (_this: Set, other: any) => {
240
- if (Porffor.rawType(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
240
+ if (Porffor.type(other) != Porffor.TYPES.set) throw new TypeError('other argument must be a Set');
241
241
 
242
242
  for (const x of _this) {
243
243
  if (other.has(x)) return false;
@@ -14,7 +14,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
14
14
  const value: any = args[0];
15
15
 
16
16
  // a. If NewTarget is undefined and value is a Symbol, return SymbolDescriptiveString(value).
17
- if (!new.target && Porffor.rawType(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
17
+ if (!new.target && Porffor.type(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
18
18
 
19
19
  // b. Let s be ? ToString(value).
20
20
  s = ecma262.ToString(value);
@@ -26,7 +26,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
26
26
  // 4. Return StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, "%String.prototype%")).
27
27
 
28
28
  // force bytestrings to strings
29
- if (Porffor.rawType(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
29
+ if (Porffor.type(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
30
30
 
31
31
  return s as StringObject;
32
32
  };
@@ -12,7 +12,7 @@ export const Symbol = (description: any): Symbol => {
12
12
  let descString: any = undefined;
13
13
 
14
14
  // 3. Else, let descString be ? ToString(description).
15
- if (Porffor.rawType(description) != Porffor.TYPES.undefined) {
15
+ if (Porffor.type(description) != Porffor.TYPES.undefined) {
16
16
  descString = ecma262.ToString(description);
17
17
  }
18
18
 
@@ -74,7 +74,7 @@ export const __Symbol_for = (key: any): Symbol => {
74
74
  };
75
75
 
76
76
  export const __Symbol_keyFor = (arg: any): any => {
77
- if (Porffor.rawType(arg) != Porffor.TYPES.symbol) throw new TypeError('Symbol.keyFor argument should be a Symbol');
77
+ if (Porffor.type(arg) != Porffor.TYPES.symbol) throw new TypeError('Symbol.keyFor argument should be a Symbol');
78
78
 
79
79
  const sym: Symbol = arg;
80
80
  const desc: any = sym.description;
@@ -18,7 +18,7 @@ export default async () => {
18
18
  let len: i32 = 0;
19
19
  let bufferPtr: i32;
20
20
 
21
- const type: i32 = Porffor.rawType(arg);
21
+ const type: i32 = Porffor.type(arg);
22
22
  if (Porffor.fastOr(
23
23
  type == Porffor.TYPES.arraybuffer,
24
24
  type == Porffor.TYPES.sharedarraybuffer
@@ -28,13 +28,13 @@ export default async () => {
28
28
  if (arg.detached) throw new TypeError('Constructed ${name} with a detached ArrayBuffer');
29
29
 
30
30
  let offset: i32 = 0;
31
- if (Porffor.rawType(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
31
+ if (Porffor.type(byteOffset) != Porffor.TYPES.undefined) offset = Math.trunc(byteOffset);
32
32
  if (offset < 0) throw new RangeError('Invalid DataView byte offset (negative)');
33
33
 
34
34
  Porffor.wasm.i32.store(outPtr, offset, 0, 8);
35
35
  Porffor.wasm.i32.store(outPtr, bufferPtr + offset, 0, 4);
36
36
 
37
- if (Porffor.rawType(length) == Porffor.TYPES.undefined) {
37
+ if (Porffor.type(length) == Porffor.TYPES.undefined) {
38
38
  const bufferLen: i32 = Porffor.wasm.i32.load(bufferPtr, 0, 0);
39
39
  len = (bufferLen - byteOffset) / ${name}.BYTES_PER_ELEMENT;
40
40
 
@@ -75,18 +75,18 @@ export const __${name}_from = (arg: any, mapFn: any): ${name} => {
75
75
  const arr: any[] = Porffor.allocate();
76
76
  let len: i32 = 0;
77
77
 
78
- const type = Porffor.rawType(arg);
78
+ const type = Porffor.type(arg);
79
79
  if (Porffor.fastOr(
80
80
  type == Porffor.TYPES.array,
81
81
  type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
82
82
  type == Porffor.TYPES.set,
83
83
  Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.float64array)
84
84
  )) {
85
- const hasMapFn = Porffor.rawType(mapFn) != Porffor.TYPES.undefined;
85
+ const hasMapFn = Porffor.type(mapFn) != Porffor.TYPES.undefined;
86
86
 
87
87
  let i: i32 = 0;
88
88
  if (hasMapFn) {
89
- if (Porffor.rawType(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
89
+ if (Porffor.type(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
90
90
 
91
91
  for (const x of arg) {
92
92
  arr[i] = mapFn(x, i);
@@ -132,7 +132,7 @@ export const __${name}_prototype_at = (_this: ${name}, index: number) => {
132
132
 
133
133
  export const __${name}_prototype_slice = (_this: ${name}, start: number, end: number) => {
134
134
  const len: i32 = _this.length;
135
- if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
135
+ if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
136
136
 
137
137
  start |= 0;
138
138
  end |= 0;
@@ -28,7 +28,7 @@ export const __ecma262_ToPrimitive_String = (input: any): any => {
28
28
  // 7.1.4 ToNumber (argument)
29
29
  // https://tc39.es/ecma262/#sec-tonumber
30
30
  export const __ecma262_ToNumber = (argument: unknown): number => {
31
- const t: i32 = Porffor.rawType(argument);
31
+ const t: i32 = Porffor.type(argument);
32
32
 
33
33
  // 1. If argument is a Number, return argument.
34
34
  if (t == Porffor.TYPES.number) return argument;
@@ -73,12 +73,12 @@ export const __ecma262_ToNumeric = (value: unknown): number => {
73
73
  // 1. Let primValue be ? ToPrimitive(value, number).
74
74
  // only run ToPrimitive if pure object for perf
75
75
  let primValue: any = value;
76
- if (Porffor.rawType(value) == Porffor.TYPES.object && Porffor.wasm`local.get ${value}` != 0)
76
+ if (Porffor.type(value) == Porffor.TYPES.object && Porffor.wasm`local.get ${value}` != 0)
77
77
  primValue = __ecma262_ToPrimitive_Number(value);
78
78
 
79
79
  // 2. If primValue is a BigInt, return primValue.
80
80
  if (Porffor.comptime.flag`hasType.bigint`) {
81
- if (Porffor.rawType(primValue) == Porffor.TYPES.bigint) return primValue;
81
+ if (Porffor.type(primValue) == Porffor.TYPES.bigint) return primValue;
82
82
  }
83
83
 
84
84
  // 3. Return ? ToNumber(primValue).
@@ -124,7 +124,7 @@ export const __ecma262_ToIndex = (value: unknown): number => {
124
124
  // 7.1.17 ToString (argument)
125
125
  // https://tc39.es/ecma262/#sec-tostring
126
126
  export const __ecma262_ToString = (argument: unknown): any => {
127
- const type: i32 = Porffor.rawType(argument);
127
+ const type: i32 = Porffor.type(argument);
128
128
 
129
129
  // 1. If argument is a String, return argument.
130
130
  if (Porffor.fastOr(
@@ -180,11 +180,11 @@ export const __ecma262_ToPropertyKey = (argument: any): any => {
180
180
  // 1. Let key be ? ToPrimitive(argument, string).
181
181
  // only run ToPrimitive if pure object for perf
182
182
  let key: any = argument;
183
- if (Porffor.rawType(argument) == Porffor.TYPES.object && Porffor.wasm`local.get ${argument}` != 0)
183
+ if (Porffor.type(argument) == Porffor.TYPES.object && Porffor.wasm`local.get ${argument}` != 0)
184
184
  key = __ecma262_ToPrimitive_String(argument);
185
185
 
186
186
  // 2. If key is a Symbol, then
187
- if (Porffor.rawType(key) == Porffor.TYPES.symbol) {
187
+ if (Porffor.type(key) == Porffor.TYPES.symbol) {
188
188
  // a. Return key.
189
189
  return key;
190
190
  }
@@ -194,6 +194,6 @@ export const __ecma262_ToPropertyKey = (argument: any): any => {
194
194
  };
195
195
 
196
196
  export const __ecma262_IsConstructor = (argument: any): boolean => {
197
- if (Porffor.rawType(argument) != Porffor.TYPES.function) return false;
197
+ if (Porffor.type(argument) != Porffor.TYPES.function) return false;
198
198
  return (__Porffor_funcLut_flags(argument) & 0b10) == 2;
199
199
  };
@@ -735,19 +735,18 @@ export const BuiltinFuncs = function() {
735
735
  this.__performance_now.usesImports = true;
736
736
 
737
737
 
738
- this.__Porffor_type = {
739
- params: [ valtypeBinary, Valtype.i32 ],
740
- typedParams: true,
741
- locals: [ Valtype.i32, Valtype.i32 ],
738
+ this.__Porffor_typeName = {
739
+ params: [ Valtype.i32 ],
740
+ locals: [],
742
741
  returns: [ valtypeBinary ],
743
742
  returnType: TYPES.bytestring,
744
743
  wasm: (scope, { typeSwitch, makeString }) => {
745
744
  const bc = {};
746
745
  for (const x in TYPE_NAMES) {
747
- bc[x] = makeString(scope, TYPE_NAMES[x]);
746
+ bc[x] = () => makeString(scope, TYPE_NAMES[x]);
748
747
  }
749
748
 
750
- return typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], bc);
749
+ return typeSwitch(scope, [ [ Opcodes.local_get, 0 ] ], bc);
751
750
  }
752
751
  };
753
752
 
@@ -15,7 +15,7 @@ export default function({ builtinFuncs }, Prefs) {
15
15
 
16
16
  builtinFuncs['#get_' + name] = {
17
17
  params: [],
18
- locals: [],
18
+ locals: [ Valtype.i32 ],
19
19
  returns: [ Valtype.i32 ],
20
20
  returnType: TYPES.object,
21
21
  wasm: (scope, { allocPage, makeString, generate, getNodeType, builtin, funcRef, glbl }) => {
@@ -41,7 +41,15 @@ export default function({ builtinFuncs }, Prefs) {
41
41
 
42
42
  // set cache & ptr for use
43
43
  number(ptr, Valtype.i32),
44
- glbl(Opcodes.global_set, `getptr_${name}`, Valtype.i32)[0]
44
+ [ Opcodes.local_tee, 0 ],
45
+ glbl(Opcodes.global_set, `getptr_${name}`, Valtype.i32)[0],
46
+
47
+ [ Opcodes.local_get, 0 ],
48
+ Opcodes.i32_from_u,
49
+ number(existingFunc ? TYPES.function : TYPES.object, Valtype.i32),
50
+ [ Opcodes.call, builtin('__Porffor_object_underlying') ],
51
+ [ Opcodes.drop ],
52
+ [ Opcodes.local_set, 0 ]
45
53
  ];
46
54
 
47
55
  for (const x in props) {
@@ -50,6 +58,20 @@ export default function({ builtinFuncs }, Prefs) {
50
58
  name: prefix + x
51
59
  };
52
60
 
61
+ if (x === '__proto__') {
62
+ out.push(
63
+ [ Opcodes.local_get, 0 ],
64
+ number(TYPES.object, Valtype.i32),
65
+
66
+ ...generate(scope, value),
67
+ Opcodes.i32_to_u,
68
+ ...getNodeType(scope, value),
69
+
70
+ [ Opcodes.call, builtin('__Porffor_object_setPrototype') ]
71
+ );
72
+ continue;
73
+ }
74
+
53
75
  let flags = 0b0000;
54
76
 
55
77
  const d = props[x];
@@ -61,8 +83,8 @@ export default function({ builtinFuncs }, Prefs) {
61
83
  if (this[prefix + x]?.type === TYPES.object && this[prefix + x] !== this.null) value = { type: 'ObjectExpression', properties: [] };
62
84
 
63
85
  out.push(
64
- getPtr,
65
- number(existingFunc ? TYPES.function : TYPES.object, Valtype.i32),
86
+ [ Opcodes.local_get, 0 ],
87
+ number(TYPES.object, Valtype.i32),
66
88
 
67
89
  ...makeString(scope, x),
68
90
  Opcodes.i32_to_u,
@@ -74,7 +96,7 @@ export default function({ builtinFuncs }, Prefs) {
74
96
  number(flags, Valtype.i32),
75
97
  number(TYPES.number, Valtype.i32),
76
98
 
77
- [ Opcodes.call, builtin('__Porffor_object_expr_initWithFlags') ]
99
+ [ Opcodes.call, builtin('__Porffor_object_fastAdd') ]
78
100
  );
79
101
  }
80
102