porffor 0.55.22 → 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.
- package/compiler/allocator.js +1 -1
- package/compiler/builtins/_internal_object.ts +560 -279
- package/compiler/builtins/bigint.ts +2 -2
- package/compiler/builtins/function.ts +1 -1
- package/compiler/builtins/object.ts +35 -44
- package/compiler/builtins/object_prototypeWithHidden.js +47 -0
- package/compiler/builtins/reflect.ts +4 -4
- package/compiler/builtins/z_ecma262.ts +3 -0
- package/compiler/builtins_precompiled.js +569 -550
- package/compiler/codegen.js +67 -143
- package/compiler/precompile.js +6 -5
- package/compiler/prototype.js +80 -66
- package/compiler/wrap.js +3 -4
- package/package.json +1 -1
- package/r.cjs +29 -6
- package/runner/index.js +1 -1
@@ -127,9 +127,9 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
|
|
127
127
|
return __Porffor_bigint_fromDigits(negative, result);
|
128
128
|
};
|
129
129
|
|
130
|
-
export const __Porffor_bigint_toString = (x: number, radix: any): string => {
|
130
|
+
export const __Porffor_bigint_toString = (x: number, radix: any): string|bytestring => {
|
131
131
|
// todo: actually use bigint
|
132
|
-
return
|
132
|
+
return __Number_prototype_toString(Math.trunc(__Porffor_bigint_toNumber(x)), radix);
|
133
133
|
};
|
134
134
|
|
135
135
|
// todo: hook up all funcs below to codegen
|
@@ -13,7 +13,7 @@ export const __Function_prototype_toLocaleString = (_this: Function) => __Functi
|
|
13
13
|
|
14
14
|
export const __Function_prototype_apply = (_this: Function, thisArg: any, argsArray: any) => {
|
15
15
|
argsArray = Array.from(argsArray ?? []);
|
16
|
-
return
|
16
|
+
return Porffor.call(_this, argsArray, thisArg, null);
|
17
17
|
};
|
18
18
|
|
19
19
|
export const __Function_prototype_bind = (_this: Function, thisArg: any, argsArray: any) => {
|
@@ -3,8 +3,7 @@ import type {} from './porffor.d.ts';
|
|
3
3
|
export const Object = function (value: any): any {
|
4
4
|
if (value == null) {
|
5
5
|
// if nullish, return new empty object
|
6
|
-
|
7
|
-
return obj;
|
6
|
+
return Porffor.allocate() as object;
|
8
7
|
}
|
9
8
|
|
10
9
|
// primitives into primitive objects
|
@@ -23,11 +22,11 @@ export const __Object_keys = (obj: any): any[] => {
|
|
23
22
|
obj = __Porffor_object_underlying(obj);
|
24
23
|
const t: i32 = Porffor.rawType(obj);
|
25
24
|
if (t == Porffor.TYPES.object) {
|
26
|
-
let ptr: i32 = Porffor.wasm`local.get ${obj}` +
|
27
|
-
const endPtr: i32 = ptr + Porffor.wasm.i32.
|
25
|
+
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
26
|
+
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
28
27
|
|
29
28
|
let i: i32 = 0;
|
30
|
-
for (; ptr < endPtr; ptr +=
|
29
|
+
for (; ptr < endPtr; ptr += 18) {
|
31
30
|
if (!Porffor.object.isEnumerable(ptr)) continue;
|
32
31
|
|
33
32
|
let key: any;
|
@@ -35,7 +34,7 @@ export const __Object_keys = (obj: any): any[] => {
|
|
35
34
|
local msb i32
|
36
35
|
local.get ${ptr}
|
37
36
|
i32.to_u
|
38
|
-
i32.load 0
|
37
|
+
i32.load 0 4
|
39
38
|
local.set raw
|
40
39
|
|
41
40
|
local.get raw
|
@@ -79,11 +78,11 @@ export const __Object_values = (obj: any): any[] => {
|
|
79
78
|
obj = __Porffor_object_underlying(obj);
|
80
79
|
const t: i32 = Porffor.rawType(obj);
|
81
80
|
if (t == Porffor.TYPES.object) {
|
82
|
-
let ptr: i32 = Porffor.wasm`local.get ${obj}` +
|
83
|
-
const endPtr: i32 = ptr + Porffor.wasm.i32.
|
81
|
+
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
82
|
+
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
84
83
|
|
85
84
|
let i: i32 = 0;
|
86
|
-
for (; ptr < endPtr; ptr +=
|
85
|
+
for (; ptr < endPtr; ptr += 18) {
|
87
86
|
if (!Porffor.object.isEnumerable(ptr)) continue;
|
88
87
|
|
89
88
|
let val: any;
|
@@ -92,11 +91,11 @@ local.get ${ptr}
|
|
92
91
|
i32.to_u
|
93
92
|
local.tee ptr32
|
94
93
|
|
95
|
-
f64.load 0
|
94
|
+
f64.load 0 8
|
96
95
|
local.set ${val}
|
97
96
|
|
98
97
|
local.get ptr32
|
99
|
-
i32.load8_u 0
|
98
|
+
i32.load8_u 0 17
|
100
99
|
local.set ${val+1}`;
|
101
100
|
|
102
101
|
out[i++] = val;
|
@@ -165,17 +164,19 @@ export const __Object_hasOwn = (obj: any, prop: any): boolean => {
|
|
165
164
|
};
|
166
165
|
|
167
166
|
export const __Porffor_object_in = (obj: any, prop: any): boolean => {
|
167
|
+
// todo: throw if obj is not an object
|
168
|
+
|
168
169
|
if (__Object_prototype_hasOwnProperty(obj, prop)) {
|
169
170
|
return true;
|
170
171
|
}
|
171
172
|
|
172
173
|
let lastProto = obj;
|
173
174
|
while (true) {
|
174
|
-
obj = obj
|
175
|
+
obj = Porffor.object.getPrototypeWithHidden(obj);
|
175
176
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
176
|
-
lastProto = obj;
|
177
177
|
|
178
178
|
if (__Object_prototype_hasOwnProperty(obj, prop)) return true;
|
179
|
+
lastProto = obj;
|
179
180
|
}
|
180
181
|
|
181
182
|
return false;
|
@@ -192,11 +193,11 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
|
|
192
193
|
|
193
194
|
let lastProto = obj;
|
194
195
|
while (true) {
|
195
|
-
obj = obj
|
196
|
+
obj = Porffor.object.getPrototypeWithHidden(obj);
|
196
197
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
197
|
-
lastProto = obj;
|
198
198
|
|
199
199
|
if (obj === checkProto) return true;
|
200
|
+
lastProto = obj;
|
200
201
|
}
|
201
202
|
|
202
203
|
return false;
|
@@ -275,11 +276,10 @@ export const __Object_is = (x: any, y: any): boolean => {
|
|
275
276
|
|
276
277
|
export const __Object_preventExtensions = (obj: any): any => {
|
277
278
|
Porffor.object.preventExtensions(obj);
|
278
|
-
|
279
279
|
return obj;
|
280
280
|
};
|
281
281
|
|
282
|
-
export const __Object_isExtensible = (obj: any):
|
282
|
+
export const __Object_isExtensible = (obj: any): boolean => {
|
283
283
|
if (!Porffor.object.isObject(obj)) {
|
284
284
|
return false;
|
285
285
|
}
|
@@ -298,7 +298,7 @@ export const __Object_freeze = (obj: any): any => {
|
|
298
298
|
return obj;
|
299
299
|
};
|
300
300
|
|
301
|
-
export const __Object_isFrozen = (obj: any):
|
301
|
+
export const __Object_isFrozen = (obj: any): boolean => {
|
302
302
|
if (!Porffor.object.isObject(obj)) {
|
303
303
|
return true;
|
304
304
|
}
|
@@ -323,7 +323,7 @@ export const __Object_seal = (obj: any): any => {
|
|
323
323
|
return obj;
|
324
324
|
};
|
325
325
|
|
326
|
-
export const __Object_isSealed = (obj: any):
|
326
|
+
export const __Object_isSealed = (obj: any): boolean => {
|
327
327
|
if (!Porffor.object.isObject(obj)) {
|
328
328
|
return true;
|
329
329
|
}
|
@@ -360,9 +360,8 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
|
|
360
360
|
return undefined;
|
361
361
|
}
|
362
362
|
|
363
|
+
const tail: i32 = Porffor.wasm.i32.load16_u(entryPtr, 0, 16);
|
363
364
|
const out: object = {};
|
364
|
-
|
365
|
-
const tail: i32 = Porffor.wasm.i32.load16_u(entryPtr, 0, 12);
|
366
365
|
out.configurable = !!(tail & 0b0010);
|
367
366
|
out.enumerable = !!(tail & 0b0100);
|
368
367
|
|
@@ -374,7 +373,7 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
|
|
374
373
|
}
|
375
374
|
|
376
375
|
// data descriptor
|
377
|
-
const value: any = Porffor.wasm.f64.load(entryPtr, 0,
|
376
|
+
const value: any = Porffor.wasm.f64.load(entryPtr, 0, 8);
|
378
377
|
Porffor.wasm`
|
379
378
|
local.get ${tail}
|
380
379
|
i32.to_u
|
@@ -412,17 +411,17 @@ export const __Object_getOwnPropertyNames = (obj: any): any[] => {
|
|
412
411
|
obj = __Porffor_object_underlying(obj);
|
413
412
|
const t: i32 = Porffor.rawType(obj);
|
414
413
|
if (t == Porffor.TYPES.object) {
|
415
|
-
let ptr: i32 = Porffor.wasm`local.get ${obj}` +
|
416
|
-
const endPtr: i32 = ptr + Porffor.wasm.i32.
|
414
|
+
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
415
|
+
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
417
416
|
|
418
417
|
let i: i32 = 0;
|
419
|
-
for (; ptr < endPtr; ptr +=
|
418
|
+
for (; ptr < endPtr; ptr += 18) {
|
420
419
|
let key: any;
|
421
420
|
Porffor.wasm`local raw i32
|
422
421
|
local msb i32
|
423
422
|
local.get ${ptr}
|
424
423
|
i32.to_u
|
425
|
-
i32.load 0
|
424
|
+
i32.load 0 4
|
426
425
|
local.set raw
|
427
426
|
|
428
427
|
local.get raw
|
@@ -467,17 +466,17 @@ export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
|
|
467
466
|
obj = __Porffor_object_underlying(obj);
|
468
467
|
const t: i32 = Porffor.rawType(obj);
|
469
468
|
if (t == Porffor.TYPES.object) {
|
470
|
-
let ptr: i32 = Porffor.wasm`local.get ${obj}` +
|
471
|
-
const endPtr: i32 = ptr + Porffor.wasm.i32.
|
469
|
+
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
470
|
+
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
472
471
|
|
473
472
|
let i: i32 = 0;
|
474
|
-
for (; ptr < endPtr; ptr +=
|
473
|
+
for (; ptr < endPtr; ptr += 18) {
|
475
474
|
let key: any;
|
476
475
|
Porffor.wasm`local raw i32
|
477
476
|
local msb i32
|
478
477
|
local.get ${ptr}
|
479
478
|
i32.to_u
|
480
|
-
i32.load 0
|
479
|
+
i32.load 0 4
|
481
480
|
local.set raw
|
482
481
|
|
483
482
|
local.get raw
|
@@ -609,9 +608,7 @@ export const __Object_create = (proto: any, props: any): object => {
|
|
609
608
|
if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
|
610
609
|
|
611
610
|
const out: object = {};
|
612
|
-
|
613
|
-
// set prototype
|
614
|
-
out.__proto__ = proto;
|
611
|
+
Porffor.object.setPrototype(out, proto);
|
615
612
|
|
616
613
|
if (props !== undefined) __Object_defineProperties(out, props);
|
617
614
|
|
@@ -639,30 +636,24 @@ export const __Object_groupBy = (items: any, callbackFn: any): object => {
|
|
639
636
|
|
640
637
|
export const __Object_getPrototypeOf = (obj: any): any => {
|
641
638
|
if (obj == null) throw new TypeError('Object is nullish, expected object');
|
642
|
-
|
643
|
-
return obj.__proto__;
|
639
|
+
return Porffor.object.getPrototypeWithHidden(obj);
|
644
640
|
};
|
645
641
|
|
646
642
|
export const __Object_setPrototypeOf = (obj: any, proto: any): any => {
|
647
643
|
if (obj == null) throw new TypeError('Object is nullish, expected object');
|
648
644
|
if (!Porffor.object.isObjectOrNull(proto)) throw new TypeError('Prototype should be an object or null');
|
649
645
|
|
650
|
-
// todo:
|
651
|
-
if (Porffor.rawType(obj) != Porffor.TYPES.object) {
|
652
|
-
return obj;
|
653
|
-
}
|
654
|
-
|
655
|
-
// todo: throw when this fails?
|
656
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf#exceptions
|
657
|
-
obj.__proto__ = proto;
|
646
|
+
// todo: if inextensible, throw if proto != current prototype
|
658
647
|
|
648
|
+
Porffor.object.setPrototype(obj, proto);
|
659
649
|
return obj;
|
660
650
|
};
|
661
651
|
|
662
652
|
export const __Object_prototype_isPrototypeOf = (_this: any, obj: any) => {
|
663
653
|
if (_this == null) throw new TypeError('This is nullish, expected object');
|
664
654
|
|
665
|
-
|
655
|
+
if (!Porffor.object.isObject(obj)) return false;
|
656
|
+
return _this == Porffor.object.getPrototypeWithHidden(obj);
|
666
657
|
};
|
667
658
|
|
668
659
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
export default ({ TYPES, TYPE_NAMES }) => {
|
2
|
+
let out = `// @porf --valtype=i32
|
3
|
+
export const __Porffor_object_getPrototypeWithHidden = (obj: any, trueType: i32 = Porffor.wasm\`local.get \${obj+1}\`): any => {
|
4
|
+
const objectProto: any = __Porffor_object_getPrototype(obj);
|
5
|
+
if (Porffor.rawType(objectProto) == Porffor.TYPES.empty) {
|
6
|
+
if (Porffor.comptime.flag\`hasFunc.#get___String_prototype\`) {
|
7
|
+
if (Porffor.fastOr(
|
8
|
+
trueType == Porffor.TYPES.string,
|
9
|
+
trueType == Porffor.TYPES.bytestring,
|
10
|
+
trueType == Porffor.TYPES.stringobject
|
11
|
+
)) return __String_prototype;
|
12
|
+
}
|
13
|
+
|
14
|
+
if (Porffor.comptime.flag\`hasFunc.#get___Number_prototype\`) {
|
15
|
+
if (Porffor.fastOr(
|
16
|
+
trueType == Porffor.TYPES.number,
|
17
|
+
trueType == Porffor.TYPES.numberobject
|
18
|
+
)) return __Number_prototype;
|
19
|
+
}
|
20
|
+
|
21
|
+
if (Porffor.comptime.flag\`hasFunc.#get___Boolean_prototype\`) {
|
22
|
+
if (Porffor.fastOr(
|
23
|
+
trueType == Porffor.TYPES.boolean,
|
24
|
+
trueType == Porffor.TYPES.booleanobject
|
25
|
+
)) return __Boolean_prototype;
|
26
|
+
}`;
|
27
|
+
|
28
|
+
for (const x in TYPES) {
|
29
|
+
if (['empty', 'undefined', 'string', 'bytestring', 'stringobject', 'number', 'numberobject', 'boolean', 'booleanobject'].includes(x)) continue;
|
30
|
+
|
31
|
+
const name = TYPE_NAMES[TYPES[x]];
|
32
|
+
out += `
|
33
|
+
if (Porffor.comptime.flag\`hasFunc.#get___${name}_prototype\`) {
|
34
|
+
if (trueType == Porffor.TYPES.${x}) return __${name}_prototype;
|
35
|
+
}`;
|
36
|
+
}
|
37
|
+
|
38
|
+
// if (trueType == Porffor.TYPES.function) return __Function_prototype;
|
39
|
+
out += `
|
40
|
+
return __Object_prototype;
|
41
|
+
}
|
42
|
+
|
43
|
+
return objectProto;
|
44
|
+
};`;
|
45
|
+
|
46
|
+
return out;
|
47
|
+
};
|
@@ -91,17 +91,17 @@ export const __Reflect_ownKeys = (target: any) => {
|
|
91
91
|
target = __Porffor_object_underlying(target);
|
92
92
|
const t: i32 = Porffor.rawType(target);
|
93
93
|
if (t == Porffor.TYPES.object) {
|
94
|
-
let ptr: i32 = Porffor.wasm`local.get ${target}` +
|
95
|
-
const endPtr: i32 = ptr + Porffor.wasm.i32.
|
94
|
+
let ptr: i32 = Porffor.wasm`local.get ${target}` + 8;
|
95
|
+
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(target, 0, 0) * 18;
|
96
96
|
|
97
97
|
let i: i32 = 0;
|
98
|
-
for (; ptr < endPtr; ptr +=
|
98
|
+
for (; ptr < endPtr; ptr += 18) {
|
99
99
|
let key: any;
|
100
100
|
Porffor.wasm`local raw i32
|
101
101
|
local msb i32
|
102
102
|
local.get ${ptr}
|
103
103
|
i32.to_u
|
104
|
-
i32.load 0
|
104
|
+
i32.load 0 4
|
105
105
|
local.set raw
|
106
106
|
|
107
107
|
local.get raw
|
@@ -156,6 +156,9 @@ export const __ecma262_ToString = (argument: unknown): any => {
|
|
156
156
|
if (type == Porffor.TYPES.number) return __Number_prototype_toString(argument, 10);
|
157
157
|
|
158
158
|
// 8. If argument is a BigInt, return BigInt::toString(argument, 10).
|
159
|
+
if (Porffor.comptime.flag`hasType.bigint`) {
|
160
|
+
if (type == Porffor.TYPES.bigint) return __Porffor_bigint_toString(argument, 10);
|
161
|
+
}
|
159
162
|
|
160
163
|
// hack: StringObject -> String
|
161
164
|
if (type == Porffor.TYPES.stringobject) {
|