porffor 0.18.13 → 0.18.15
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/crypto.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 -35
- package/compiler/builtins/string_f64.ts +29 -0
- 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 +464 -464
- 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
|
|
@@ -28,7 +28,7 @@ export const __crypto_randomUUID = (): bytestring => {
|
|
28
28
|
12 // 4 + 8
|
29
29
|
);
|
30
30
|
|
31
|
-
let output: bytestring =
|
31
|
+
let output: bytestring = Porffor.allocate();
|
32
32
|
|
33
33
|
let i: i32 = Porffor.wasm`local.get ${output}`;
|
34
34
|
let j: i32 = bytesPtr;
|
@@ -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)) {
|
@@ -1,24 +1,11 @@
|
|
1
1
|
// @porf --valtype=i32
|
2
2
|
import type {} from './porffor.d.ts';
|
3
3
|
|
4
|
-
export const __String_fromCharCode = (code: i32) => {
|
5
|
-
// todo: support >1 arg
|
6
|
-
if (code < 256) {
|
7
|
-
let out: bytestring = '.';
|
8
|
-
Porffor.wasm.i32.store8(out, code, 0, 4);
|
9
|
-
return out;
|
10
|
-
}
|
11
|
-
|
12
|
-
let out: string = Porffor.s`.`;
|
13
|
-
Porffor.wasm.i32.store16(out, code, 0, 4);
|
14
|
-
return out;
|
15
|
-
};
|
16
|
-
|
17
4
|
export const __String_prototype_toUpperCase = (_this: string) => {
|
18
5
|
// todo: unicode not just ascii
|
19
6
|
const len: i32 = _this.length;
|
20
7
|
|
21
|
-
let out: string = Porffor.
|
8
|
+
let out: string = Porffor.allocate();
|
22
9
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
23
10
|
|
24
11
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -41,7 +28,7 @@ export const __String_prototype_toUpperCase = (_this: string) => {
|
|
41
28
|
export const __ByteString_prototype_toUpperCase = (_this: bytestring) => {
|
42
29
|
const len: i32 = _this.length;
|
43
30
|
|
44
|
-
let out: bytestring =
|
31
|
+
let out: bytestring = Porffor.allocate();
|
45
32
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
46
33
|
|
47
34
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -64,7 +51,7 @@ export const __String_prototype_toLowerCase = (_this: string) => {
|
|
64
51
|
// todo: unicode not just ascii
|
65
52
|
const len: i32 = _this.length;
|
66
53
|
|
67
|
-
let out: string = Porffor.
|
54
|
+
let out: string = Porffor.allocate();
|
68
55
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
69
56
|
|
70
57
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -87,7 +74,7 @@ export const __String_prototype_toLowerCase = (_this: string) => {
|
|
87
74
|
export const __ByteString_prototype_toLowerCase = (_this: bytestring) => {
|
88
75
|
const len: i32 = _this.length;
|
89
76
|
|
90
|
-
let out: bytestring =
|
77
|
+
let out: bytestring = Porffor.allocate();
|
91
78
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
92
79
|
|
93
80
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
@@ -499,7 +486,7 @@ export const __ByteString_prototype_includes = (_this: bytestring, searchString:
|
|
499
486
|
|
500
487
|
|
501
488
|
export const __String_prototype_padStart = (_this: string, targetLength: number, padString: string) => {
|
502
|
-
let out: string = Porffor.
|
489
|
+
let out: string = Porffor.allocate();
|
503
490
|
|
504
491
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
505
492
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -546,7 +533,7 @@ export const __String_prototype_padStart = (_this: string, targetLength: number,
|
|
546
533
|
export const __ByteString_prototype_padStart = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
547
534
|
// todo: handle padString being non-bytestring
|
548
535
|
|
549
|
-
let out: bytestring = Porffor.
|
536
|
+
let out: bytestring = Porffor.allocate();
|
550
537
|
|
551
538
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
552
539
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -588,7 +575,7 @@ export const __ByteString_prototype_padStart = (_this: bytestring, targetLength:
|
|
588
575
|
|
589
576
|
|
590
577
|
export const __String_prototype_padEnd = (_this: string, targetLength: number, padString: string) => {
|
591
|
-
let out: string = Porffor.
|
578
|
+
let out: string = Porffor.allocate();
|
592
579
|
|
593
580
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
594
581
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -635,7 +622,7 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
|
|
635
622
|
export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
636
623
|
// todo: handle padString being non-bytestring
|
637
624
|
|
638
|
-
let out: bytestring = Porffor.
|
625
|
+
let out: bytestring = Porffor.allocate();
|
639
626
|
|
640
627
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
641
628
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -693,7 +680,7 @@ export const __String_prototype_substring = (_this: string, start: number, end:
|
|
693
680
|
if (end < 0) end = 0;
|
694
681
|
if (end > len) end = len;
|
695
682
|
|
696
|
-
let out: string = Porffor.
|
683
|
+
let out: string = Porffor.allocate();
|
697
684
|
|
698
685
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
699
686
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -731,7 +718,7 @@ export const __ByteString_prototype_substring = (_this: bytestring, start: numbe
|
|
731
718
|
if (end < 0) end = 0;
|
732
719
|
if (end > len) end = len;
|
733
720
|
|
734
|
-
let out: bytestring = Porffor.
|
721
|
+
let out: bytestring = Porffor.allocate();
|
735
722
|
|
736
723
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
737
724
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -766,7 +753,7 @@ export const __String_prototype_substr = (_this: string, start: number, length:
|
|
766
753
|
|
767
754
|
if (start + length > len) length = len - start;
|
768
755
|
|
769
|
-
let out: string = Porffor.
|
756
|
+
let out: string = Porffor.allocate();
|
770
757
|
|
771
758
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
772
759
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -803,7 +790,7 @@ export const __ByteString_prototype_substr = (_this: string, start: number, leng
|
|
803
790
|
|
804
791
|
if (start + length > len) length = len - start;
|
805
792
|
|
806
|
-
let out: bytestring = Porffor.
|
793
|
+
let out: bytestring = Porffor.allocate();
|
807
794
|
|
808
795
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
809
796
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -840,7 +827,7 @@ export const __String_prototype_slice = (_this: string, start: number, end: numb
|
|
840
827
|
}
|
841
828
|
if (end > len) end = len;
|
842
829
|
|
843
|
-
let out: string = Porffor.
|
830
|
+
let out: string = Porffor.allocate();
|
844
831
|
|
845
832
|
if (start > end) return out;
|
846
833
|
|
@@ -881,7 +868,7 @@ export const __ByteString_prototype_slice = (_this: bytestring, start: number, e
|
|
881
868
|
}
|
882
869
|
if (end > len) end = len;
|
883
870
|
|
884
|
-
let out: bytestring = Porffor.
|
871
|
+
let out: bytestring = Porffor.allocate();
|
885
872
|
|
886
873
|
if (start > end) return out;
|
887
874
|
|
@@ -903,7 +890,7 @@ export const __ByteString_prototype_slice = (_this: bytestring, start: number, e
|
|
903
890
|
|
904
891
|
|
905
892
|
export const __String_prototype_trimStart = (_this: string) => {
|
906
|
-
let out: string = Porffor.
|
893
|
+
let out: string = Porffor.allocate();
|
907
894
|
|
908
895
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
909
896
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -919,7 +906,7 @@ export const __String_prototype_trimStart = (_this: string) => {
|
|
919
906
|
|
920
907
|
if (start) {
|
921
908
|
// todo: not spec compliant, needs more unicode chars
|
922
|
-
if (Porffor.fastOr(chr ==
|
909
|
+
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
910
|
n++;
|
924
911
|
continue;
|
925
912
|
}
|
@@ -937,7 +924,7 @@ export const __String_prototype_trimStart = (_this: string) => {
|
|
937
924
|
};
|
938
925
|
|
939
926
|
export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
940
|
-
let out: bytestring = Porffor.
|
927
|
+
let out: bytestring = Porffor.allocate();
|
941
928
|
|
942
929
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
943
930
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -952,7 +939,7 @@ export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
|
952
939
|
|
953
940
|
if (start) {
|
954
941
|
// todo: not spec compliant, needs more unicode chars
|
955
|
-
if (Porffor.fastOr(chr ==
|
942
|
+
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
943
|
n++;
|
957
944
|
continue;
|
958
945
|
}
|
@@ -970,7 +957,7 @@ export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
|
970
957
|
|
971
958
|
|
972
959
|
export const __String_prototype_trimEnd = (_this: string) => {
|
973
|
-
let out: string = Porffor.
|
960
|
+
let out: string = Porffor.allocate();
|
974
961
|
|
975
962
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
976
963
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -991,7 +978,7 @@ export const __String_prototype_trimEnd = (_this: string) => {
|
|
991
978
|
|
992
979
|
if (start) {
|
993
980
|
// todo: not spec compliant, needs more unicode chars
|
994
|
-
if (Porffor.fastOr(chr ==
|
981
|
+
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
982
|
n++;
|
996
983
|
continue;
|
997
984
|
}
|
@@ -1008,7 +995,7 @@ export const __String_prototype_trimEnd = (_this: string) => {
|
|
1008
995
|
};
|
1009
996
|
|
1010
997
|
export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
1011
|
-
let out: bytestring = Porffor.
|
998
|
+
let out: bytestring = Porffor.allocate();
|
1012
999
|
|
1013
1000
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
1014
1001
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
@@ -1028,7 +1015,7 @@ export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
|
1028
1015
|
|
1029
1016
|
if (start) {
|
1030
1017
|
// todo: not spec compliant, needs more unicode chars
|
1031
|
-
if (Porffor.fastOr(chr ==
|
1018
|
+
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
1019
|
n++;
|
1033
1020
|
continue;
|
1034
1021
|
}
|
@@ -5,4 +5,33 @@ import type {} from './porffor.d.ts';
|
|
5
5
|
export const String = function (value: any): bytestring {
|
6
6
|
if (!new.target && Porffor.rawType(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
|
7
7
|
return __ecma262_ToString(value);
|
8
|
+
};
|
9
|
+
|
10
|
+
export const __String_fromCharCode = (...codes: any[]): bytestring|string => {
|
11
|
+
let out: string = Porffor.allocate();
|
12
|
+
|
13
|
+
const len: i32 = codes.length;
|
14
|
+
out.length = len;
|
15
|
+
|
16
|
+
let bytestringable: boolean = true;
|
17
|
+
for (let i: i32 = 0; i < len; i++) {
|
18
|
+
const v: i32 = __ecma262_ToIntegerOrInfinity(codes[i]);
|
19
|
+
if (v > 0xFF) bytestringable = false;
|
20
|
+
|
21
|
+
Porffor.wasm.i32.store16(Porffor.wasm`local.get ${out}` + i * 2, v, 0, 4);
|
22
|
+
}
|
23
|
+
|
24
|
+
if (bytestringable) {
|
25
|
+
let out2: bytestring = Porffor.wasm`local.get ${out}`;
|
26
|
+
for (let i: i32 = 0; i < len; i++) {
|
27
|
+
Porffor.wasm.i32.store8(
|
28
|
+
Porffor.wasm`local.get ${out}` + i,
|
29
|
+
Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${out}` + i * 2, 0, 4),
|
30
|
+
0, 4);
|
31
|
+
}
|
32
|
+
|
33
|
+
return out2;
|
34
|
+
}
|
35
|
+
|
36
|
+
return out;
|
8
37
|
};
|
@@ -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
|
};
|