porffor 0.61.1 → 0.61.2
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/builtins/_internal_object.ts +1 -1
- package/compiler/builtins/annexb_string.js +5 -4
- package/compiler/builtins/array.ts +16 -16
- package/compiler/builtins/arraybuffer.ts +4 -4
- package/compiler/builtins/base64.ts +2 -2
- package/compiler/builtins/bigint.ts +5 -5
- package/compiler/builtins/crypto.ts +1 -1
- package/compiler/builtins/dataview.ts +1 -1
- package/compiler/builtins/date.ts +9 -9
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/function.ts +1 -1
- package/compiler/builtins/json.ts +5 -5
- package/compiler/builtins/map.ts +5 -5
- package/compiler/builtins/number.ts +3 -3
- package/compiler/builtins/object.ts +8 -8
- package/compiler/builtins/porffor.d.ts +2 -2
- package/compiler/builtins/promise.ts +9 -9
- package/compiler/builtins/reflect.ts +1 -1
- package/compiler/builtins/regexp.ts +319 -388
- package/compiler/builtins/set.ts +2 -2
- package/compiler/builtins/string.ts +42 -42
- package/compiler/builtins/string_f64.ts +2 -2
- package/compiler/builtins/symbol.ts +2 -2
- package/compiler/builtins/typedarray.js +5 -5
- package/compiler/builtins/uint8array_base64.ts +2 -2
- package/compiler/builtins/uri.ts +145 -145
- package/compiler/builtins/weakmap.ts +3 -3
- package/compiler/builtins/weakref.ts +1 -1
- package/compiler/builtins/weakset.ts +1 -1
- package/compiler/builtins.js +43 -75
- package/compiler/builtins_precompiled.js +682 -676
- package/compiler/codegen.js +16 -11
- package/compiler/wrap.js +13 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/runtime/index.js +1 -1
|
@@ -153,7 +153,7 @@ return`;
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
if (Porffor.type(_obj) > 0x05) {
|
|
156
|
-
if (underlyingStore == 0) underlyingStore = Porffor.
|
|
156
|
+
if (underlyingStore == 0) underlyingStore = Porffor.malloc();
|
|
157
157
|
|
|
158
158
|
// check if underlying object already exists for obj
|
|
159
159
|
const underlyingLength: i32 = Porffor.wasm.i32.load(underlyingStore, 0, 0);
|
|
@@ -21,16 +21,17 @@ export const __ByteString_prototype_${a0} = (_this: bytestring) =>
|
|
|
21
21
|
const arg = (name, s1, s2) => out += `
|
|
22
22
|
export const __String_prototype_${name} = (_this: string, arg: any) => {
|
|
23
23
|
arg = ecma262.ToString(arg);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const len: i32 = arg.length;
|
|
25
|
+
const escaped: bytestring = Porffor.malloc(4 + len * 6); // overallocate in case of "s
|
|
26
|
+
for (let i: i32 = 0; i < len; i++) {
|
|
27
|
+
const c: i32 = arg.charCodeAt(i);
|
|
27
28
|
if (c != 34) {
|
|
28
29
|
__Porffor_bytestring_appendChar(escaped, c);
|
|
29
30
|
} else {
|
|
30
31
|
__Porffor_bytestring_appendStr(escaped, '"');
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
return Porffor.concatStrings(
|
|
35
36
|
Porffor.concatStrings(
|
|
36
37
|
Porffor.concatStrings(
|
|
@@ -4,7 +4,7 @@ export const Array = function (...args: any[]): any[] {
|
|
|
4
4
|
const argsLen: number = args.length;
|
|
5
5
|
if (argsLen == 0) {
|
|
6
6
|
// 0 args, new 0 length array
|
|
7
|
-
const out: any[] = Porffor.
|
|
7
|
+
const out: any[] = Porffor.malloc();
|
|
8
8
|
return out;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ export const Array = function (...args: any[]): any[] {
|
|
|
20
20
|
!Number.isInteger(n) // non-integer/non-finite
|
|
21
21
|
)) throw new RangeError('Invalid array length');
|
|
22
22
|
|
|
23
|
-
const out: any[] = Porffor.
|
|
23
|
+
const out: any[] = Porffor.malloc();
|
|
24
24
|
out.length = n;
|
|
25
25
|
return out;
|
|
26
26
|
}
|
|
@@ -38,7 +38,7 @@ export const __Array_isArray = (x: unknown): boolean =>
|
|
|
38
38
|
export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
39
39
|
if (arg == null) throw new TypeError('Argument cannot be nullish');
|
|
40
40
|
|
|
41
|
-
let out: any[] = Porffor.
|
|
41
|
+
let out: any[] = Porffor.malloc();
|
|
42
42
|
|
|
43
43
|
if (Porffor.fastOr(
|
|
44
44
|
Porffor.type(arg) == Porffor.TYPES.array,
|
|
@@ -220,7 +220,7 @@ export const __Array_prototype_slice = (_this: any[], _start: any, _end: any) =>
|
|
|
220
220
|
}
|
|
221
221
|
if (end > len) end = len;
|
|
222
222
|
|
|
223
|
-
let out: any[] = Porffor.
|
|
223
|
+
let out: any[] = Porffor.malloc();
|
|
224
224
|
|
|
225
225
|
if (start > end) return out;
|
|
226
226
|
|
|
@@ -260,7 +260,7 @@ export const __Array_prototype_splice = (_this: any[], _start: any, _deleteCount
|
|
|
260
260
|
if (deleteCount > len - start) deleteCount = len - start;
|
|
261
261
|
|
|
262
262
|
// read values to be deleted into out
|
|
263
|
-
let out: any[] = Porffor.
|
|
263
|
+
let out: any[] = Porffor.malloc();
|
|
264
264
|
out.length = deleteCount;
|
|
265
265
|
|
|
266
266
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
|
@@ -437,7 +437,7 @@ export const __Array_prototype_with = (_this: any[], _index: any, value: any) =>
|
|
|
437
437
|
throw new RangeError('Invalid index');
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
let out: any[] = Porffor.
|
|
440
|
+
let out: any[] = Porffor.malloc();
|
|
441
441
|
Porffor.clone(_this, out);
|
|
442
442
|
|
|
443
443
|
out[index] = value;
|
|
@@ -485,7 +485,7 @@ export const __Array_prototype_copyWithin = (_this: any[], _target: any, _start:
|
|
|
485
485
|
// @porf-typed-array
|
|
486
486
|
export const __Array_prototype_concat = (_this: any[], ...vals: any[]) => {
|
|
487
487
|
// todo/perf: rewrite to use memory.copy (via some Porffor.array.append thing?)
|
|
488
|
-
let out: any[] = Porffor.
|
|
488
|
+
let out: any[] = Porffor.malloc();
|
|
489
489
|
Porffor.clone(_this, out);
|
|
490
490
|
|
|
491
491
|
let len: i32 = _this.length;
|
|
@@ -536,7 +536,7 @@ export const __Array_prototype_forEach = (_this: any[], callbackFn: any, thisArg
|
|
|
536
536
|
// @porf-typed-array
|
|
537
537
|
export const __Array_prototype_filter = (_this: any[], callbackFn: any, thisArg: any) => {
|
|
538
538
|
if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
|
|
539
|
-
const out: any[] = Porffor.
|
|
539
|
+
const out: any[] = Porffor.malloc();
|
|
540
540
|
|
|
541
541
|
const len: i32 = _this.length;
|
|
542
542
|
let i: i32 = 0;
|
|
@@ -554,7 +554,7 @@ export const __Array_prototype_filter = (_this: any[], callbackFn: any, thisArg:
|
|
|
554
554
|
export const __Array_prototype_map = (_this: any[], callbackFn: any, thisArg: any) => {
|
|
555
555
|
if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
|
|
556
556
|
const len: i32 = _this.length;
|
|
557
|
-
const out: any[] = Porffor.
|
|
557
|
+
const out: any[] = Porffor.malloc();
|
|
558
558
|
out.length = len;
|
|
559
559
|
|
|
560
560
|
let i: i32 = 0;
|
|
@@ -568,7 +568,7 @@ export const __Array_prototype_map = (_this: any[], callbackFn: any, thisArg: an
|
|
|
568
568
|
export const __Array_prototype_flatMap = (_this: any[], callbackFn: any, thisArg: any) => {
|
|
569
569
|
if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
|
|
570
570
|
const len: i32 = _this.length;
|
|
571
|
-
const out: any[] = Porffor.
|
|
571
|
+
const out: any[] = Porffor.malloc();
|
|
572
572
|
|
|
573
573
|
let i: i32 = 0, j: i32 = 0;
|
|
574
574
|
while (i < len) {
|
|
@@ -768,7 +768,7 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
|
|
|
768
768
|
export const __Array_prototype_toString = (_this: any[]) => {
|
|
769
769
|
// todo: this is bytestring only!
|
|
770
770
|
|
|
771
|
-
let out: bytestring = Porffor.
|
|
771
|
+
let out: bytestring = Porffor.malloc();
|
|
772
772
|
const len: i32 = _this.length;
|
|
773
773
|
let i: i32 = 0;
|
|
774
774
|
while (i < len) {
|
|
@@ -799,7 +799,7 @@ export const __Array_prototype_join = (_this: any[], _separator: any) => {
|
|
|
799
799
|
if (Porffor.type(_separator) != Porffor.TYPES.undefined)
|
|
800
800
|
separator = ecma262.ToString(_separator);
|
|
801
801
|
|
|
802
|
-
let out: bytestring = Porffor.
|
|
802
|
+
let out: bytestring = Porffor.malloc();
|
|
803
803
|
const len: i32 = _this.length;
|
|
804
804
|
let i: i32 = 0;
|
|
805
805
|
while (i < len) {
|
|
@@ -829,7 +829,7 @@ export const __Array_prototype_toReversed = (_this: any[]) => {
|
|
|
829
829
|
let start: i32 = 0;
|
|
830
830
|
let end: i32 = len - 1;
|
|
831
831
|
|
|
832
|
-
let out: any[] = Porffor.
|
|
832
|
+
let out: any[] = Porffor.malloc();
|
|
833
833
|
out.length = len;
|
|
834
834
|
|
|
835
835
|
while (true) {
|
|
@@ -847,14 +847,14 @@ export const __Array_prototype_toReversed = (_this: any[]) => {
|
|
|
847
847
|
export const __Array_prototype_toSorted = (_this: any[], callbackFn: any) => {
|
|
848
848
|
// todo/perf: could be rewritten to be its own instead of cloning and using normal sort()
|
|
849
849
|
|
|
850
|
-
let out: any[] = Porffor.
|
|
850
|
+
let out: any[] = Porffor.malloc();
|
|
851
851
|
Porffor.clone(_this, out);
|
|
852
852
|
|
|
853
853
|
return __Array_prototype_sort(out, callbackFn);
|
|
854
854
|
};
|
|
855
855
|
|
|
856
856
|
export const __Array_prototype_toSpliced = (_this: any[], _start: any, _deleteCount: any, ...items: any[]) => {
|
|
857
|
-
let out: any[] = Porffor.
|
|
857
|
+
let out: any[] = Porffor.malloc();
|
|
858
858
|
Porffor.clone(_this, out);
|
|
859
859
|
|
|
860
860
|
const len: i32 = _this.length;
|
|
@@ -942,7 +942,7 @@ export const __Array_prototype_flat = (_this: any[], _depth: any) => {
|
|
|
942
942
|
if (Porffor.type(_depth) == Porffor.TYPES.undefined) _depth = 1;
|
|
943
943
|
let depth: i32 = ecma262.ToIntegerOrInfinity(_depth);
|
|
944
944
|
|
|
945
|
-
let out: any[] = Porffor.
|
|
945
|
+
let out: any[] = Porffor.malloc();
|
|
946
946
|
if (depth <= 0) {
|
|
947
947
|
Porffor.clone(_this, out);
|
|
948
948
|
return out;
|
|
@@ -22,7 +22,7 @@ export const ArrayBuffer = function (length: any): ArrayBuffer {
|
|
|
22
22
|
if (byteLength < 0) throw new RangeError('Invalid ArrayBuffer length (negative)');
|
|
23
23
|
if (byteLength > 4294967295) throw new RangeError('Invalid ArrayBuffer length (over 32 bit address space)');
|
|
24
24
|
|
|
25
|
-
const out: ArrayBuffer = Porffor.
|
|
25
|
+
const out: ArrayBuffer = Porffor.malloc(byteLength + 4);
|
|
26
26
|
Porffor.wasm.i32.store(out, byteLength, 0, 0);
|
|
27
27
|
|
|
28
28
|
return out;
|
|
@@ -98,7 +98,7 @@ export const __ArrayBuffer_prototype_slice = (_this: ArrayBuffer, start: any, en
|
|
|
98
98
|
}
|
|
99
99
|
if (end > len) end = len;
|
|
100
100
|
|
|
101
|
-
const out: ArrayBuffer = Porffor.
|
|
101
|
+
const out: ArrayBuffer = Porffor.malloc(4 + (end - start));
|
|
102
102
|
Porffor.wasm.i32.store(out, end - start, 0, 0);
|
|
103
103
|
|
|
104
104
|
Porffor.wasm`
|
|
@@ -185,7 +185,7 @@ export const SharedArrayBuffer = function (length: any): SharedArrayBuffer {
|
|
|
185
185
|
if (byteLength < 0) throw new RangeError('Invalid SharedArrayBuffer length (negative)');
|
|
186
186
|
if (byteLength > 4294967295) throw new RangeError('Invalid SharedArrayBuffer length (over 32 bit address space)');
|
|
187
187
|
|
|
188
|
-
const out: SharedArrayBuffer = Porffor.
|
|
188
|
+
const out: SharedArrayBuffer = Porffor.malloc(byteLength + 4);
|
|
189
189
|
Porffor.wasm.i32.store(out, byteLength, 0, 0);
|
|
190
190
|
|
|
191
191
|
return out;
|
|
@@ -222,7 +222,7 @@ export const __SharedArrayBuffer_prototype_slice = (_this: SharedArrayBuffer, st
|
|
|
222
222
|
}
|
|
223
223
|
if (end > len) end = len;
|
|
224
224
|
|
|
225
|
-
const out: SharedArrayBuffer = Porffor.
|
|
225
|
+
const out: SharedArrayBuffer = Porffor.malloc(4 + (end - start));
|
|
226
226
|
Porffor.wasm.i32.store(out, end - start, 0, 0);
|
|
227
227
|
|
|
228
228
|
Porffor.wasm`
|
|
@@ -8,7 +8,7 @@ export const btoa = (input: bytestring): bytestring => {
|
|
|
8
8
|
const keyStrPtr: i32 = Porffor.wasm`local.get ${keyStr}`;
|
|
9
9
|
|
|
10
10
|
let len: i32 = input.length;
|
|
11
|
-
let output: bytestring = Porffor.
|
|
11
|
+
let output: bytestring = Porffor.malloc();
|
|
12
12
|
|
|
13
13
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
|
14
14
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
|
@@ -49,7 +49,7 @@ export const atob = (input: bytestring): bytestring => {
|
|
|
49
49
|
const lut: bytestring = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>@@@?456789:;<=@@@@@@@\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19@@@@@@\x1A\x1B\x1C\x1D\x1E\x1F !"#$%&\'()*+,-./0123';
|
|
50
50
|
const lutPtr: i32 = Porffor.wasm`local.get ${lut}`;
|
|
51
51
|
|
|
52
|
-
let output: bytestring = Porffor.
|
|
52
|
+
let output: bytestring = Porffor.malloc();
|
|
53
53
|
|
|
54
54
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
|
55
55
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
|
@@ -30,7 +30,7 @@ export const __Porffor_bigint_fromDigits = (negative: boolean, digits: i32[]): b
|
|
|
30
30
|
// store small (abs(n) < 2^51 (0x8000000000000)) values inline (no allocation)
|
|
31
31
|
// like a ~s52 (s53 exc 2^51+(0-2^32) for u32 as pointer) inside a f64
|
|
32
32
|
export const __Porffor_bigint_inlineToDigitForm = (n: number): number => {
|
|
33
|
-
const ptr: i32 = Porffor.
|
|
33
|
+
const ptr: i32 = Porffor.malloc(4); // 4 meta + 1 digit
|
|
34
34
|
Porffor.wasm.i32.store8(ptr, n < 0, 0, 0);
|
|
35
35
|
Porffor.wasm.i32.store16(ptr, 1, 0, 2);
|
|
36
36
|
Porffor.wasm.i32.store(ptr, Math.abs(n), 0, 4);
|
|
@@ -46,7 +46,7 @@ export const __Porffor_bigint_fromNumber = (n: number): bigint => {
|
|
|
46
46
|
const negative: boolean = n < 0;
|
|
47
47
|
n = Math.abs(n);
|
|
48
48
|
|
|
49
|
-
const digits: i32[] = Porffor.
|
|
49
|
+
const digits: i32[] = Porffor.malloc();
|
|
50
50
|
while (n > 0) {
|
|
51
51
|
digits.unshift(n % 0x100000000);
|
|
52
52
|
n = Math.trunc(n / 0x100000000);
|
|
@@ -90,7 +90,7 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
|
|
|
90
90
|
// 4294967297 -> [ 1, 1 ]
|
|
91
91
|
|
|
92
92
|
const BASE: i32 = 0x100000000; // 2^32
|
|
93
|
-
const digits: i32[] = Porffor.
|
|
93
|
+
const digits: i32[] = Porffor.malloc(); // todo: free later
|
|
94
94
|
digits.length = len - offset;
|
|
95
95
|
|
|
96
96
|
let i: i32 = 0;
|
|
@@ -109,7 +109,7 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
|
|
|
109
109
|
return acc as bigint;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const result: i32[] = Porffor.
|
|
112
|
+
const result: i32[] = Porffor.malloc();
|
|
113
113
|
while (digits.length > 0) {
|
|
114
114
|
let carry: i32 = 0;
|
|
115
115
|
for (let j: i32 = 0; j < digits.length; j++) {
|
|
@@ -156,7 +156,7 @@ export const __Porffor_bigint_add = (a: number, b: number, sub: boolean): bigint
|
|
|
156
156
|
const bLen: i32 = Porffor.wasm.i32.load16_u(b, 0, 2);
|
|
157
157
|
|
|
158
158
|
const maxLen: i32 = Math.max(aLen, bLen);
|
|
159
|
-
const digits: i32[] = Porffor.
|
|
159
|
+
const digits: i32[] = Porffor.malloc();
|
|
160
160
|
|
|
161
161
|
// fast path: same sign
|
|
162
162
|
let negative: boolean = false;
|
|
@@ -22,7 +22,7 @@ export const DataView = function (arg: any, byteOffset: any, length: any): DataV
|
|
|
22
22
|
if (len < 0) throw new RangeError('Invalid DataView length (negative)');
|
|
23
23
|
if (len > 4294967295) throw new RangeError('Invalid DataView length (over 32 bit address space)');
|
|
24
24
|
|
|
25
|
-
const out: DataView = Porffor.
|
|
25
|
+
const out: DataView = Porffor.malloc(12);
|
|
26
26
|
Porffor.wasm.i32.store(out, Porffor.wasm`local.get ${arg}` + offset, 0, 4);
|
|
27
27
|
Porffor.wasm.i32.store(out, offset, 0, 8);
|
|
28
28
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
|
@@ -347,7 +347,7 @@ export const __ecma262_WeekDayName = (tv: number): bytestring => {
|
|
|
347
347
|
const lut: bytestring = 'SunMonTueWedThuFriSat';
|
|
348
348
|
const weekday: number = __ecma262_WeekDay(tv);
|
|
349
349
|
|
|
350
|
-
let out: bytestring = Porffor.
|
|
350
|
+
let out: bytestring = Porffor.malloc(8);
|
|
351
351
|
out.length = 3;
|
|
352
352
|
|
|
353
353
|
let outPtr: number = Porffor.wasm`local.get ${out}`;
|
|
@@ -365,7 +365,7 @@ export const __ecma262_MonthName = (tv: number): bytestring => {
|
|
|
365
365
|
const lut: bytestring = 'JanFebMarAprMayJunJulAugSepOctNovDec';
|
|
366
366
|
const month: number = __ecma262_MonthFromTime(tv);
|
|
367
367
|
|
|
368
|
-
let out: bytestring = Porffor.
|
|
368
|
+
let out: bytestring = Porffor.malloc(8);
|
|
369
369
|
out.length = 3;
|
|
370
370
|
|
|
371
371
|
let outPtr: number = Porffor.wasm`local.get ${out}`;
|
|
@@ -1472,7 +1472,7 @@ export const __Porffor_bytestring_appendPadNum = (str: bytestring, num: number,
|
|
|
1472
1472
|
export const __ecma262_ToUTCDTSF = (t: number): bytestring => {
|
|
1473
1473
|
const year: number = __ecma262_YearFromTime(t);
|
|
1474
1474
|
|
|
1475
|
-
let out: bytestring = Porffor.
|
|
1475
|
+
let out: bytestring = Porffor.malloc(64);
|
|
1476
1476
|
if (Porffor.fastOr(year < 0, year >= 10000)) {
|
|
1477
1477
|
// extended year format
|
|
1478
1478
|
// sign
|
|
@@ -1565,7 +1565,7 @@ export const __ecma262_TimeString = (tv: number): bytestring => {
|
|
|
1565
1565
|
const second: number = __ecma262_SecFromTime(tv);
|
|
1566
1566
|
|
|
1567
1567
|
// 4. Return the string-concatenation of hour, ":", minute, ":", second, the code unit 0x0020 (SPACE), and "GMT".
|
|
1568
|
-
let out: bytestring = Porffor.
|
|
1568
|
+
let out: bytestring = Porffor.malloc(64);
|
|
1569
1569
|
__Porffor_bytestring_appendPadNum(out, hour, 2);
|
|
1570
1570
|
__Porffor_bytestring_appendChar(out, 58); // ':'
|
|
1571
1571
|
|
|
@@ -1601,7 +1601,7 @@ export const __ecma262_DateString = (tv: number): bytestring => {
|
|
|
1601
1601
|
// 5. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
|
|
1602
1602
|
// 6. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
|
|
1603
1603
|
// 7. Return the string-concatenation of weekday, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), yearSign, and paddedYear.
|
|
1604
|
-
let out: bytestring = Porffor.
|
|
1604
|
+
let out: bytestring = Porffor.malloc(64);
|
|
1605
1605
|
|
|
1606
1606
|
// weekday
|
|
1607
1607
|
__Porffor_bytestring_appendStr(out, weekday);
|
|
@@ -1638,7 +1638,7 @@ export const __ecma262_ToDateString = (tv: number) => {
|
|
|
1638
1638
|
const t: number = __ecma262_LocalTime(tv);
|
|
1639
1639
|
|
|
1640
1640
|
// 3. Return the string-concatenation of DateString(t), the code unit 0x0020 (SPACE), TimeString(t), and TimeZoneString(tv).
|
|
1641
|
-
const out: bytestring = Porffor.
|
|
1641
|
+
const out: bytestring = Porffor.malloc(64);
|
|
1642
1642
|
__Porffor_bytestring_appendStr(out, __ecma262_DateString(t));
|
|
1643
1643
|
__Porffor_bytestring_appendChar(out, 32);
|
|
1644
1644
|
|
|
@@ -1675,7 +1675,7 @@ export const __Date_prototype_toTimeString = (_this: any) => {
|
|
|
1675
1675
|
const t: number = __ecma262_LocalTime(tv);
|
|
1676
1676
|
|
|
1677
1677
|
// 6. Return the string-concatenation of TimeString(t) and TimeZoneString(tv).
|
|
1678
|
-
const out: bytestring = Porffor.
|
|
1678
|
+
const out: bytestring = Porffor.malloc(64);
|
|
1679
1679
|
__Porffor_bytestring_appendStr(out, __ecma262_TimeString(t));
|
|
1680
1680
|
__Porffor_bytestring_appendStr(out, __ecma262_TimeZoneString(tv));
|
|
1681
1681
|
return out;
|
|
@@ -1728,7 +1728,7 @@ export const __Date_prototype_toUTCString = (_this: any) => {
|
|
|
1728
1728
|
// 11. Return the string-concatenation of weekday, ",", the code unit 0x0020 (SPACE),
|
|
1729
1729
|
// day, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE),
|
|
1730
1730
|
// yearSign, paddedYear, the code unit 0x0020 (SPACE), and TimeString(tv).
|
|
1731
|
-
const out: bytestring = Porffor.
|
|
1731
|
+
const out: bytestring = Porffor.malloc(64);
|
|
1732
1732
|
|
|
1733
1733
|
// weekday
|
|
1734
1734
|
__Porffor_bytestring_appendStr(out, weekday);
|
|
@@ -1867,7 +1867,7 @@ export const Date = function (...values: any[]): bytestring|Date {
|
|
|
1867
1867
|
}
|
|
1868
1868
|
|
|
1869
1869
|
// 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »).
|
|
1870
|
-
const O: Date = Porffor.
|
|
1870
|
+
const O: Date = Porffor.malloc(8);
|
|
1871
1871
|
|
|
1872
1872
|
// 7. Set O.[[DateValue]] to dv.
|
|
1873
1873
|
__Porffor_date_write(O, dv);
|
|
@@ -8,7 +8,7 @@ export default () => {
|
|
|
8
8
|
if (message === undefined) message = '';
|
|
9
9
|
else message = ecma262.ToString(message);
|
|
10
10
|
|
|
11
|
-
const obj: ${name} = Porffor.
|
|
11
|
+
const obj: ${name} = Porffor.malloc(8);
|
|
12
12
|
Porffor.wasm.i32.store(obj, message, 0, 0);
|
|
13
13
|
Porffor.wasm.i32.store8(obj, Porffor.type(message), 0, 4);
|
|
14
14
|
|
|
@@ -10,7 +10,7 @@ export const Function = function (source: string) {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const __Function_prototype_toString = (_this: Function) => {
|
|
13
|
-
const out: bytestring = Porffor.
|
|
13
|
+
const out: bytestring = Porffor.malloc(256);
|
|
14
14
|
|
|
15
15
|
Porffor.bytestring.appendStr(out, 'function ');
|
|
16
16
|
Porffor.bytestring.appendStr(out, __Porffor_funcLut_name(_this));
|
|
@@ -240,7 +240,7 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
|
240
240
|
if (space < 1) {
|
|
241
241
|
space = undefined;
|
|
242
242
|
} else {
|
|
243
|
-
const spaceStr: bytestring = Porffor.
|
|
243
|
+
const spaceStr: bytestring = Porffor.malloc(4 + space);
|
|
244
244
|
for (let i: i32 = 0; i < space; i++) Porffor.bytestring.appendChar(spaceStr, 32);
|
|
245
245
|
|
|
246
246
|
space = spaceStr;
|
|
@@ -262,8 +262,8 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
const buffer: bytestring = Porffor.
|
|
266
|
-
const out = __Porffor_json_serialize(buffer, value, 0, space);
|
|
265
|
+
const buffer: bytestring = Porffor.malloc(4096);
|
|
266
|
+
const out: i32 = __Porffor_json_serialize(buffer, value, 0, space);
|
|
267
267
|
if (out == -1) return undefined;
|
|
268
268
|
|
|
269
269
|
buffer.length = out - (buffer as i32);
|
|
@@ -329,7 +329,7 @@ export const __JSON_parse = (_: bytestring) => {
|
|
|
329
329
|
|
|
330
330
|
if (c == 34) { // '"' - string
|
|
331
331
|
pos++;
|
|
332
|
-
const out: bytestring = Porffor.
|
|
332
|
+
const out: bytestring = Porffor.malloc();
|
|
333
333
|
|
|
334
334
|
while (pos < len) {
|
|
335
335
|
const ch: i32 = text.charCodeAt(pos);
|
|
@@ -375,7 +375,7 @@ export const __JSON_parse = (_: bytestring) => {
|
|
|
375
375
|
|
|
376
376
|
if (c == 91) { // '[' - array
|
|
377
377
|
pos++;
|
|
378
|
-
const arr: any[] = Porffor.
|
|
378
|
+
const arr: any[] = Porffor.malloc();
|
|
379
379
|
skipWhitespace();
|
|
380
380
|
|
|
381
381
|
if (pos < len && text.charCodeAt(pos) == 93) { // empty array
|
package/compiler/builtins/map.ts
CHANGED
|
@@ -87,10 +87,10 @@ export const __Map_prototype_forEach = (_this: Map, callbackFn: any) => {
|
|
|
87
87
|
export const Map = function (iterable: any): Map {
|
|
88
88
|
if (!new.target) throw new TypeError("Constructor Map requires 'new'");
|
|
89
89
|
|
|
90
|
-
const out: Map = Porffor.
|
|
90
|
+
const out: Map = Porffor.malloc(8);
|
|
91
91
|
|
|
92
|
-
const keys: any[] = Porffor.
|
|
93
|
-
const vals: any[] = Porffor.
|
|
92
|
+
const keys: any[] = Porffor.malloc();
|
|
93
|
+
const vals: any[] = Porffor.malloc();
|
|
94
94
|
Porffor.wasm.i32.store(out, keys, 0, 0);
|
|
95
95
|
Porffor.wasm.i32.store(out, vals, 0, 4);
|
|
96
96
|
|
|
@@ -104,7 +104,7 @@ export const Map = function (iterable: any): Map {
|
|
|
104
104
|
|
|
105
105
|
export const __Map_prototype_keys = (_this: Map) => {
|
|
106
106
|
const keys: any[] = Porffor.wasm.i32.load(_this, 0, 0);
|
|
107
|
-
const out: any[] = Porffor.
|
|
107
|
+
const out: any[] = Porffor.malloc();
|
|
108
108
|
|
|
109
109
|
for (const x of keys) {
|
|
110
110
|
Porffor.array.fastPush(out, x);
|
|
@@ -116,7 +116,7 @@ export const __Map_prototype_keys = (_this: Map) => {
|
|
|
116
116
|
export const __Map_prototype_values = (_this: Map) => {
|
|
117
117
|
const size: i32 = Porffor.wasm.i32.load(Porffor.wasm.i32.load(_this, 0, 0), 0, 0);
|
|
118
118
|
const vals: any[] = Porffor.wasm.i32.load(_this, 0, 4);
|
|
119
|
-
const out: any[] = Porffor.
|
|
119
|
+
const out: any[] = Porffor.malloc();
|
|
120
120
|
|
|
121
121
|
for (let i: i32 = 0; i < size; i++) {
|
|
122
122
|
Porffor.array.fastPush(out, vals[i]);
|
|
@@ -55,7 +55,7 @@ export const __Number_prototype_toString = (_this: number, radix: number|any) =>
|
|
|
55
55
|
return '0';
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
let out: bytestring = Porffor.
|
|
58
|
+
let out: bytestring = Porffor.malloc(512);
|
|
59
59
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
|
60
60
|
|
|
61
61
|
// if negative value
|
|
@@ -279,7 +279,7 @@ export const __Number_prototype_toFixed = (_this: number, fractionDigits: number
|
|
|
279
279
|
return '-Infinity';
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
let out: bytestring = Porffor.
|
|
282
|
+
let out: bytestring = Porffor.malloc(512);
|
|
283
283
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
|
284
284
|
|
|
285
285
|
// if negative value
|
|
@@ -373,7 +373,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
-
let out: bytestring = Porffor.
|
|
376
|
+
let out: bytestring = Porffor.malloc(512);
|
|
377
377
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
|
378
378
|
|
|
379
379
|
// if negative value
|
|
@@ -3,7 +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
|
-
return Porffor.
|
|
6
|
+
return Porffor.malloc() as object;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// primitives into primitive objects
|
|
@@ -17,7 +17,7 @@ export const Object = function (value: any): any {
|
|
|
17
17
|
|
|
18
18
|
export const __Object_keys = (obj: any): any[] => {
|
|
19
19
|
if (obj == null) throw new TypeError('Argument is nullish, expected object');
|
|
20
|
-
const out: any[] = Porffor.
|
|
20
|
+
const out: any[] = Porffor.malloc();
|
|
21
21
|
|
|
22
22
|
obj = __Porffor_object_underlying(obj);
|
|
23
23
|
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
|
@@ -72,7 +72,7 @@ local.set ${key}`;
|
|
|
72
72
|
|
|
73
73
|
export const __Object_values = (obj: any): any[] => {
|
|
74
74
|
if (obj == null) throw new TypeError('Argument is nullish, expected object');
|
|
75
|
-
const out: any[] = Porffor.
|
|
75
|
+
const out: any[] = Porffor.malloc();
|
|
76
76
|
|
|
77
77
|
obj = __Porffor_object_underlying(obj);
|
|
78
78
|
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
|
@@ -106,7 +106,7 @@ export const __Object_values = (obj: any): any[] => {
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
export const __Object_entries = (obj: any): any[] => {
|
|
109
|
-
const out: any[] = Porffor.
|
|
109
|
+
const out: any[] = Porffor.malloc();
|
|
110
110
|
|
|
111
111
|
const keys: any[] = __Object_keys(obj);
|
|
112
112
|
const vals: any[] = __Object_values(obj);
|
|
@@ -116,7 +116,7 @@ export const __Object_entries = (obj: any): any[] => {
|
|
|
116
116
|
|
|
117
117
|
for (let i: i32 = 0; i < size; i++) {
|
|
118
118
|
// what is memory efficiency anyway?
|
|
119
|
-
const entry: any[] = Porffor.
|
|
119
|
+
const entry: any[] = Porffor.malloc();
|
|
120
120
|
|
|
121
121
|
entry.length = 2;
|
|
122
122
|
entry[0] = keys[i];
|
|
@@ -408,7 +408,7 @@ export const __Object_getOwnPropertyDescriptors = (obj: any): object => {
|
|
|
408
408
|
|
|
409
409
|
export const __Object_getOwnPropertyNames = (obj: any): any[] => {
|
|
410
410
|
if (obj == null) throw new TypeError('Argument is nullish, expected object');
|
|
411
|
-
const out: any[] = Porffor.
|
|
411
|
+
const out: any[] = Porffor.malloc();
|
|
412
412
|
|
|
413
413
|
obj = __Porffor_object_underlying(obj);
|
|
414
414
|
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
|
@@ -462,7 +462,7 @@ local.set ${key}`;
|
|
|
462
462
|
|
|
463
463
|
export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
|
|
464
464
|
if (obj == null) throw new TypeError('Argument is nullish, expected object');
|
|
465
|
-
const out: any[] = Porffor.
|
|
465
|
+
const out: any[] = Porffor.malloc();
|
|
466
466
|
|
|
467
467
|
obj = __Porffor_object_underlying(obj);
|
|
468
468
|
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
|
@@ -623,7 +623,7 @@ export const __Object_groupBy = (items: any, callbackFn: any): object => {
|
|
|
623
623
|
for (const x of items) {
|
|
624
624
|
const k: any = callbackFn(x, i++);
|
|
625
625
|
if (!__Object_hasOwn(out, k)) {
|
|
626
|
-
const arr: any[] = Porffor.
|
|
626
|
+
const arr: any[] = Porffor.malloc();
|
|
627
627
|
out[k] = arr;
|
|
628
628
|
}
|
|
629
629
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {} from './porffor.d.ts';
|
|
2
2
|
|
|
3
3
|
export const __ecma262_NewPromiseReactionJob = (reaction: any[], argument: any): any[] => {
|
|
4
|
-
const job: any[] = Porffor.
|
|
4
|
+
const job: any[] = Porffor.malloc(32);
|
|
5
5
|
job[0] = reaction;
|
|
6
6
|
job[1] = argument;
|
|
7
7
|
|
|
@@ -96,7 +96,7 @@ export const __Porffor_promise_noop = (x: any): any => x;
|
|
|
96
96
|
|
|
97
97
|
export const __Porffor_promise_newReaction = (handler: Function, promise: any, flags: i32): any[] => {
|
|
98
98
|
// enum ReactionType { then = 0, finally = 1 }
|
|
99
|
-
const out: any[] = Porffor.
|
|
99
|
+
const out: any[] = Porffor.malloc(32);
|
|
100
100
|
out[0] = handler;
|
|
101
101
|
out[1] = promise;
|
|
102
102
|
out[2] = flags;
|
|
@@ -164,7 +164,7 @@ export const __Porffor_promise_reject = (reason: any, promise: any): void => {
|
|
|
164
164
|
|
|
165
165
|
export const __Porffor_promise_create = (): any[] => {
|
|
166
166
|
// Promise [ result, state, fulfillReactions, rejectReactions ]
|
|
167
|
-
const obj: any[] = Porffor.
|
|
167
|
+
const obj: any[] = Porffor.malloc(64);
|
|
168
168
|
|
|
169
169
|
// result = undefined
|
|
170
170
|
obj[0] = undefined;
|
|
@@ -174,11 +174,11 @@ export const __Porffor_promise_create = (): any[] => {
|
|
|
174
174
|
obj[1] = 0;
|
|
175
175
|
|
|
176
176
|
// fulfillReactions = []
|
|
177
|
-
const fulfillReactions: any[] = Porffor.
|
|
177
|
+
const fulfillReactions: any[] = Porffor.malloc(512);
|
|
178
178
|
obj[2] = fulfillReactions;
|
|
179
179
|
|
|
180
180
|
// rejectReactions = []
|
|
181
|
-
const rejectReactions: any[] = Porffor.
|
|
181
|
+
const rejectReactions: any[] = Porffor.malloc(512);
|
|
182
182
|
obj[3] = rejectReactions;
|
|
183
183
|
|
|
184
184
|
return obj;
|
|
@@ -246,7 +246,7 @@ export const __Promise_withResolvers = (): object => {
|
|
|
246
246
|
const obj: any[] = __Porffor_promise_create();
|
|
247
247
|
activePromise = obj;
|
|
248
248
|
|
|
249
|
-
const out: object = Porffor.
|
|
249
|
+
const out: object = Porffor.malloc();
|
|
250
250
|
out.promise = obj as Promise;
|
|
251
251
|
|
|
252
252
|
out.resolve = __Porffor_promise_resolveActive;
|
|
@@ -339,7 +339,7 @@ export const __Promise_all = (promises: any): Promise => {
|
|
|
339
339
|
return new Promise((res, rej) => {
|
|
340
340
|
_allRes = res, _allRej = rej;
|
|
341
341
|
|
|
342
|
-
const arr: any[] = Porffor.
|
|
342
|
+
const arr: any[] = Porffor.malloc();
|
|
343
343
|
_allOut = arr;
|
|
344
344
|
_allLen = 0;
|
|
345
345
|
|
|
@@ -375,7 +375,7 @@ export const __Promise_allSettled = (promises: any): Promise => {
|
|
|
375
375
|
return new Promise((res, rej) => {
|
|
376
376
|
_allRes = res, _allRej = rej;
|
|
377
377
|
|
|
378
|
-
const arr: any[] = Porffor.
|
|
378
|
+
const arr: any[] = Porffor.malloc();
|
|
379
379
|
_allOut = arr;
|
|
380
380
|
_allLen = 0;
|
|
381
381
|
|
|
@@ -420,7 +420,7 @@ export const __Promise_any = (promises: any): Promise => {
|
|
|
420
420
|
return new Promise((res, rej) => {
|
|
421
421
|
_allRes = res, _allRej = rej;
|
|
422
422
|
|
|
423
|
-
const arr: any[] = Porffor.
|
|
423
|
+
const arr: any[] = Porffor.malloc();
|
|
424
424
|
_allOut = arr; // list of rejections
|
|
425
425
|
_allLen = 0;
|
|
426
426
|
|
|
@@ -86,7 +86,7 @@ export const __Reflect_setPrototypeOf = (target: any, proto: any) => {
|
|
|
86
86
|
export const __Reflect_ownKeys = (target: any) => {
|
|
87
87
|
if (!Porffor.object.isObject(target)) throw new TypeError('Target is a non-object');
|
|
88
88
|
|
|
89
|
-
const out: any[] = Porffor.
|
|
89
|
+
const out: any[] = Porffor.malloc();
|
|
90
90
|
|
|
91
91
|
target = __Porffor_object_underlying(target);
|
|
92
92
|
if (Porffor.type(target) == Porffor.TYPES.object) {
|