porffor 0.18.13 → 0.18.14
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/array.ts +2 -2
- package/compiler/builtins/base64.ts +2 -2
- package/compiler/builtins/boolean.ts +1 -1
- package/compiler/builtins/date.ts +10 -29
- package/compiler/builtins/escape.ts +2 -2
- package/compiler/builtins/number.ts +3 -3
- package/compiler/builtins/string.ts +22 -22
- package/compiler/builtins/symbol.ts +1 -1
- package/compiler/builtins/z_ecma262.ts +1 -1
- package/compiler/builtins.js +61 -4
- package/compiler/codegen.js +221 -114
- package/compiler/generated_builtins.js +452 -452
- package/compiler/types.js +14 -13
- package/compiler/wrap.js +7 -9
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -413,7 +413,7 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
|
|
413
413
|
export const __Array_prototype_toString = (_this: any[]) => {
|
414
414
|
// todo: this is bytestring only!
|
415
415
|
|
416
|
-
let out: bytestring =
|
416
|
+
let out: bytestring = Porffor.allocate();
|
417
417
|
out.length = 0;
|
418
418
|
|
419
419
|
const len: i32 = _this.length;
|
@@ -444,7 +444,7 @@ export const __Array_prototype_join = (_this: any[], _separator: any) => {
|
|
444
444
|
if (Porffor.rawType(_separator) != Porffor.TYPES.undefined)
|
445
445
|
separator = ecma262.ToString(_separator);
|
446
446
|
|
447
|
-
let out: bytestring =
|
447
|
+
let out: bytestring = Porffor.allocate();
|
448
448
|
out.length = 0;
|
449
449
|
|
450
450
|
const len: i32 = _this.length;
|
@@ -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 =
|
11
|
+
let output: bytestring = Porffor.allocate();
|
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 =
|
52
|
+
let output: bytestring = Porffor.allocate();
|
53
53
|
|
54
54
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
55
55
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
@@ -5,7 +5,7 @@ import type {} from './porffor.d.ts';
|
|
5
5
|
export const __Boolean_prototype_toString = (_this: boolean) => {
|
6
6
|
// 1. Let b be ? ThisBooleanValue(this value).
|
7
7
|
// 2. If b is true, return "true"; else return "false".
|
8
|
-
let out: bytestring =
|
8
|
+
let out: bytestring = Porffor.allocate();
|
9
9
|
if (_this) out = 'true';
|
10
10
|
else out = 'false';
|
11
11
|
|
@@ -418,7 +418,7 @@ export const __ecma262_WeekDayName = (tv: number): bytestring => {
|
|
418
418
|
|
419
419
|
const lut: bytestring = 'SunMonTueWedThuFriSat';
|
420
420
|
|
421
|
-
let out: bytestring =
|
421
|
+
let out: bytestring = Porffor.allocateBytes(7);
|
422
422
|
out.length = 3;
|
423
423
|
|
424
424
|
let outPtr: number = Porffor.wasm`local.get ${out}`;
|
@@ -452,7 +452,7 @@ export const __ecma262_MonthName = (tv: number): bytestring => {
|
|
452
452
|
|
453
453
|
const lut: bytestring = 'JanFebMarAprMayJunJulAugSepOctNovDec';
|
454
454
|
|
455
|
-
let out: bytestring =
|
455
|
+
let out: bytestring = Porffor.allocateBytes(7);
|
456
456
|
out.length = 3;
|
457
457
|
|
458
458
|
let outPtr: number = Porffor.wasm`local.get ${out}`;
|
@@ -694,25 +694,6 @@ export const __Date_parse = (string: bytestring): number => {
|
|
694
694
|
};
|
695
695
|
|
696
696
|
|
697
|
-
// dark wasm magic for a basic allocator, sorry.
|
698
|
-
export const __Porffor_date_allocate = (): Date => {
|
699
|
-
const hack: bytestring = '';
|
700
|
-
|
701
|
-
if (hack.length == 0) {
|
702
|
-
hack.length = Porffor.wasm`
|
703
|
-
i32.const 1
|
704
|
-
memory.grow 0
|
705
|
-
i32.const 65536
|
706
|
-
i32.mul
|
707
|
-
i32.from_u`;
|
708
|
-
}
|
709
|
-
|
710
|
-
const ptr: number = hack.length;
|
711
|
-
hack.length = ptr + 8;
|
712
|
-
|
713
|
-
return ptr;
|
714
|
-
};
|
715
|
-
|
716
697
|
export const __Porffor_date_read = (ptr: Date): number => Porffor.wasm.f64.load(ptr, 0, 0);
|
717
698
|
export const __Porffor_date_write = (ptr: Date, val: number) => {
|
718
699
|
Porffor.wasm.f64.store(ptr, val, 0, 0);
|
@@ -1593,7 +1574,7 @@ export const __Porffor_bytestring_appendPadNum = (str: bytestring, num: number,
|
|
1593
1574
|
export const __ecma262_ToUTCDTSF = (t: number): bytestring => {
|
1594
1575
|
const year: number = __ecma262_YearFromTime(t);
|
1595
1576
|
|
1596
|
-
let out: bytestring =
|
1577
|
+
let out: bytestring = Porffor.allocateBytes(31);
|
1597
1578
|
out.length = 0;
|
1598
1579
|
|
1599
1580
|
if (Porffor.fastOr(year < 0, year >= 10000)) {
|
@@ -1689,7 +1670,7 @@ export const __ecma262_TimeString = (tv: number): bytestring => {
|
|
1689
1670
|
const second: number = __ecma262_SecFromTime(tv);
|
1690
1671
|
|
1691
1672
|
// 4. Return the string-concatenation of hour, ":", minute, ":", second, the code unit 0x0020 (SPACE), and "GMT".
|
1692
|
-
let out: bytestring =
|
1673
|
+
let out: bytestring = Porffor.allocateBytes(16);
|
1693
1674
|
out.length = 0;
|
1694
1675
|
|
1695
1676
|
__Porffor_bytestring_appendPadNum(out, hour, 2);
|
@@ -1728,7 +1709,7 @@ export const __ecma262_DateString = (tv: number): bytestring => {
|
|
1728
1709
|
// 5. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
|
1729
1710
|
// 6. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
|
1730
1711
|
// 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.
|
1731
|
-
let out: bytestring =
|
1712
|
+
let out: bytestring = Porffor.allocateBytes(20);
|
1732
1713
|
out.length = 0;
|
1733
1714
|
|
1734
1715
|
// weekday
|
@@ -1761,7 +1742,7 @@ export const __ecma262_TimeZoneString = (tv: number) => {
|
|
1761
1742
|
// 21.4.4.41.4 ToDateString (tv)
|
1762
1743
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-todatestring
|
1763
1744
|
export const __ecma262_ToDateString = (tv: number) => {
|
1764
|
-
let out: bytestring =
|
1745
|
+
let out: bytestring = Porffor.allocateBytes(44);
|
1765
1746
|
out.length = 0;
|
1766
1747
|
|
1767
1748
|
// 1. If tv is NaN, return "Invalid Date".
|
@@ -1804,7 +1785,7 @@ export const __Date_prototype_toTimeString = (_this: Date) => {
|
|
1804
1785
|
const tv: number = __Porffor_date_read(_this);
|
1805
1786
|
|
1806
1787
|
// 4. If tv is NaN, return "Invalid Date".
|
1807
|
-
let out: bytestring =
|
1788
|
+
let out: bytestring = Porffor.allocateBytes(27);
|
1808
1789
|
out.length = 0;
|
1809
1790
|
|
1810
1791
|
if (Number.isNaN(tv)) {
|
@@ -1832,7 +1813,7 @@ export const __Date_prototype_toDateString = (_this: Date) => {
|
|
1832
1813
|
const tv: number = __Porffor_date_read(_this);
|
1833
1814
|
|
1834
1815
|
// 4. If tv is NaN, return "Invalid Date".
|
1835
|
-
let out: bytestring =
|
1816
|
+
let out: bytestring = Porffor.allocateBytes(20);
|
1836
1817
|
out.length = 0;
|
1837
1818
|
|
1838
1819
|
if (Number.isNaN(tv)) {
|
@@ -1857,7 +1838,7 @@ export const __Date_prototype_toUTCString = (_this: Date) => {
|
|
1857
1838
|
const tv: number = __Porffor_date_read(_this);
|
1858
1839
|
|
1859
1840
|
// 4. If tv is NaN, return "Invalid Date".
|
1860
|
-
let out: bytestring =
|
1841
|
+
let out: bytestring = Porffor.allocateBytes(34);
|
1861
1842
|
out.length = 0;
|
1862
1843
|
|
1863
1844
|
if (Number.isNaN(tv)) {
|
@@ -2030,7 +2011,7 @@ export const Date = function (v0: unknown, v1: unknown, v2: unknown, v3: unknown
|
|
2030
2011
|
}
|
2031
2012
|
|
2032
2013
|
// 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »).
|
2033
|
-
const O: Date =
|
2014
|
+
const O: Date = Porffor.allocateBytes(8);
|
2034
2015
|
|
2035
2016
|
// 7. Set O.[[DateValue]] to dv.
|
2036
2017
|
__Porffor_date_write(O, dv);
|
@@ -28,7 +28,7 @@ export const escape = (input: string|bytestring): bytestring => {
|
|
28
28
|
|
29
29
|
if (outLength == len) return input;
|
30
30
|
|
31
|
-
let output: bytestring =
|
31
|
+
let output: bytestring = Porffor.allocate();
|
32
32
|
output.length = outLength;
|
33
33
|
|
34
34
|
i = Porffor.wasm`local.get ${input}`;
|
@@ -81,7 +81,7 @@ export const escape = (input: string|bytestring): bytestring => {
|
|
81
81
|
|
82
82
|
if (outLength == len) return input;
|
83
83
|
|
84
|
-
let output: bytestring =
|
84
|
+
let output: bytestring = Porffor.allocate();
|
85
85
|
output.length = outLength;
|
86
86
|
|
87
87
|
i = Porffor.wasm`local.get ${input}`;
|
@@ -2,7 +2,7 @@ import type {} from './porffor.d.ts';
|
|
2
2
|
|
3
3
|
// radix: number|any for rawType check
|
4
4
|
export const __Number_prototype_toString = (_this: number, radix: number|any) => {
|
5
|
-
let out: bytestring =
|
5
|
+
let out: bytestring = Porffor.allocate();
|
6
6
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
7
7
|
|
8
8
|
if (!Number.isFinite(_this)) {
|
@@ -235,7 +235,7 @@ export const __Number_prototype_toString = (_this: number, radix: number|any) =>
|
|
235
235
|
};
|
236
236
|
|
237
237
|
export const __Number_prototype_toFixed = (_this: number, fractionDigits: number) => {
|
238
|
-
let out: bytestring =
|
238
|
+
let out: bytestring = Porffor.allocate();
|
239
239
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
240
240
|
|
241
241
|
if (!Number.isFinite(_this)) {
|
@@ -322,7 +322,7 @@ export const __Number_prototype_toFixed = (_this: number, fractionDigits: number
|
|
322
322
|
|
323
323
|
// fractionDigits: number|any for rawType check
|
324
324
|
export const __Number_prototype_toExponential = (_this: number, fractionDigits: number|any) => {
|
325
|
-
let out: bytestring =
|
325
|
+
let out: bytestring = Porffor.allocate();
|
326
326
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
327
327
|
|
328
328
|
if (!Number.isFinite(_this)) {
|
@@ -18,7 +18,7 @@ export const __String_prototype_toUpperCase = (_this: string) => {
|
|
18
18
|
// todo: unicode not just ascii
|
19
19
|
const len: i32 = _this.length;
|
20
20
|
|
21
|
-
let out: string = Porffor.
|
21
|
+
let out: string = Porffor.allocate();
|
22
22
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
23
23
|
|
24
24
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -41,7 +41,7 @@ export const __String_prototype_toUpperCase = (_this: string) => {
|
|
41
41
|
export const __ByteString_prototype_toUpperCase = (_this: bytestring) => {
|
42
42
|
const len: i32 = _this.length;
|
43
43
|
|
44
|
-
let out: bytestring =
|
44
|
+
let out: bytestring = Porffor.allocate();
|
45
45
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
46
46
|
|
47
47
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -64,7 +64,7 @@ export const __String_prototype_toLowerCase = (_this: string) => {
|
|
64
64
|
// todo: unicode not just ascii
|
65
65
|
const len: i32 = _this.length;
|
66
66
|
|
67
|
-
let out: string = Porffor.
|
67
|
+
let out: string = Porffor.allocate();
|
68
68
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
69
69
|
|
70
70
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -87,7 +87,7 @@ export const __String_prototype_toLowerCase = (_this: string) => {
|
|
87
87
|
export const __ByteString_prototype_toLowerCase = (_this: bytestring) => {
|
88
88
|
const len: i32 = _this.length;
|
89
89
|
|
90
|
-
let out: bytestring =
|
90
|
+
let out: bytestring = Porffor.allocate();
|
91
91
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
92
92
|
|
93
93
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -499,7 +499,7 @@ export const __ByteString_prototype_includes = (_this: bytestring, searchString:
|
|
499
499
|
|
500
500
|
|
501
501
|
export const __String_prototype_padStart = (_this: string, targetLength: number, padString: string) => {
|
502
|
-
let out: string = Porffor.
|
502
|
+
let out: string = Porffor.allocate();
|
503
503
|
|
504
504
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
505
505
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -546,7 +546,7 @@ export const __String_prototype_padStart = (_this: string, targetLength: number,
|
|
546
546
|
export const __ByteString_prototype_padStart = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
547
547
|
// todo: handle padString being non-bytestring
|
548
548
|
|
549
|
-
let out: bytestring = Porffor.
|
549
|
+
let out: bytestring = Porffor.allocate();
|
550
550
|
|
551
551
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
552
552
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -588,7 +588,7 @@ export const __ByteString_prototype_padStart = (_this: bytestring, targetLength:
|
|
588
588
|
|
589
589
|
|
590
590
|
export const __String_prototype_padEnd = (_this: string, targetLength: number, padString: string) => {
|
591
|
-
let out: string = Porffor.
|
591
|
+
let out: string = Porffor.allocate();
|
592
592
|
|
593
593
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
594
594
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -635,7 +635,7 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
|
|
635
635
|
export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
636
636
|
// todo: handle padString being non-bytestring
|
637
637
|
|
638
|
-
let out: bytestring = Porffor.
|
638
|
+
let out: bytestring = Porffor.allocate();
|
639
639
|
|
640
640
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
641
641
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -693,7 +693,7 @@ export const __String_prototype_substring = (_this: string, start: number, end:
|
|
693
693
|
if (end < 0) end = 0;
|
694
694
|
if (end > len) end = len;
|
695
695
|
|
696
|
-
let out: string = Porffor.
|
696
|
+
let out: string = Porffor.allocate();
|
697
697
|
|
698
698
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
699
699
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -731,7 +731,7 @@ export const __ByteString_prototype_substring = (_this: bytestring, start: numbe
|
|
731
731
|
if (end < 0) end = 0;
|
732
732
|
if (end > len) end = len;
|
733
733
|
|
734
|
-
let out: bytestring = Porffor.
|
734
|
+
let out: bytestring = Porffor.allocate();
|
735
735
|
|
736
736
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
737
737
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -766,7 +766,7 @@ export const __String_prototype_substr = (_this: string, start: number, length:
|
|
766
766
|
|
767
767
|
if (start + length > len) length = len - start;
|
768
768
|
|
769
|
-
let out: string = Porffor.
|
769
|
+
let out: string = Porffor.allocate();
|
770
770
|
|
771
771
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
772
772
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -803,7 +803,7 @@ export const __ByteString_prototype_substr = (_this: string, start: number, leng
|
|
803
803
|
|
804
804
|
if (start + length > len) length = len - start;
|
805
805
|
|
806
|
-
let out: bytestring = Porffor.
|
806
|
+
let out: bytestring = Porffor.allocate();
|
807
807
|
|
808
808
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
809
809
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -840,7 +840,7 @@ export const __String_prototype_slice = (_this: string, start: number, end: numb
|
|
840
840
|
}
|
841
841
|
if (end > len) end = len;
|
842
842
|
|
843
|
-
let out: string = Porffor.
|
843
|
+
let out: string = Porffor.allocate();
|
844
844
|
|
845
845
|
if (start > end) return out;
|
846
846
|
|
@@ -881,7 +881,7 @@ export const __ByteString_prototype_slice = (_this: bytestring, start: number, e
|
|
881
881
|
}
|
882
882
|
if (end > len) end = len;
|
883
883
|
|
884
|
-
let out: bytestring = Porffor.
|
884
|
+
let out: bytestring = Porffor.allocate();
|
885
885
|
|
886
886
|
if (start > end) return out;
|
887
887
|
|
@@ -903,7 +903,7 @@ export const __ByteString_prototype_slice = (_this: bytestring, start: number, e
|
|
903
903
|
|
904
904
|
|
905
905
|
export const __String_prototype_trimStart = (_this: string) => {
|
906
|
-
let out: string = Porffor.
|
906
|
+
let out: string = Porffor.allocate();
|
907
907
|
|
908
908
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
909
909
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -919,7 +919,7 @@ export const __String_prototype_trimStart = (_this: string) => {
|
|
919
919
|
|
920
920
|
if (start) {
|
921
921
|
// todo: not spec compliant, needs more unicode chars
|
922
|
-
if (Porffor.fastOr(chr ==
|
922
|
+
if (Porffor.fastOr(chr == 0x9, chr == 0xb, chr == 0xc, chr == 0xfeff, chr == 0x20, chr == 0xa0, chr == 0x1680, chr == 0x2000, chr == 0x2001, chr == 0x2002, chr == 0x2003, chr == 0x2004, chr == 0x2005, chr == 0x2006, chr == 0x2007, chr == 0x2008, chr == 0x2009, chr == 0x200a, chr == 0x202f, chr == 0x205f, chr == 0x3000, chr == 0xa, chr == 0xd, chr == 0x2028, chr == 0x2029)) {
|
923
923
|
n++;
|
924
924
|
continue;
|
925
925
|
}
|
@@ -937,7 +937,7 @@ export const __String_prototype_trimStart = (_this: string) => {
|
|
937
937
|
};
|
938
938
|
|
939
939
|
export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
940
|
-
let out: bytestring = Porffor.
|
940
|
+
let out: bytestring = Porffor.allocate();
|
941
941
|
|
942
942
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
943
943
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -952,7 +952,7 @@ export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
|
952
952
|
|
953
953
|
if (start) {
|
954
954
|
// todo: not spec compliant, needs more unicode chars
|
955
|
-
if (Porffor.fastOr(chr ==
|
955
|
+
if (Porffor.fastOr(chr == 0x9, chr == 0xb, chr == 0xc, chr == 0xfeff, chr == 0x20, chr == 0xa0, chr == 0x1680, chr == 0x2000, chr == 0x2001, chr == 0x2002, chr == 0x2003, chr == 0x2004, chr == 0x2005, chr == 0x2006, chr == 0x2007, chr == 0x2008, chr == 0x2009, chr == 0x200a, chr == 0x202f, chr == 0x205f, chr == 0x3000, chr == 0xa, chr == 0xd, chr == 0x2028, chr == 0x2029)) {
|
956
956
|
n++;
|
957
957
|
continue;
|
958
958
|
}
|
@@ -970,7 +970,7 @@ export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
|
970
970
|
|
971
971
|
|
972
972
|
export const __String_prototype_trimEnd = (_this: string) => {
|
973
|
-
let out: string = Porffor.
|
973
|
+
let out: string = Porffor.allocate();
|
974
974
|
|
975
975
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
976
976
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -991,7 +991,7 @@ export const __String_prototype_trimEnd = (_this: string) => {
|
|
991
991
|
|
992
992
|
if (start) {
|
993
993
|
// todo: not spec compliant, needs more unicode chars
|
994
|
-
if (Porffor.fastOr(chr ==
|
994
|
+
if (Porffor.fastOr(chr == 0x9, chr == 0xb, chr == 0xc, chr == 0xfeff, chr == 0x20, chr == 0xa0, chr == 0x1680, chr == 0x2000, chr == 0x2001, chr == 0x2002, chr == 0x2003, chr == 0x2004, chr == 0x2005, chr == 0x2006, chr == 0x2007, chr == 0x2008, chr == 0x2009, chr == 0x200a, chr == 0x202f, chr == 0x205f, chr == 0x3000, chr == 0xa, chr == 0xd, chr == 0x2028, chr == 0x2029)) {
|
995
995
|
n++;
|
996
996
|
continue;
|
997
997
|
}
|
@@ -1008,7 +1008,7 @@ export const __String_prototype_trimEnd = (_this: string) => {
|
|
1008
1008
|
};
|
1009
1009
|
|
1010
1010
|
export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
1011
|
-
let out: bytestring = Porffor.
|
1011
|
+
let out: bytestring = Porffor.allocate();
|
1012
1012
|
|
1013
1013
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
1014
1014
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -1028,7 +1028,7 @@ export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
|
1028
1028
|
|
1029
1029
|
if (start) {
|
1030
1030
|
// todo: not spec compliant, needs more unicode chars
|
1031
|
-
if (Porffor.fastOr(chr ==
|
1031
|
+
if (Porffor.fastOr(chr == 0x9, chr == 0xb, chr == 0xc, chr == 0xfeff, chr == 0x20, chr == 0xa0, chr == 0x1680, chr == 0x2000, chr == 0x2001, chr == 0x2002, chr == 0x2003, chr == 0x2004, chr == 0x2005, chr == 0x2006, chr == 0x2007, chr == 0x2008, chr == 0x2009, chr == 0x200a, chr == 0x202f, chr == 0x205f, chr == 0x3000, chr == 0xa, chr == 0xd, chr == 0x2028, chr == 0x2029)) {
|
1032
1032
|
n++;
|
1033
1033
|
continue;
|
1034
1034
|
}
|
@@ -28,7 +28,7 @@ export const __Symbol_prototype_description$get = (_this: Symbol) => {
|
|
28
28
|
};
|
29
29
|
|
30
30
|
export const __Symbol_prototype_toString = (_this: Symbol) => {
|
31
|
-
let out: bytestring =
|
31
|
+
let out: bytestring = Porffor.allocate();
|
32
32
|
|
33
33
|
// Symbol(
|
34
34
|
Porffor.wasm.i32.store8(out, 83, 0, 4);
|
@@ -26,7 +26,7 @@ export const __ecma262_ToIntegerOrInfinity = (argument: unknown): number => {
|
|
26
26
|
// 7.1.17 ToString (argument)
|
27
27
|
// https://tc39.es/ecma262/#sec-tostring
|
28
28
|
export const __ecma262_ToString = (argument: unknown): bytestring => {
|
29
|
-
let out: bytestring =
|
29
|
+
let out: bytestring = Porffor.allocate();
|
30
30
|
const type: i32 = Porffor.rawType(argument);
|
31
31
|
|
32
32
|
// 1. If argument is a String, return argument.
|
package/compiler/builtins.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as GeneratedBuiltins from './generated_builtins.js';
|
2
2
|
import { Blocktype, Opcodes, Valtype, ValtypeSize } from './wasmSpec.js';
|
3
3
|
import { number } from './embedding.js';
|
4
|
-
import { TYPES } from './types.js';
|
4
|
+
import { TYPES, TYPE_NAMES } from './types.js';
|
5
5
|
import Prefs from './prefs.js';
|
6
6
|
|
7
7
|
export const importedFuncs = [
|
@@ -1099,7 +1099,7 @@ export const BuiltinFuncs = function() {
|
|
1099
1099
|
locals: [ Valtype.i32, Valtype.i32 ],
|
1100
1100
|
returns: [ valtypeBinary ],
|
1101
1101
|
returnType: Prefs.bytestring ? TYPES.bytestring : TYPES.string,
|
1102
|
-
wasm: (scope, {
|
1102
|
+
wasm: (scope, { typeSwitch, makeString }) => {
|
1103
1103
|
const bc = {};
|
1104
1104
|
for (const x in TYPE_NAMES) {
|
1105
1105
|
bc[x] = makeString(scope, TYPE_NAMES[x], false, '#Porffor_type_result');
|
@@ -1159,8 +1159,8 @@ export const BuiltinFuncs = function() {
|
|
1159
1159
|
[ Opcodes.global_get, 1 ],
|
1160
1160
|
...number(pageSize, Valtype.i32),
|
1161
1161
|
[ Opcodes.i32_ge_s ],
|
1162
|
-
[ Opcodes.if,
|
1163
|
-
// bytesWritten =
|
1162
|
+
[ Opcodes.if, Blocktype.void ],
|
1163
|
+
// bytesWritten = bytesToAllocate
|
1164
1164
|
[ Opcodes.local_get, 0 ],
|
1165
1165
|
[ Opcodes.global_set, 1 ],
|
1166
1166
|
|
@@ -1185,5 +1185,62 @@ export const BuiltinFuncs = function() {
|
|
1185
1185
|
]
|
1186
1186
|
};
|
1187
1187
|
|
1188
|
+
this.__Porffor_bytestringToString = {
|
1189
|
+
params: [ Valtype.i32, Valtype.i32 ],
|
1190
|
+
locals: [ Valtype.i32, Valtype.i32 ],
|
1191
|
+
localNames: [ 'src', 'len', '#bytestring_to_string_counter', '#bytestring_to_string_dst' ],
|
1192
|
+
returns: [ Valtype.i32 ],
|
1193
|
+
returnType: TYPES.string,
|
1194
|
+
wasm: [
|
1195
|
+
// dst = grow memory by 1 page
|
1196
|
+
[ Opcodes.i32_const, 1 ],
|
1197
|
+
[ Opcodes.memory_grow, 0 ],
|
1198
|
+
...number(65536, Valtype.i32),
|
1199
|
+
[ Opcodes.i32_mul ],
|
1200
|
+
[ Opcodes.local_tee, 3 ],
|
1201
|
+
|
1202
|
+
// dst.length = len
|
1203
|
+
[ Opcodes.local_get, 1 ],
|
1204
|
+
[ Opcodes.i32_store, 0, 0 ],
|
1205
|
+
|
1206
|
+
// counter = 0
|
1207
|
+
[ Opcodes.i32_const, 0 ],
|
1208
|
+
[ Opcodes.local_set, 2 ],
|
1209
|
+
|
1210
|
+
[ Opcodes.loop, Blocktype.void ],
|
1211
|
+
|
1212
|
+
// base for store later
|
1213
|
+
[ Opcodes.local_get, 2 ],
|
1214
|
+
[ Opcodes.i32_const, 2 ],
|
1215
|
+
[ Opcodes.i32_mul ],
|
1216
|
+
[ Opcodes.local_get, 3 ],
|
1217
|
+
[ Opcodes.i32_add ],
|
1218
|
+
|
1219
|
+
// load char from src
|
1220
|
+
[ Opcodes.local_get, 0 ],
|
1221
|
+
[ Opcodes.local_get, 2 ],
|
1222
|
+
[ Opcodes.i32_add ],
|
1223
|
+
[ Opcodes.i32_load8_u, 0, 4 ],
|
1224
|
+
|
1225
|
+
// store char to dst
|
1226
|
+
[ Opcodes.i32_store16, 0, 4 ],
|
1227
|
+
|
1228
|
+
// counter++
|
1229
|
+
[ Opcodes.local_get, 2 ],
|
1230
|
+
[ Opcodes.i32_const, 1 ],
|
1231
|
+
[ Opcodes.i32_add ],
|
1232
|
+
[ Opcodes.local_tee, 2 ],
|
1233
|
+
|
1234
|
+
// loop if counter < len
|
1235
|
+
[ Opcodes.local_get, 1 ],
|
1236
|
+
[ Opcodes.i32_lt_s ],
|
1237
|
+
[ Opcodes.br_if, 0 ],
|
1238
|
+
[ Opcodes.end ],
|
1239
|
+
|
1240
|
+
// return dst
|
1241
|
+
[ Opcodes.local_get, 3 ]
|
1242
|
+
]
|
1243
|
+
};
|
1244
|
+
|
1188
1245
|
GeneratedBuiltins.BuiltinFuncs.call(this);
|
1189
1246
|
};
|