porffor 0.58.18 → 0.59.0

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/AGENT.md ADDED
@@ -0,0 +1,22 @@
1
+ you are an assistant coder for Porffor - an early javascript and typescript to webassembly and native ahead-of-time compiler. the codebase is written in js and ts.
2
+
3
+ IMPORTANT:
4
+ - built-ins apis (Date, String.prototype, etc) are written in ts inside `compiler/builtins`
5
+ - once you update a file inside that directory, you MUST run `./porf precompile` to compile to make your changes effective
6
+
7
+ Test your work using the test262 tools available, iterate independently but do not get stuck on one chain of thought or approach. Paths for test262 tools should be relative to the 'test262/test' directory (e.g., 'built-ins/RegExp' NOT 'test262/test/built-ins/RegExp').
8
+
9
+ You can also do the following via bash/shell commands:
10
+ - To get an overview of the most failing directories, use the command: `node test262/fails.cjs`
11
+ - To just evaluate code in the engine, use the command: `./porf -p "..."`
12
+
13
+ ## Code Style
14
+ - After finishing, check if your work/diff could be simplified
15
+ - Always use single quotes (unless double is required)
16
+ - 2-space indentation, LF line endings, no trailing whitespace
17
+ - Built-in APIs in `compiler/builtins/` written in TypeScript
18
+ - Inline code in built-ins, avoid helper functions
19
+ - Use semicolons
20
+ - Do not use trailing commas
21
+ - Use const/let, avoid var
22
+ - Follow existing naming: camelCase for variables, PascalCase for types
@@ -208,20 +208,9 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
208
208
  const bytesPerFunc = funcs.bytesPerFuncLut();
209
209
  for (let i = 0; i < indirectFuncs.length; i++) {
210
210
  const func = indirectFuncs[i].wrapperOf;
211
- let name = func.name;
212
211
 
213
212
  // userland exposed .length
214
- let length = func.jsLength;
215
- if (length == null) {
216
- length = func.params.length;
217
- if (func.constr) length -= 4;
218
- if (func.method) length -= 2;
219
- if (!func.internal || func.typedParams) length = Math.floor(length / 2);
220
-
221
- // remove _this from internal prototype funcs
222
- if (func.internal && name.includes('_prototype_')) length--;
223
- }
224
-
213
+ const length = func.jsLength;
225
214
  bytes.push(length % 256, (length / 256 | 0) % 256);
226
215
 
227
216
  let flags = 0b00000000; // 8 flag bits
@@ -229,8 +218,8 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
229
218
  if (func.constr) flags |= 0b10;
230
219
  bytes.push(flags);
231
220
 
221
+ let name = func.name;
232
222
  if (name.startsWith('#')) name = '';
233
-
234
223
  // eg: __String_prototype_toLowerCase -> toLowerCase
235
224
  if (name.startsWith('__')) name = name.split('_').pop();
236
225
 
@@ -114,6 +114,54 @@ export const __Array_prototype_push = (_this: any[], ...items: any[]) => {
114
114
  return _this.length = len + itemsLen;
115
115
  };
116
116
 
117
+ export const __Array_prototype_pop = (_this: any[]) => {
118
+ const len: i32 = _this.length;
119
+ if (len == 0) return undefined;
120
+
121
+ const lastIndex: i32 = len - 1;
122
+ const element: any = _this[lastIndex];
123
+ _this.length = lastIndex;
124
+
125
+ return element;
126
+ };
127
+
128
+ export const __Array_prototype_shift = (_this: any[]) => {
129
+ const len: i32 = _this.length;
130
+ if (len == 0) return undefined;
131
+
132
+ const element: any = _this[0];
133
+ _this.length = len - 1;
134
+
135
+ // shift all elements left by 1 using memory.copy
136
+ Porffor.wasm`;; ptr = ptr(_this) + 4
137
+ local #shift_ptr i32
138
+ local.get ${_this}
139
+ i32.to_u
140
+ i32.const 4
141
+ i32.add
142
+ local.set #shift_ptr
143
+
144
+ ;; dst = ptr (start of array)
145
+ local.get #shift_ptr
146
+
147
+ ;; src = ptr + 9 (second element)
148
+ local.get #shift_ptr
149
+ i32.const 9
150
+ i32.add
151
+
152
+ ;; size = (len - 1) * 9
153
+ local.get ${len}
154
+ i32.to_u
155
+ i32.const 1
156
+ i32.sub
157
+ i32.const 9
158
+ i32.mul
159
+
160
+ memory.copy 0 0`;
161
+
162
+ return element;
163
+ };
164
+
117
165
  export const __Array_prototype_unshift = (_this: any[], ...items: any[]) => {
118
166
  let len: i32 = _this.length;
119
167
  const itemsLen: i32 = items.length;
@@ -57,6 +57,13 @@ export const __Porffor_array_fastPushI32 = (arr: any[], el: any): i32 => {
57
57
  return len;
58
58
  };
59
59
 
60
+ export const __Porffor_array_fastPopI32 = (arr: any[]): i32 => {
61
+ let len: i32 = arr.length;
62
+ const ret: any = arr[--len];
63
+ arr.length = len;
64
+ return ret;
65
+ };
66
+
60
67
  export const __Porffor_regex_compile = (patternStr: bytestring, flagsStr: bytestring): RegExp => {
61
68
  const ptr: i32 = Porffor.allocate();
62
69
  Porffor.wasm.i32.store(ptr, patternStr, 0, 0);
@@ -341,21 +348,21 @@ export const __Porffor_regex_compile = (patternStr: bytestring, flagsStr: bytest
341
348
 
342
349
  let thisAltDepth: i32 = altDepth[groupDepth];
343
350
  while (thisAltDepth-- > 0) {
344
- const jumpPtr: i32 = altStack.pop();
351
+ const jumpPtr: i32 = Porffor.array.fastPopI32(altStack);
345
352
  Porffor.wasm.i32.store16(jumpPtr, bcPtr - jumpPtr, 0, 1);
346
353
  }
347
354
  altDepth[groupDepth] = 0;
348
355
 
349
356
  groupDepth -= 1;
350
357
 
351
- const capturePop: i32 = groupStack.pop();
358
+ const capturePop: i32 = Porffor.array.fastPopI32(groupStack);
352
359
  if (capturePop != -1) {
353
360
  Porffor.wasm.i32.store8(bcPtr, 0x31, 0, 0); // end capture
354
361
  Porffor.wasm.i32.store8(bcPtr, capturePop, 0, 1);
355
362
  bcPtr += 2;
356
363
  }
357
364
 
358
- const groupStartPtr: i32 = groupStack.pop();
365
+ const groupStartPtr: i32 = Porffor.array.fastPopI32(groupStack);
359
366
  lastWasAtom = true;
360
367
  lastAtomStart = groupStartPtr;
361
368
  continue;
@@ -751,7 +758,7 @@ export const __Porffor_regex_compile = (patternStr: bytestring, flagsStr: bytest
751
758
 
752
759
  let thisAltDepth: i32 = altDepth[groupDepth];
753
760
  while (thisAltDepth-- > 0) {
754
- const jumpPtr: i32 = altStack.pop();
761
+ const jumpPtr: i32 = Porffor.array.fastPopI32(altStack);
755
762
  Porffor.wasm.i32.store16(jumpPtr, bcPtr - jumpPtr, 0, 1);
756
763
  }
757
764
  altDepth[groupDepth] = 0;
@@ -780,11 +787,11 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
780
787
  const inputLen: i32 = Porffor.wasm.i32.load(input, 0, 0);
781
788
  let searchStart: i32 = 0;
782
789
  if (global || sticky) {
783
- searchStart = Porffor.wasm.i32.load(regexp, 0, 8);
790
+ searchStart = Porffor.wasm.i32.load16_u(regexp, 0, 8);
784
791
  }
785
792
 
786
793
  if (searchStart > inputLen) {
787
- if (global || sticky) Porffor.wasm.i32.store(regexp, 0, 0, 8);
794
+ if (global || sticky) Porffor.wasm.i32.store16(regexp, 0, 0, 8);
788
795
  return null;
789
796
  }
790
797
 
@@ -912,7 +919,7 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
912
919
  backtrack = true;
913
920
  } else {
914
921
  const classId: i32 = Porffor.wasm.i32.load8_u(pc, 0, 1);
915
- const char: i32 = Porffor.wasm.i32.load8_u(input + 4 + sp, 0, 0);
922
+ const char: i32 = Porffor.wasm.i32.load8_u(input + sp, 0, 4);
916
923
  let isMatch: boolean = false;
917
924
  if (classId == 1) isMatch = char >= 48 && char <= 57;
918
925
  else if (classId == 2) isMatch = !(char >= 48 && char <= 57);
@@ -941,16 +948,56 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
941
948
  backtrack = true;
942
949
  }
943
950
  } else if (op == 0x07) { // word boundary
944
- const prevIsWord = sp > 0 && ((Porffor.wasm.i32.load8_u(input + sp, 0, 3) >= 65 && Porffor.wasm.i32.load8_u(input + sp, 0, 3) <= 90) || (Porffor.wasm.i32.load8_u(input + sp, 0, 3) >= 97 && Porffor.wasm.i32.load8_u(input + sp, 0, 3) <= 122) || (Porffor.wasm.i32.load8_u(input + sp, 0, 3) >= 48 && Porffor.wasm.i32.load8_u(input + sp, 0, 3) <= 57) || Porffor.wasm.i32.load8_u(input + sp, 0, 3) == 95);
945
- const nextIsWord = sp < inputLen && ((Porffor.wasm.i32.load8_u(input + sp, 0, 4) >= 65 && Porffor.wasm.i32.load8_u(input + sp, 0, 4) <= 90) || (Porffor.wasm.i32.load8_u(input + sp, 0, 4) >= 97 && Porffor.wasm.i32.load8_u(input + sp, 0, 4) <= 122) || (Porffor.wasm.i32.load8_u(input + sp, 0, 4) >= 48 && Porffor.wasm.i32.load8_u(input + sp, 0, 4) <= 57) || Porffor.wasm.i32.load8_u(input + sp, 0, 4) == 95);
951
+ let prevIsWord: boolean = false;
952
+ if (sp > 0) {
953
+ const prevChar: i32 = Porffor.wasm.i32.load8_u(input + sp, 0, 3);
954
+ prevIsWord = Porffor.fastOr(
955
+ prevChar >= 65 && prevChar <= 90, // A-Z
956
+ prevChar >= 97 && prevChar <= 122, // a-z
957
+ prevChar >= 48 && prevChar <= 57, // 0-9
958
+ prevChar == 95 // _
959
+ );
960
+ }
961
+
962
+ let nextIsWord: boolean = false;
963
+ if (sp < inputLen) {
964
+ const nextChar: i32 = Porffor.wasm.i32.load8_u(input + sp, 0, 4);
965
+ nextIsWord = Porffor.fastOr(
966
+ nextChar >= 65 && nextChar <= 90, // A-Z
967
+ nextChar >= 97 && nextChar <= 122, // a-z
968
+ nextChar >= 48 && nextChar <= 57, // 0-9
969
+ nextChar == 95 // _
970
+ );
971
+ }
972
+
946
973
  if (prevIsWord != nextIsWord) {
947
974
  pc += 1;
948
975
  } else {
949
976
  backtrack = true;
950
977
  }
951
978
  } else if (op == 0x08) { // non-word boundary
952
- const prevIsWord = sp > 0 && ((Porffor.wasm.i32.load8_u(input + sp, 0, 3) >= 65 && Porffor.wasm.i32.load8_u(input + sp, 0, 3) <= 90) || (Porffor.wasm.i32.load8_u(input + sp, 0, 3) >= 97 && Porffor.wasm.i32.load8_u(input + sp, 0, 3) <= 122) || (Porffor.wasm.i32.load8_u(input + sp, 0, 3) >= 48 && Porffor.wasm.i32.load8_u(input + sp, 0, 3) <= 57) || Porffor.wasm.i32.load8_u(input + sp, 0, 3) == 95);
953
- const nextIsWord = sp < inputLen && ((Porffor.wasm.i32.load8_u(input + sp, 0, 4) >= 65 && Porffor.wasm.i32.load8_u(input + sp, 0, 4) <= 90) || (Porffor.wasm.i32.load8_u(input + sp, 0, 4) >= 97 && Porffor.wasm.i32.load8_u(input + sp, 0, 4) <= 122) || (Porffor.wasm.i32.load8_u(input + sp, 0, 4) >= 48 && Porffor.wasm.i32.load8_u(input + sp, 0, 4) <= 57) || Porffor.wasm.i32.load8_u(input + sp, 0, 4) == 95);
979
+ let prevIsWord: boolean = false;
980
+ if (sp > 0) {
981
+ const prevChar: i32 = Porffor.wasm.i32.load8_u(input + sp, 0, 3);
982
+ prevIsWord = Porffor.fastOr(
983
+ prevChar >= 65 && prevChar <= 90, // A-Z
984
+ prevChar >= 97 && prevChar <= 122, // a-z
985
+ prevChar >= 48 && prevChar <= 57, // 0-9
986
+ prevChar == 95 // _
987
+ );
988
+ }
989
+
990
+ let nextIsWord: boolean = false;
991
+ if (sp < inputLen) {
992
+ const nextChar: i32 = Porffor.wasm.i32.load8_u(input + sp, 0, 4);
993
+ nextIsWord = Porffor.fastOr(
994
+ nextChar >= 65 && nextChar <= 90, // A-Z
995
+ nextChar >= 97 && nextChar <= 122, // a-z
996
+ nextChar >= 48 && nextChar <= 57, // 0-9
997
+ nextChar == 95 // _
998
+ );
999
+ }
1000
+
954
1001
  if (prevIsWord == nextIsWord) {
955
1002
  pc += 1;
956
1003
  } else {
@@ -1032,9 +1079,9 @@ export const __Porffor_regex_interpret = (regexp: RegExp, input: i32, isTest: bo
1032
1079
  if (backtrack) {
1033
1080
  if (backtrackStack.length == 0) break;
1034
1081
  // Porffor.log(`backtrack! before: captures.length = ${captures.length}, sp = ${sp}, pc = ${pc}`);
1035
- captures.length = backtrackStack.pop();
1036
- sp = backtrackStack.pop();
1037
- pc = backtrackStack.pop();
1082
+ captures.length = Porffor.array.fastPopI32(backtrackStack);
1083
+ sp = Porffor.array.fastPopI32(backtrackStack);
1084
+ pc = Porffor.array.fastPopI32(backtrackStack);
1038
1085
  // Porffor.log(`backtrack! after: captures.length = ${captures.length}, sp = ${sp}, pc = ${pc}`);
1039
1086
  }
1040
1087
  }
@@ -353,6 +353,72 @@ export const __Porffor_strcat = (a: any, b: any): any => {
353
353
  };
354
354
 
355
355
 
356
+ export const __String_prototype_at = (_this: string, index: number) => {
357
+ const len: i32 = _this.length;
358
+
359
+ if (index < 0) index = len + index;
360
+ if (Porffor.fastOr(index < 0, index >= len)) return undefined;
361
+
362
+ let out: string = Porffor.allocateBytes(8);
363
+ Porffor.wasm.i32.store(out, 1, 0, 0); // out.length = 1
364
+
365
+ Porffor.wasm.i32.store16(
366
+ Porffor.wasm`local.get ${out}`,
367
+ Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${_this}` + index * 2, 0, 4),
368
+ 0, 4);
369
+
370
+ return out;
371
+ };
372
+
373
+ export const __ByteString_prototype_at = (_this: bytestring, index: number) => {
374
+ const len: i32 = _this.length;
375
+
376
+ if (index < 0) index = len + index;
377
+ if (Porffor.fastOr(index < 0, index >= len)) return undefined;
378
+
379
+ let out: bytestring = Porffor.allocateBytes(8);
380
+ Porffor.wasm.i32.store(out, 1, 0, 0); // out.length = 1
381
+
382
+ Porffor.wasm.i32.store8(
383
+ Porffor.wasm`local.get ${out}`,
384
+ Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${_this}` + index, 0, 4),
385
+ 0, 4);
386
+
387
+ return out;
388
+ };
389
+
390
+ export const __String_prototype_charAt = (_this: string, index: number) => {
391
+ const len: i32 = _this.length;
392
+
393
+ if (Porffor.fastOr(index < 0, index >= len)) return '';
394
+
395
+ let out: string = Porffor.allocateBytes(8);
396
+ Porffor.wasm.i32.store(out, 1, 0, 0); // out.length = 1
397
+
398
+ Porffor.wasm.i32.store16(
399
+ Porffor.wasm`local.get ${out}`,
400
+ Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${_this}` + index * 2, 0, 4),
401
+ 0, 4);
402
+
403
+ return out;
404
+ };
405
+
406
+ export const __ByteString_prototype_charAt = (_this: bytestring, index: number) => {
407
+ const len: i32 = _this.length;
408
+
409
+ if (Porffor.fastOr(index < 0, index >= len)) return '';
410
+
411
+ let out: bytestring = Porffor.allocateBytes(8);
412
+ Porffor.wasm.i32.store(out, 1, 0, 0); // out.length = 1
413
+
414
+ Porffor.wasm.i32.store8(
415
+ Porffor.wasm`local.get ${out}`,
416
+ Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${_this}` + index, 0, 4),
417
+ 0, 4);
418
+
419
+ return out;
420
+ };
421
+
356
422
  export const __String_prototype_toUpperCase = (_this: string) => {
357
423
  // todo: unicode not just ascii
358
424
  const len: i32 = _this.length;
@@ -451,7 +517,6 @@ export const __ByteString_prototype_toLocaleLowerCase = (_this: bytestring) => _
451
517
  export const __String_prototype_codePointAt = (_this: string, index: number) => {
452
518
  const len: i32 = _this.length;
453
519
 
454
- index |= 0;
455
520
  if (Porffor.fastOr(index < 0, index >= len)) return undefined;
456
521
 
457
522
  index *= 2;
@@ -474,7 +539,6 @@ export const __String_prototype_codePointAt = (_this: string, index: number) =>
474
539
  export const __ByteString_prototype_codePointAt = (_this: bytestring, index: number) => {
475
540
  const len: i32 = _this.length;
476
541
 
477
- index |= 0;
478
542
  if (Porffor.fastOr(index < 0, index >= len)) return undefined;
479
543
 
480
544
  // bytestrings cannot have surrogates, so just do charCodeAt
@@ -494,7 +558,6 @@ export const __String_prototype_startsWith = (_this: string, searchString: strin
494
558
  const len: i32 = _this.length;
495
559
  if (position > 0) {
496
560
  if (position > len) position = len;
497
- else position |= 0;
498
561
  } else position = 0;
499
562
 
500
563
  thisPtr += position * 2;
@@ -524,7 +587,6 @@ export const __ByteString_prototype_startsWith = (_this: bytestring, searchStrin
524
587
  const len: i32 = _this.length;
525
588
  if (position > 0) {
526
589
  if (position > len) position = len;
527
- else position |= 0;
528
590
  } else position = 0;
529
591
 
530
592
  thisPtr += position;
@@ -557,7 +619,6 @@ export const __String_prototype_endsWith = (_this: string, searchString: string,
557
619
 
558
620
  if (endPosition > 0) {
559
621
  if (endPosition > len) endPosition = len;
560
- else endPosition |= 0;
561
622
  } else endPosition = 0;
562
623
 
563
624
  endPosition -= searchLen;
@@ -598,7 +659,6 @@ export const __ByteString_prototype_endsWith = (_this: bytestring, searchString:
598
659
 
599
660
  if (endPosition > 0) {
600
661
  if (endPosition > len) endPosition = len;
601
- else endPosition |= 0;
602
662
  } else endPosition = 0;
603
663
 
604
664
  endPosition -= searchLen;
@@ -631,7 +691,6 @@ export const __String_prototype_indexOf = (_this: string, searchString: string,
631
691
  const len: i32 = _this.length;
632
692
  if (position > 0) {
633
693
  if (position > len) position = len;
634
- else position |= 0;
635
694
  } else position = 0;
636
695
 
637
696
  const thisPtrEnd: i32 = thisPtr + (len * 2) - searchLenX2;
@@ -672,7 +731,6 @@ export const __ByteString_prototype_indexOf = (_this: bytestring, searchString:
672
731
  const len: i32 = _this.length;
673
732
  if (position > 0) {
674
733
  if (position > len) position = len;
675
- else position |= 0;
676
734
  } else position = 0;
677
735
 
678
736
  const thisPtrEnd: i32 = thisPtr + len - searchLen;
@@ -718,7 +776,6 @@ export const __String_prototype_lastIndexOf = (_this: string, searchString: stri
718
776
  if (position > 0) {
719
777
  const max: i32 = len - searchLen;
720
778
  if (position > max) position = max;
721
- else position |= 0;
722
779
  } else position = 0;
723
780
 
724
781
  const thisPtrStart: i32 = thisPtr;
@@ -764,7 +821,6 @@ export const __ByteString_prototype_lastIndexOf = (_this: bytestring, searchStri
764
821
  if (position > 0) {
765
822
  const max: i32 = len - searchLen;
766
823
  if (position > max) position = max;
767
- else position |= 0;
768
824
  } else position = 0;
769
825
 
770
826
  const thisPtrStart: i32 = thisPtr;
@@ -804,7 +860,6 @@ export const __String_prototype_includes = (_this: string, searchString: string,
804
860
  const len: i32 = _this.length;
805
861
  if (position > 0) {
806
862
  if (position > len) position = len;
807
- else position |= 0;
808
863
  } else position = 0;
809
864
 
810
865
  const thisPtrEnd: i32 = thisPtr + (len * 2) - searchLenX2;
@@ -845,7 +900,6 @@ export const __ByteString_prototype_includes = (_this: bytestring, searchString:
845
900
  const len: i32 = _this.length;
846
901
  if (position > 0) {
847
902
  if (position > len) position = len;
848
- else position |= 0;
849
903
  } else position = 0;
850
904
 
851
905
  const thisPtrEnd: i32 = thisPtr + len - searchLen;
@@ -878,11 +932,9 @@ export const __String_prototype_padStart = (_this: string, targetLength: number,
878
932
 
879
933
  let outPtr: i32 = Porffor.wasm`local.get ${out}`;
880
934
  let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
881
- // const padStringPtr: i32 = Porffor.wasm`local.get ${padString}`;
882
935
 
883
936
  const len: i32 = _this.length;
884
937
 
885
- targetLength |= 0;
886
938
 
887
939
  const todo: i32 = targetLength - len;
888
940
  if (todo > 0) {
@@ -897,8 +949,7 @@ export const __String_prototype_padStart = (_this: string, targetLength: number,
897
949
  const padStringLen: i32 = padString.length;
898
950
  if (padStringLen > 0) {
899
951
  for (let i: i32 = 0; i < todo; i++) {
900
- // Porffor.wasm.i32.store16(outPtr, Porffor.wasm.i32.load16_u(padStringPtr + (i % padStringLen) * 2, 0, 4), 0, 4);
901
- Porffor.wasm.i32.store16(outPtr, padString.charCodeAt(i % padStringLen), 0, 4);
952
+ Porffor.wasm.i32.store16(outPtr, Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${padString}` + (i % padStringLen) * 2, 0, 4), 0, 4);
902
953
  outPtr += 2;
903
954
  }
904
955
  out.length = targetLength;
@@ -925,11 +976,9 @@ export const __ByteString_prototype_padStart = (_this: bytestring, targetLength:
925
976
 
926
977
  let outPtr: i32 = Porffor.wasm`local.get ${out}`;
927
978
  let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
928
- const padStringPtr: i32 = Porffor.wasm`local.get ${padString}`;
929
979
 
930
980
  const len: i32 = _this.length;
931
981
 
932
- targetLength |= 0;
933
982
 
934
983
  const todo: i32 = targetLength - len;
935
984
  if (todo > 0) {
@@ -943,8 +992,7 @@ export const __ByteString_prototype_padStart = (_this: bytestring, targetLength:
943
992
  const padStringLen: i32 = padString.length;
944
993
  if (padStringLen > 0) {
945
994
  for (let i: i32 = 0; i < todo; i++) {
946
- Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(padStringPtr + (i % padStringLen), 0, 4), 0, 4);
947
- // Porffor.wasm.i32.store8(outPtr++, padString.charCodeAt(i % padStringLen), 0, 4);
995
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${padString}` + (i % padStringLen), 0, 4), 0, 4);
948
996
  }
949
997
 
950
998
  out.length = targetLength;
@@ -967,7 +1015,6 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
967
1015
 
968
1016
  let outPtr: i32 = Porffor.wasm`local.get ${out}`;
969
1017
  let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
970
- // const padStringPtr: i32 = Porffor.wasm`local.get ${padString}`;
971
1018
 
972
1019
  const len: i32 = _this.length;
973
1020
 
@@ -980,7 +1027,6 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
980
1027
  outPtr += 2;
981
1028
  }
982
1029
 
983
- targetLength |= 0;
984
1030
 
985
1031
  const todo: i32 = targetLength - len;
986
1032
  if (todo > 0) {
@@ -995,8 +1041,7 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
995
1041
  const padStringLen: i32 = padString.length;
996
1042
  if (padStringLen > 0) {
997
1043
  for (let i: i32 = 0; i < todo; i++) {
998
- // Porffor.wasm.i32.store16(outPtr, Porffor.wasm.i32.load16_u(padStringPtr + (i % padStringLen) * 2, 0, 4), 0, 4);
999
- Porffor.wasm.i32.store16(outPtr, padString.charCodeAt(i % padStringLen), 0, 4);
1044
+ Porffor.wasm.i32.store16(outPtr, Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${padString}` + (i % padStringLen) * 2, 0, 4), 0, 4);
1000
1045
  outPtr += 2;
1001
1046
  }
1002
1047
  out.length = targetLength;
@@ -1014,7 +1059,6 @@ export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: n
1014
1059
 
1015
1060
  let outPtr: i32 = Porffor.wasm`local.get ${out}`;
1016
1061
  let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
1017
- const padStringPtr: i32 = Porffor.wasm`local.get ${padString}`;
1018
1062
 
1019
1063
  const len: i32 = _this.length;
1020
1064
 
@@ -1024,7 +1068,6 @@ export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: n
1024
1068
  Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(thisPtr++, 0, 4), 0, 4);
1025
1069
  }
1026
1070
 
1027
- targetLength |= 0;
1028
1071
 
1029
1072
  const todo: i32 = targetLength - len;
1030
1073
  if (todo > 0) {
@@ -1038,8 +1081,7 @@ export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: n
1038
1081
  const padStringLen: i32 = padString.length;
1039
1082
  if (padStringLen > 0) {
1040
1083
  for (let i: i32 = 0; i < todo; i++) {
1041
- Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(padStringPtr + (i % padStringLen), 0, 4), 0, 4);
1042
- // Porffor.wasm.i32.store8(outPtr++, padString.charCodeAt(i % padStringLen), 0, 4);
1084
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${padString}` + (i % padStringLen), 0, 4), 0, 4);
1043
1085
  }
1044
1086
 
1045
1087
  out.length = targetLength;
@@ -1060,8 +1102,6 @@ export const __String_prototype_substring = (_this: string, start: number, end:
1060
1102
  start = tmp;
1061
1103
  }
1062
1104
 
1063
- start |= 0;
1064
- end |= 0;
1065
1105
 
1066
1106
  if (start < 0) start = 0;
1067
1107
  if (start > len) start = len;
@@ -1098,8 +1138,6 @@ export const __ByteString_prototype_substring = (_this: bytestring, start: numbe
1098
1138
  start = tmp;
1099
1139
  }
1100
1140
 
1101
- start |= 0;
1102
- end |= 0;
1103
1141
 
1104
1142
  if (start < 0) start = 0;
1105
1143
  if (start > len) start = len;
@@ -1128,7 +1166,6 @@ export const __ByteString_prototype_substring = (_this: bytestring, start: numbe
1128
1166
  export const __String_prototype_substr = (_this: string, start: number, length: number) => {
1129
1167
  const len: i32 = _this.length;
1130
1168
 
1131
- start |= 0;
1132
1169
 
1133
1170
  if (start < 0) {
1134
1171
  start = len + start;
@@ -1137,7 +1174,6 @@ export const __String_prototype_substr = (_this: string, start: number, length:
1137
1174
 
1138
1175
  if (Porffor.wasm`local.get ${length+1}` == Porffor.TYPES.undefined) length = len - start;
1139
1176
 
1140
- length |= 0;
1141
1177
 
1142
1178
  if (start + length > len) length = len - start;
1143
1179
 
@@ -1165,7 +1201,6 @@ export const __String_prototype_substr = (_this: string, start: number, length:
1165
1201
  export const __ByteString_prototype_substr = (_this: bytestring, start: number, length: number) => {
1166
1202
  const len: i32 = _this.length;
1167
1203
 
1168
- start |= 0;
1169
1204
 
1170
1205
  if (start < 0) {
1171
1206
  start = len + start;
@@ -1174,7 +1209,6 @@ export const __ByteString_prototype_substr = (_this: bytestring, start: number,
1174
1209
 
1175
1210
  if (Porffor.wasm`local.get ${length+1}` == Porffor.TYPES.undefined) length = len - start;
1176
1211
 
1177
- length |= 0;
1178
1212
 
1179
1213
  if (start + length > len) length = len - start;
1180
1214
 
@@ -1201,8 +1235,6 @@ export const __String_prototype_slice = (_this: string, start: number, end: numb
1201
1235
  const len: i32 = _this.length;
1202
1236
  if (Porffor.wasm`local.get ${end+1}` == Porffor.TYPES.undefined) end = len;
1203
1237
 
1204
- start |= 0;
1205
- end |= 0;
1206
1238
 
1207
1239
  if (start < 0) {
1208
1240
  start = len + start;
@@ -1242,8 +1274,6 @@ export const __ByteString_prototype_slice = (_this: bytestring, start: number, e
1242
1274
  const len: i32 = _this.length;
1243
1275
  if (Porffor.wasm`local.get ${end+1}` == Porffor.TYPES.undefined) end = len;
1244
1276
 
1245
- start |= 0;
1246
- end |= 0;
1247
1277
 
1248
1278
  if (start < 0) {
1249
1279
  start = len + start;
@@ -1581,7 +1611,6 @@ export const __String_prototype_split = (_this: string, separator: any, limit: a
1581
1611
  let out: any[] = Porffor.allocate(), outLen: i32 = 0;
1582
1612
 
1583
1613
  if (Porffor.wasm`local.get ${limit+1}` == Porffor.TYPES.undefined) limit = Number.MAX_SAFE_INTEGER;
1584
- limit |= 0;
1585
1614
  if (limit < 0) limit = Number.MAX_SAFE_INTEGER;
1586
1615
 
1587
1616
  if (separator == null) {
@@ -1759,7 +1788,6 @@ i32.store8 0 12`;
1759
1788
  }
1760
1789
 
1761
1790
  if (Porffor.wasm`local.get ${limit+1}` == Porffor.TYPES.undefined) limit = Number.MAX_SAFE_INTEGER;
1762
- limit |= 0;
1763
1791
  if (limit < 0) limit = Number.MAX_SAFE_INTEGER;
1764
1792
 
1765
1793
  let tmp: bytestring = Porffor.allocate(), tmpLen: i32 = 0;