porffor 0.18.12 → 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.
@@ -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}`;
@@ -1574,7 +1574,7 @@ export const __Porffor_bytestring_appendPadNum = (str: bytestring, num: number,
1574
1574
  export const __ecma262_ToUTCDTSF = (t: number): bytestring => {
1575
1575
  const year: number = __ecma262_YearFromTime(t);
1576
1576
 
1577
- let out: bytestring = '';
1577
+ let out: bytestring = Porffor.allocateBytes(31);
1578
1578
  out.length = 0;
1579
1579
 
1580
1580
  if (Porffor.fastOr(year < 0, year >= 10000)) {
@@ -1670,7 +1670,7 @@ export const __ecma262_TimeString = (tv: number): bytestring => {
1670
1670
  const second: number = __ecma262_SecFromTime(tv);
1671
1671
 
1672
1672
  // 4. Return the string-concatenation of hour, ":", minute, ":", second, the code unit 0x0020 (SPACE), and "GMT".
1673
- let out: bytestring = '';
1673
+ let out: bytestring = Porffor.allocateBytes(16);
1674
1674
  out.length = 0;
1675
1675
 
1676
1676
  __Porffor_bytestring_appendPadNum(out, hour, 2);
@@ -1709,7 +1709,7 @@ export const __ecma262_DateString = (tv: number): bytestring => {
1709
1709
  // 5. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
1710
1710
  // 6. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
1711
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.
1712
- let out: bytestring = '';
1712
+ let out: bytestring = Porffor.allocateBytes(20);
1713
1713
  out.length = 0;
1714
1714
 
1715
1715
  // weekday
@@ -1742,7 +1742,7 @@ export const __ecma262_TimeZoneString = (tv: number) => {
1742
1742
  // 21.4.4.41.4 ToDateString (tv)
1743
1743
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-todatestring
1744
1744
  export const __ecma262_ToDateString = (tv: number) => {
1745
- let out: bytestring = '';
1745
+ let out: bytestring = Porffor.allocateBytes(44);
1746
1746
  out.length = 0;
1747
1747
 
1748
1748
  // 1. If tv is NaN, return "Invalid Date".
@@ -1785,7 +1785,7 @@ export const __Date_prototype_toTimeString = (_this: Date) => {
1785
1785
  const tv: number = __Porffor_date_read(_this);
1786
1786
 
1787
1787
  // 4. If tv is NaN, return "Invalid Date".
1788
- let out: bytestring = '';
1788
+ let out: bytestring = Porffor.allocateBytes(27);
1789
1789
  out.length = 0;
1790
1790
 
1791
1791
  if (Number.isNaN(tv)) {
@@ -1813,7 +1813,7 @@ export const __Date_prototype_toDateString = (_this: Date) => {
1813
1813
  const tv: number = __Porffor_date_read(_this);
1814
1814
 
1815
1815
  // 4. If tv is NaN, return "Invalid Date".
1816
- let out: bytestring = '';
1816
+ let out: bytestring = Porffor.allocateBytes(20);
1817
1817
  out.length = 0;
1818
1818
 
1819
1819
  if (Number.isNaN(tv)) {
@@ -1838,7 +1838,7 @@ export const __Date_prototype_toUTCString = (_this: Date) => {
1838
1838
  const tv: number = __Porffor_date_read(_this);
1839
1839
 
1840
1840
  // 4. If tv is NaN, return "Invalid Date".
1841
- let out: bytestring = '';
1841
+ let out: bytestring = Porffor.allocateBytes(34);
1842
1842
  out.length = 0;
1843
1843
 
1844
1844
  if (Number.isNaN(tv)) {
@@ -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.s``;
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.s``;
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.s``;
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.bs``;
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.s``;
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.bs``;
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.s``;
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.bs``;
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.s``;
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.bs``;
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.s``;
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.bs``;
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.s``;
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 == 0x0009, chr == 0x000b, chr == 0x000c, chr == 0x0020, chr == 0x00a0, chr == 0xfeff, chr == 0x000a, chr == 0x000d, chr == 0x2028, chr == 0x2029)) {
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.bs``;
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 == 0x0009, chr == 0x000b, chr == 0x000c, chr == 0x0020, chr == 0x00a0, chr == 0xfeff, chr == 0x000a, chr == 0x000d, chr == 0x2028, chr == 0x2029)) {
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.s``;
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 == 0x0009, chr == 0x000b, chr == 0x000c, chr == 0x0020, chr == 0x00a0, chr == 0xfeff, chr == 0x000a, chr == 0x000d, chr == 0x2028, chr == 0x2029)) {
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.bs``;
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 == 0x0009, chr == 0x000b, chr == 0x000c, chr == 0x0020, chr == 0x00a0, chr == 0xfeff, chr == 0x000a, chr == 0x000d, chr == 0x2028, chr == 0x2029)) {
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.
@@ -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, { TYPE_NAMES, typeSwitch, makeString }) => {
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, Valtype.i32 ],
1163
- // bytesWritten = 0
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
  };