porffor 0.18.17 → 0.18.19
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 +3 -0
- package/compiler/builtins/number.ts +141 -0
- package/compiler/builtins/object.ts +3 -1
- package/compiler/builtins/set.ts +3 -1
- package/compiler/builtins/string.ts +3 -1
- package/compiler/builtins/symbol.ts +2 -0
- package/compiler/codegen.js +5 -3
- package/compiler/generated_builtins.js +2183 -3539
- package/compiler/precompile.js +6 -9
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/compiler/builtins/int.ts +0 -147
@@ -531,6 +531,9 @@ export const __Array_prototype_toString = (_this: any[]) => {
|
|
531
531
|
return out;
|
532
532
|
};
|
533
533
|
|
534
|
+
// @porf-typed-array
|
535
|
+
export const __Array_prototype_toLocaleString = (_this: any[]) => __Array_prototype_toString(_this);
|
536
|
+
|
534
537
|
// @porf-typed-array
|
535
538
|
export const __Array_prototype_join = (_this: any[], _separator: any) => {
|
536
539
|
// todo: this is bytestring only!
|
@@ -320,6 +320,8 @@ export const __Number_prototype_toFixed = (_this: number, fractionDigits: number
|
|
320
320
|
return out;
|
321
321
|
};
|
322
322
|
|
323
|
+
export const __Number_prototype_toLocaleString = (_this: number) => __Number_prototype_toString(_this, 10);
|
324
|
+
|
323
325
|
// fractionDigits: number|any for rawType check
|
324
326
|
export const __Number_prototype_toExponential = (_this: number, fractionDigits: number|any) => {
|
325
327
|
let out: bytestring = Porffor.allocate();
|
@@ -518,3 +520,142 @@ export const __Number_prototype_valueOf = (_this: number) => {
|
|
518
520
|
// 1. Return ? ThisNumberValue(this value).
|
519
521
|
return _this;
|
520
522
|
};
|
523
|
+
|
524
|
+
|
525
|
+
export const parseInt = (input: string|bytestring, radix: number): f64 => {
|
526
|
+
// todo/perf: optimize this instead of doing a naive algo (https://kholdstare.github.io/technical/2020/05/26/faster-integer-parsing.html)
|
527
|
+
// todo/perf: use i32s here once that becomes not annoying
|
528
|
+
|
529
|
+
if (radix == 0) radix = 10;
|
530
|
+
if (radix < 2 || radix > 36) return NaN;
|
531
|
+
|
532
|
+
let nMax: f64 = 58;
|
533
|
+
if (radix < 10) nMax = 48 + radix;
|
534
|
+
|
535
|
+
let n: f64 = NaN;
|
536
|
+
|
537
|
+
const inputPtr: f64 = Porffor.wasm`local.get ${input}`;
|
538
|
+
const len: f64 = Porffor.wasm.i32.load(inputPtr, 0, 0);
|
539
|
+
let i: f64 = inputPtr;
|
540
|
+
|
541
|
+
let negative: boolean = false;
|
542
|
+
|
543
|
+
if (Porffor.rawType(input) == Porffor.TYPES.bytestring) {
|
544
|
+
const endPtr: f64 = i + len;
|
545
|
+
|
546
|
+
// check start of string
|
547
|
+
const startChr: f64 = Porffor.wasm.i32.load8_u(i, 0, 4);
|
548
|
+
|
549
|
+
// +, ignore
|
550
|
+
if (startChr == 43) i++;
|
551
|
+
|
552
|
+
// -, switch to negative
|
553
|
+
if (startChr == 45) {
|
554
|
+
negative = true;
|
555
|
+
i++;
|
556
|
+
}
|
557
|
+
|
558
|
+
// 0, potential start of hex
|
559
|
+
if (startChr == 48) {
|
560
|
+
const second: f64 = Porffor.wasm.i32.load8_u(i + 1, 0, 4);
|
561
|
+
// 0x or 0X
|
562
|
+
if (second == 120 || second == 88) {
|
563
|
+
// set radix to 16 and skip leading 2 chars
|
564
|
+
i += 2;
|
565
|
+
radix = 16;
|
566
|
+
}
|
567
|
+
}
|
568
|
+
|
569
|
+
while (i < endPtr) {
|
570
|
+
const chr: f64 = Porffor.wasm.i32.load8_u(i++, 0, 4);
|
571
|
+
|
572
|
+
if (chr >= 48 && chr < nMax) {
|
573
|
+
if (Number.isNaN(n)) n = 0;
|
574
|
+
|
575
|
+
n *= radix;
|
576
|
+
n += chr - 48;
|
577
|
+
} else if (radix > 10) {
|
578
|
+
if (chr >= 97 && chr < (87 + radix)) {
|
579
|
+
if (Number.isNaN(n)) n = 0;
|
580
|
+
|
581
|
+
n *= radix;
|
582
|
+
n += chr - 87;
|
583
|
+
} else if (chr >= 65 && chr < (55 + radix)) {
|
584
|
+
if (Number.isNaN(n)) n = 0;
|
585
|
+
|
586
|
+
n *= radix;
|
587
|
+
n += chr - 55;
|
588
|
+
} else {
|
589
|
+
if (negative) return -n;
|
590
|
+
return n;
|
591
|
+
}
|
592
|
+
} else {
|
593
|
+
if (negative) return -n;
|
594
|
+
return n;
|
595
|
+
}
|
596
|
+
}
|
597
|
+
|
598
|
+
if (negative) return -n;
|
599
|
+
return n;
|
600
|
+
}
|
601
|
+
|
602
|
+
const endPtr: f64 = i + len * 2;
|
603
|
+
|
604
|
+
// check start of string
|
605
|
+
const startChr: f64 = Porffor.wasm.i32.load16_u(i, 0, 4);
|
606
|
+
|
607
|
+
// +, ignore
|
608
|
+
if (startChr == 43) i += 2;
|
609
|
+
|
610
|
+
// -, switch to negative
|
611
|
+
if (startChr == 45) {
|
612
|
+
negative = true;
|
613
|
+
i += 2;
|
614
|
+
}
|
615
|
+
|
616
|
+
// 0, potential start of hex
|
617
|
+
if (startChr == 48) {
|
618
|
+
const second: f64 = Porffor.wasm.i32.load16_u(i + 2, 0, 4);
|
619
|
+
// 0x or 0X
|
620
|
+
if (second == 120 || second == 88) {
|
621
|
+
// set radix to 16 and skip leading 2 chars
|
622
|
+
i += 4;
|
623
|
+
radix = 16;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
while (i < endPtr) {
|
628
|
+
const chr: f64 = Porffor.wasm.i32.load16_u(i, 0, 4);
|
629
|
+
i += 2;
|
630
|
+
|
631
|
+
if (chr >= 48 && chr < nMax) {
|
632
|
+
if (Number.isNaN(n)) n = 0;
|
633
|
+
|
634
|
+
n *= radix;
|
635
|
+
n += chr - 48;
|
636
|
+
} else if (radix > 10) {
|
637
|
+
if (chr >= 97 && chr < (87 + radix)) {
|
638
|
+
if (Number.isNaN(n)) n = 0;
|
639
|
+
|
640
|
+
n *= radix;
|
641
|
+
n += chr - 87;
|
642
|
+
} else if (chr >= 65 && chr < (55 + radix)) {
|
643
|
+
if (Number.isNaN(n)) n = 0;
|
644
|
+
|
645
|
+
n *= radix;
|
646
|
+
n += chr - 55;
|
647
|
+
} else {
|
648
|
+
if (negative) return -n;
|
649
|
+
return n;
|
650
|
+
}
|
651
|
+
} else {
|
652
|
+
if (negative) return -n;
|
653
|
+
return n;
|
654
|
+
}
|
655
|
+
}
|
656
|
+
|
657
|
+
if (negative) return -n;
|
658
|
+
return n;
|
659
|
+
};
|
660
|
+
|
661
|
+
export const __Number_parseInt = (input: string|bytestring, radix: number): f64 => parseInt(input, radix);
|
@@ -3,4 +3,6 @@ import type {} from './porffor.d.ts';
|
|
3
3
|
export const __Object_prototype_toString = (_this: object) => {
|
4
4
|
let out: bytestring = '[object Object]';
|
5
5
|
return out;
|
6
|
-
};
|
6
|
+
};
|
7
|
+
|
8
|
+
export const __Object_prototype_toLocaleString = (_this: object) => __Object_prototype_toLocaleString(_this);
|
package/compiler/builtins/set.ts
CHANGED
@@ -191,4 +191,6 @@ export const __Set_prototype_union = (_this: Set, other: any) => {
|
|
191
191
|
export const __Set_prototype_toString = (_this: Set) => {
|
192
192
|
const out: bytestring = '[object Set]';
|
193
193
|
return out;
|
194
|
-
};
|
194
|
+
};
|
195
|
+
|
196
|
+
export const __Set_prototype_toLocaleString = (_this: Set) => __Set_prototype_toString(_this);
|
@@ -1031,7 +1031,6 @@ export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
|
1031
1031
|
return out;
|
1032
1032
|
};
|
1033
1033
|
|
1034
|
-
|
1035
1034
|
export const __String_prototype_trim = (_this: string) => {
|
1036
1035
|
// todo/perf: optimize and not just reuse
|
1037
1036
|
return __String_prototype_trimStart(__String_prototype_trimEnd(_this));
|
@@ -1042,6 +1041,7 @@ export const __ByteString_prototype_trim = (_this: bytestring) => {
|
|
1042
1041
|
return __ByteString_prototype_trimStart(__ByteString_prototype_trimEnd(_this));
|
1043
1042
|
};
|
1044
1043
|
|
1044
|
+
|
1045
1045
|
// 22.1.3.29 String.prototype.toString ()
|
1046
1046
|
// https://tc39.es/ecma262/#sec-string.prototype.tostring
|
1047
1047
|
export const __String_prototype_toString = (_this: string) => {
|
@@ -1054,6 +1054,8 @@ export const __ByteString_prototype_toString = (_this: bytestring) => {
|
|
1054
1054
|
return _this;
|
1055
1055
|
};
|
1056
1056
|
|
1057
|
+
export const __String_prototype_toLocaleString = (_this: string) => __String_prototype_toString(_this);
|
1058
|
+
export const __ByteString_prototype_toLocaleString = (_this: bytestring) => __ByteString_prototype_toString(_this);
|
1057
1059
|
|
1058
1060
|
// 22.1.3.35 String.prototype.valueOf ()
|
1059
1061
|
// https://tc39.es/ecma262/#sec-string.prototype.valueof
|
@@ -58,6 +58,8 @@ export const __Symbol_prototype_toString = (_this: Symbol) => {
|
|
58
58
|
return out;
|
59
59
|
};
|
60
60
|
|
61
|
+
export const __Symbol_prototype_toLocaleString = (_this: Symbol) => __Symbol_prototype_toString(_this);
|
62
|
+
|
61
63
|
export const __Symbol_prototype_valueOf = (_this: Symbol) => {
|
62
64
|
return _this;
|
63
65
|
};
|
package/compiler/codegen.js
CHANGED
@@ -1138,9 +1138,11 @@ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes
|
|
1138
1138
|
}
|
1139
1139
|
|
1140
1140
|
for (const x of _data) {
|
1141
|
-
|
1142
|
-
if (
|
1143
|
-
|
1141
|
+
let offset = x[0];
|
1142
|
+
if (offset != null) offset += pages.size * pageSize;
|
1143
|
+
|
1144
|
+
const bytes = x[1];
|
1145
|
+
data.push({ offset, bytes });
|
1144
1146
|
}
|
1145
1147
|
|
1146
1148
|
const func = {
|