Skip to content

Commit f7e9275

Browse files
committed
builtins: rawType -> type, type -> typeName
less confusing naming test262: 56.41% | πŸ§ͺ 50373 | 🀠 28417 | ❌ 7205 | πŸ’€ 13733 (-1) | πŸ—οΈ 31 | πŸ’₯ 263 | ⏰ 7 (+1) | πŸ“ 717
1 parent 31a57c4 commit f7e9275

28 files changed

+185
-186
lines changed

β€Žcompiler/builtins.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -735,19 +735,18 @@ export const BuiltinFuncs = function() {
735735
this.__performance_now.usesImports = true;
736736

737737

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: [],
742741
returns: [ valtypeBinary ],
743742
returnType: TYPES.bytestring,
744743
wasm: (scope, { typeSwitch, makeString }) => {
745744
const bc = {};
746745
for (const x in TYPE_NAMES) {
747-
bc[x] = makeString(scope, TYPE_NAMES[x]);
746+
bc[x] = () => makeString(scope, TYPE_NAMES[x]);
748747
}
749748

750-
return typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], bc);
749+
return typeSwitch(scope, [ [ Opcodes.local_get, 0 ] ], bc);
751750
}
752751
};
753752

β€Žcompiler/builtins/_internal_object.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export const __Porffor_object_fastAdd = (obj: any, key: any, value: any, flags:
239239
// store underlying (real) objects for hidden types
240240
let underlyingStore: i32 = 0;
241241
export const __Porffor_object_underlying = (_obj: any): any => {
242-
if (Porffor.rawType(_obj) == Porffor.TYPES.object) {
242+
if (Porffor.type(_obj) == Porffor.TYPES.object) {
243243
Porffor.wasm`
244244
local.get ${_obj}
245245
i32.trunc_sat_f64_u
@@ -248,8 +248,8 @@ return`;
248248
}
249249

250250
if (Porffor.fastAnd(
251-
Porffor.rawType(_obj) >= Porffor.TYPES.error,
252-
Porffor.rawType(_obj) < 0x40
251+
Porffor.type(_obj) >= Porffor.TYPES.error,
252+
Porffor.type(_obj) < 0x40
253253
)) {
254254
Porffor.wasm`
255255
local.get ${_obj}
@@ -259,8 +259,8 @@ return`;
259259
}
260260

261261
if (Porffor.fastAnd(
262-
Porffor.rawType(_obj) > 0x05,
263-
Porffor.rawType(_obj) != Porffor.TYPES.undefined
262+
Porffor.type(_obj) > 0x05,
263+
Porffor.type(_obj) != Porffor.TYPES.undefined
264264
)) {
265265
if (underlyingStore == 0) underlyingStore = Porffor.allocate();
266266

@@ -280,7 +280,7 @@ local.set ${obj}`;
280280

281281
// it does not, make it
282282
const underlying: object = {};
283-
if (Porffor.rawType(_obj) == Porffor.TYPES.function) {
283+
if (Porffor.type(_obj) == Porffor.TYPES.function) {
284284
if (ecma262.IsConstructor(_obj)) { // constructor
285285
// set prototype and prototype.constructor if function and constructor
286286
const proto: object = {};
@@ -292,7 +292,7 @@ local.set ${obj}`;
292292
__Porffor_object_fastAdd(underlying, 'length', __Porffor_funcLut_length(obj), 0b0010);
293293
}
294294

295-
if (Porffor.rawType(_obj) == Porffor.TYPES.array) {
295+
if (Porffor.type(_obj) == Porffor.TYPES.array) {
296296
const len: i32 = Porffor.wasm.i32.load(obj, 0, 0);
297297
__Porffor_object_fastAdd(underlying, 'length', len, 0b1000);
298298

@@ -314,8 +314,8 @@ local.set x#type`;
314314
}
315315

316316
if (Porffor.fastOr(
317-
Porffor.rawType(_obj) == Porffor.TYPES.string,
318-
Porffor.rawType(_obj) == Porffor.TYPES.stringobject)
317+
Porffor.type(_obj) == Porffor.TYPES.string,
318+
Porffor.type(_obj) == Porffor.TYPES.stringobject)
319319
) {
320320
const len: i32 = (obj as string).length;
321321
__Porffor_object_fastAdd(underlying, 'length', len, 0b0000);
@@ -324,10 +324,10 @@ local.set x#type`;
324324
__Porffor_object_fastAdd(underlying, __Number_prototype_toString(i), (obj as string)[i], 0b0100);
325325
}
326326

327-
if (Porffor.rawType(_obj) == Porffor.TYPES.string) Porffor.wasm.i32.store8(obj, 0b0001, 0, 2); // make inextensible
327+
if (Porffor.type(_obj) == Porffor.TYPES.string) Porffor.wasm.i32.store8(obj, 0b0001, 0, 2); // make inextensible
328328
}
329329

330-
if (Porffor.rawType(_obj) == Porffor.TYPES.bytestring) {
330+
if (Porffor.type(_obj) == Porffor.TYPES.bytestring) {
331331
const len: i32 = (obj as bytestring).length;
332332
__Porffor_object_fastAdd(underlying, 'length', len, 0b0000);
333333

@@ -408,7 +408,7 @@ export const __Porffor_object_setPrototype = (obj: any, proto: any): void => {
408408

409409
if (__Porffor_object_isObjectOrNull(proto)) {
410410
Porffor.wasm.i32.store(obj, proto, 0, 4);
411-
Porffor.wasm.i32.store8(obj, Porffor.rawType(proto), 0, 3);
411+
Porffor.wasm.i32.store8(obj, Porffor.type(proto), 0, 3);
412412
}
413413
};
414414

β€Žcompiler/builtins/_internal_string.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {} from './porffor.d.ts';
22

33
export const __Porffor_compareStrings = (a: any, b: any): boolean => {
4-
let at: i32 = Porffor.rawType(a);
5-
let bt: i32 = Porffor.rawType(b);
4+
let at: i32 = Porffor.type(a);
5+
let bt: i32 = Porffor.type(b);
66

77
if ((at | 0b10000000) != Porffor.TYPES.bytestring) {
88
// a is not string or bytestring
@@ -36,8 +36,8 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
3636
};
3737

3838
export const __Porffor_concatStrings = (a: any, b: any): any => {
39-
let at: i32 = Porffor.rawType(a);
40-
let bt: i32 = Porffor.rawType(b);
39+
let at: i32 = Porffor.type(a);
40+
let bt: i32 = Porffor.type(b);
4141

4242
if ((at | 0b10000000) != Porffor.TYPES.bytestring) {
4343
// a is not string or bytestring

β€Žcompiler/builtins/array.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const Array = function (...args: any[]): any[] {
1111
if (argsLen == 1) {
1212
// 1 arg, length (number) or first element (non-number)
1313
const arg: any = args[0];
14-
if (Porffor.rawType(arg) == Porffor.TYPES.number) {
14+
if (Porffor.type(arg) == Porffor.TYPES.number) {
1515
// number so use as length
1616
const n: number = args[0];
1717
if (Porffor.fastOr(
@@ -33,24 +33,24 @@ export const Array = function (...args: any[]): any[] {
3333
};
3434

3535
export const __Array_isArray = (x: unknown): boolean =>
36-
Porffor.rawType(x) == Porffor.TYPES.array;
36+
Porffor.type(x) == Porffor.TYPES.array;
3737

3838
export const __Array_from = (arg: any, mapFn: any): any[] => {
3939
if (arg == null) throw new TypeError('Argument cannot be nullish');
4040

4141
let out: any[] = Porffor.allocate();
4242
let len: i32 = 0;
4343

44-
const type = Porffor.rawType(arg);
44+
const type = Porffor.type(arg);
4545
if (Porffor.fastOr(
4646
type == Porffor.TYPES.array,
4747
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
4848
type == Porffor.TYPES.set,
4949
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.float64array)
5050
)) {
5151
let i: i32 = 0;
52-
if (Porffor.rawType(mapFn) != Porffor.TYPES.undefined) {
53-
if (Porffor.rawType(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
52+
if (Porffor.type(mapFn) != Porffor.TYPES.undefined) {
53+
if (Porffor.type(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
5454

5555
for (const x of arg) {
5656
out[i] = mapFn(x, i);
@@ -132,7 +132,7 @@ memory.copy 0 0`;
132132

133133
export const __Array_prototype_slice = (_this: any[], _start: any, _end: any) => {
134134
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;
136136

137137
let start: i32 = ecma262.ToIntegerOrInfinity(_start);
138138
let end: i32 = ecma262.ToIntegerOrInfinity(_end);
@@ -181,7 +181,7 @@ export const __Array_prototype_splice = (_this: any[], _start: any, _deleteCount
181181
}
182182
if (start > len) start = len;
183183

184-
if (Porffor.rawType(_deleteCount) == Porffor.TYPES.undefined) _deleteCount = len - start;
184+
if (Porffor.type(_deleteCount) == Porffor.TYPES.undefined) _deleteCount = len - start;
185185
let deleteCount: i32 = ecma262.ToIntegerOrInfinity(_deleteCount);
186186

187187
if (deleteCount < 0) deleteCount = 0;
@@ -272,8 +272,8 @@ memory.copy 0 0`;
272272
export const __Array_prototype_fill = (_this: any[], value: any, _start: any, _end: any) => {
273273
const len: i32 = _this.length;
274274

275-
if (Porffor.rawType(_start) == Porffor.TYPES.undefined) _start = 0;
276-
if (Porffor.rawType(_end) == Porffor.TYPES.undefined) _end = len;
275+
if (Porffor.type(_start) == Porffor.TYPES.undefined) _start = 0;
276+
if (Porffor.type(_end) == Porffor.TYPES.undefined) _end = len;
277277

278278
let start: i32 = ecma262.ToIntegerOrInfinity(_start);
279279
let end: i32 = ecma262.ToIntegerOrInfinity(_end);
@@ -392,7 +392,7 @@ export const __Array_prototype_copyWithin = (_this: any[], _target: any, _start:
392392
if (start > len) start = len;
393393

394394
let end: i32;
395-
if (Porffor.rawType(_end) == Porffor.TYPES.undefined) {
395+
if (Porffor.type(_end) == Porffor.TYPES.undefined) {
396396
end = len;
397397
} else {
398398
end = ecma262.ToIntegerOrInfinity(_end);
@@ -419,7 +419,7 @@ export const __Array_prototype_concat = (_this: any[], ...vals: any[]) => {
419419
let len: i32 = _this.length;
420420

421421
for (const x of vals) {
422-
if (Porffor.rawType(x) & 0b01000000) { // value is iterable
422+
if (Porffor.type(x) & 0b01000000) { // value is iterable
423423
// todo: for..of is broken here because ??
424424
const l: i32 = x.length;
425425
for (let i: i32 = 0; i < l; i++) {
@@ -497,7 +497,7 @@ export const __Array_prototype_flatMap = (_this: any[], callbackFn: any, thisArg
497497
let i: i32 = 0, j: i32 = 0;
498498
while (i < len) {
499499
let x: any = callbackFn.call(thisArg, _this[i], i++, _this);
500-
if (Porffor.rawType(x) == Porffor.TYPES.array) {
500+
if (Porffor.type(x) == Porffor.TYPES.array) {
501501
for (const y of x) out[j++] = y;
502502
} else out[j++] = x;
503503
}
@@ -646,8 +646,8 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
646646

647647
// 23.1.3.30.2 CompareArrayElements (x, y, comparefn)
648648
// https://tc39.es/ecma262/#sec-comparearrayelements
649-
const xt: i32 = Porffor.rawType(x);
650-
const yt: i32 = Porffor.rawType(y);
649+
const xt: i32 = Porffor.type(x);
650+
const yt: i32 = Porffor.type(y);
651651
let v: number;
652652

653653
// 1. If x and y are both undefined, return +0𝔽.
@@ -690,7 +690,7 @@ export const __Array_prototype_toString = (_this: any[]) => {
690690
if (i > 0) Porffor.bytestring.appendChar(out, 44);
691691

692692
const element: any = _this[i++];
693-
const type: i32 = Porffor.rawType(element);
693+
const type: i32 = Porffor.type(element);
694694
if (element != 0 || Porffor.fastAnd(
695695
type != Porffor.TYPES.undefined, // undefined
696696
type != Porffor.TYPES.object // null
@@ -712,7 +712,7 @@ export const __Array_prototype_join = (_this: any[], _separator: any) => {
712712
// todo/perf: optimize default separator (?)
713713

714714
let separator: bytestring = ',';
715-
if (Porffor.rawType(_separator) != Porffor.TYPES.undefined)
715+
if (Porffor.type(_separator) != Porffor.TYPES.undefined)
716716
separator = ecma262.ToString(_separator);
717717

718718
let out: bytestring = Porffor.allocate();
@@ -722,7 +722,7 @@ export const __Array_prototype_join = (_this: any[], _separator: any) => {
722722
if (i > 0) Porffor.bytestring.appendStr(out, separator);
723723

724724
const element: any = _this[i++];
725-
const type: i32 = Porffor.rawType(element);
725+
const type: i32 = Porffor.type(element);
726726
if (element != 0 || Porffor.fastAnd(
727727
type != Porffor.TYPES.undefined, // undefined
728728
type != Porffor.TYPES.object // null
@@ -780,7 +780,7 @@ export const __Array_prototype_toSpliced = (_this: any[], _start: any, _deleteCo
780780
}
781781
if (start > len) start = len;
782782

783-
if (Porffor.rawType(_deleteCount) == Porffor.TYPES.undefined) _deleteCount = len - start;
783+
if (Porffor.type(_deleteCount) == Porffor.TYPES.undefined) _deleteCount = len - start;
784784
let deleteCount: i32 = ecma262.ToIntegerOrInfinity(_deleteCount);
785785

786786
if (deleteCount < 0) deleteCount = 0;
@@ -853,7 +853,7 @@ memory.copy 0 0`;
853853

854854

855855
export const __Array_prototype_flat = (_this: any[], _depth: any) => {
856-
if (Porffor.rawType(_depth) == Porffor.TYPES.undefined) _depth = 1;
856+
if (Porffor.type(_depth) == Porffor.TYPES.undefined) _depth = 1;
857857
let depth: i32 = ecma262.ToIntegerOrInfinity(_depth);
858858

859859
let out: any[] = Porffor.allocate();
@@ -866,7 +866,7 @@ export const __Array_prototype_flat = (_this: any[], _depth: any) => {
866866
let i: i32 = 0, j: i32 = 0;
867867
while (i < len) {
868868
let x: any = _this[i++];
869-
if (Porffor.rawType(x) == Porffor.TYPES.array) {
869+
if (Porffor.type(x) == Porffor.TYPES.array) {
870870
if (depth > 1) x = __Array_prototype_flat(x, depth - 1);
871871
for (const y of x) out[j++] = y;
872872
} else out[j++] = x;

β€Žcompiler/builtins/arraybuffer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {} from './porffor.d.ts';
22

33
export const __ArrayBuffer_isView = (value: any): boolean => {
4-
const t: i32 = Porffor.rawType(value);
4+
const t: i32 = Porffor.type(value);
55
if (Porffor.fastOr(
66
t == Porffor.TYPES.dataview,
77
Porffor.fastAnd(t >= Porffor.TYPES.uint8array, t <= Porffor.TYPES.float64array)
@@ -84,7 +84,7 @@ export const __ArrayBuffer_prototype_slice = (_this: ArrayBuffer, start: any, en
8484
if (_this.detached) throw new TypeError('Called ArrayBuffer.prototype.slice on a detached ArrayBuffer');
8585

8686
const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
87-
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
87+
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
8888

8989
start = ecma262.ToIntegerOrInfinity(start);
9090
end = ecma262.ToIntegerOrInfinity(end);
@@ -136,7 +136,7 @@ export const __ArrayBuffer_prototype_transfer = (_this: ArrayBuffer, newLength:
136136
if (_this.detached) throw new TypeError('Called ArrayBuffer.prototype.transfer on a detached ArrayBuffer');
137137

138138
const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
139-
if (Porffor.rawType(newLength) == Porffor.TYPES.undefined) newLength = len;
139+
if (Porffor.type(newLength) == Porffor.TYPES.undefined) newLength = len;
140140

141141
// make new arraybuffer
142142
const out: ArrayBuffer = new ArrayBuffer(newLength);
@@ -208,7 +208,7 @@ export const __SharedArrayBuffer_prototype_growable$get = (_this: SharedArrayBuf
208208

209209
export const __SharedArrayBuffer_prototype_slice = (_this: SharedArrayBuffer, start: any, end: any) => {
210210
const len: i32 = Porffor.wasm.i32.load(_this, 0, 0);
211-
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
211+
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
212212

213213
start = ecma262.ToIntegerOrInfinity(start);
214214
end = ecma262.ToIntegerOrInfinity(end);

β€Žcompiler/builtins/bigint.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ export const __ecma262_ToBigInt = (argument: any): bigint => {
280280
// Table 12: BigInt Conversions
281281
// Argument Type Result
282282
// BigInt Return prim.
283-
if (Porffor.rawType(prim) == Porffor.TYPES.bigint) return prim;
283+
if (Porffor.type(prim) == Porffor.TYPES.bigint) return prim;
284284

285285
// String
286286
// 1. Let n be StringToBigInt(prim).
287287
// 2. If n is undefined, throw a SyntaxError exception.
288288
// 3. Return n.
289-
if ((Porffor.rawType(prim) | 0b10000000) == Porffor.TYPES.bytestring) return __Porffor_bigint_fromString(prim);
289+
if ((Porffor.type(prim) | 0b10000000) == Porffor.TYPES.bytestring) return __Porffor_bigint_fromString(prim);
290290

291291
// Boolean Return 1n if prim is true and 0n if prim is false.
292-
if (Porffor.rawType(prim) == Porffor.TYPES.boolean) return prim ? 1n : 0n;
292+
if (Porffor.type(prim) == Porffor.TYPES.boolean) return prim ? 1n : 0n;
293293

294294
// Number Throw a TypeError exception.
295295
// Symbol Throw a TypeError exception.
@@ -306,7 +306,7 @@ export const BigInt = (value: any): bigint => {
306306
const prim: any = ecma262.ToPrimitive.Number(value);
307307

308308
// 3. If prim is a Number, return ? NumberToBigInt(prim).
309-
if (Porffor.rawType(prim) == Porffor.TYPES.number) return __Porffor_bigint_fromNumber(prim);
309+
if (Porffor.type(prim) == Porffor.TYPES.number) return __Porffor_bigint_fromNumber(prim);
310310

311311
// 4. Otherwise, return ? ToBigInt(prim).
312312
return __ecma262_ToBigInt(prim);

0 commit comments

Comments
Β (0)