porffor 0.2.0-5ad562e → 0.2.0-5c24120
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/CONTRIBUTING.md +6 -5
- package/compiler/builtins/annexb_string.js +1 -1
- package/compiler/builtins/annexb_string.ts +4 -4
- package/compiler/builtins/array.ts +9 -9
- package/compiler/builtins/boolean.ts +20 -0
- package/compiler/builtins/date.ts +50 -51
- package/compiler/builtins/escape.ts +1 -1
- package/compiler/builtins/function.ts +7 -0
- package/compiler/builtins/int.ts +2 -2
- package/compiler/builtins/number.ts +8 -1
- package/compiler/builtins/object.ts +6 -0
- package/compiler/builtins/string.ts +46 -21
- package/compiler/builtins.js +4 -4
- package/compiler/codegen.js +69 -50
- package/compiler/generated_builtins.js +177 -141
- package/compiler/precompile.js +1 -1
- package/compiler/prefs.js +1 -1
- package/compiler/prototype.js +14 -14
- package/compiler/types.js +1 -1
- package/compiler/wrap.js +3 -3
- package/package.json +1 -1
- package/compiler/builtins/tostring.ts +0 -45
package/CONTRIBUTING.md
CHANGED
@@ -36,7 +36,7 @@ Porffor has usual JS types (or at least the ones it supports), but also internal
|
|
36
36
|
|
37
37
|
### ByteString
|
38
38
|
|
39
|
-
The most important and widely used internal type is ByteString
|
39
|
+
The most important and widely used internal type is ByteString. Regular strings in Porffor are UTF-16 encoded, so each character uses 2 bytes. ByteStrings are special strings which are used when the characters in a string only use ASCII/LATIN-1 characters, so the lower byte of the UTF-16 characters are unused. Instead of wasting memory with all the unused memory, ByteStrings instead use 1 byte per character. This halves memory usage of such strings and also makes operating on them faster. The downside is that many Porffor built-ins have to be written twice, slightly different, for both `String` and `ByteString` types.
|
40
40
|
|
41
41
|
### i32
|
42
42
|
|
@@ -107,7 +107,7 @@ Stores the length `length` at pointer `pointer`, setting the length of an object
|
|
107
107
|
Here is the code for `ByteString.prototype.toUpperCase()`:
|
108
108
|
|
109
109
|
```ts
|
110
|
-
export const
|
110
|
+
export const __ByteString_prototype_toUpperCase = (_this: bytestring) => {
|
111
111
|
const len: i32 = _this.length;
|
112
112
|
|
113
113
|
let out: bytestring = '';
|
@@ -132,14 +132,14 @@ export const ___bytestring_prototype_toUpperCase = (_this: bytestring) => {
|
|
132
132
|
Now let's go through it section by section:
|
133
133
|
|
134
134
|
```ts
|
135
|
-
export const
|
135
|
+
export const __ByteString_prototype_toUpperCase = (_this: bytestring) => {
|
136
136
|
```
|
137
137
|
|
138
138
|
Here we define a built-in for Porffor. Notably:
|
139
139
|
- We do not use `a.b.c`, instead we use `__a_b_c`
|
140
|
-
- The ByteString type is actually `_bytestring`, as internal types have an extra `_` at the beginning (this is due to be fixed/simplified soon(tm))
|
141
140
|
- We use a `_this` argument, as `this` does not exist in Porffor yet
|
142
141
|
- We use an arrow function
|
142
|
+
- We do not set a return type as prototype methods cannot use them currently or errors can happen.
|
143
143
|
|
144
144
|
---
|
145
145
|
|
@@ -202,6 +202,7 @@ Store the character code into the `out` pointer variable, and increment it.
|
|
202
202
|
- You might spot `Porffor.fastOr`/`Porffor.fastAnd`, these are non-short circuiting versions of `||`/`&&`, taking any number of conditions as arguments. You shouldn't don't need to use or worry about these.
|
203
203
|
- **There are ~no objects, you cannot use them/literals.**
|
204
204
|
- Attempt to avoid string/array-heavy code and use more variables instead if possible, easier on memory and CPU/perf.
|
205
|
+
- Do not set a return type for prototype methods, it can cause errors/unexpected results.
|
205
206
|
|
206
207
|
<br>
|
207
208
|
|
@@ -228,7 +229,7 @@ builtins/tostring_number: impl radix
|
|
228
229
|
|
229
230
|
## Test262
|
230
231
|
|
231
|
-
Make sure you have Test262 cloned already **inside of `test262/`** (`git clone https://github.com/tc39/test262.git test262/test262`).
|
232
|
+
Make sure you have Test262 cloned already **inside of `test262/`** (`git clone https://github.com/tc39/test262.git test262/test262`) and run `npm install` inside `test262/` too.
|
232
233
|
|
233
234
|
Run `node test262` to run all the tests and get an output of total overall test results. The main thing you want to pay attention to is the emoji summary (lol):
|
234
235
|
```
|
@@ -31,7 +31,7 @@ ${[...a1].map((x, i) => ` Porffor.wasm.i32.store16(outPtr, ${x.charCodeAt(0)},
|
|
31
31
|
|
32
32
|
return out;
|
33
33
|
};
|
34
|
-
export const
|
34
|
+
export const __ByteString_prototype_${a0} = (_this: bytestring) => {
|
35
35
|
let out: bytestring = Porffor.bs\`<${a1}>\`;
|
36
36
|
|
37
37
|
let outPtr: i32 = Porffor.wasm\`local.get \${out}\` + ${2 + a1.length};
|
@@ -4,8 +4,8 @@ export const __String_prototype_trimLeft = (_this: string) => {
|
|
4
4
|
return __String_prototype_trimStart(_this);
|
5
5
|
};
|
6
6
|
|
7
|
-
export const
|
8
|
-
return
|
7
|
+
export const __ByteString_prototype_trimLeft = (_this: string) => {
|
8
|
+
return __ByteString_prototype_trimStart(_this);
|
9
9
|
};
|
10
10
|
|
11
11
|
|
@@ -13,6 +13,6 @@ export const __String_prototype_trimRight = (_this: string) => {
|
|
13
13
|
return __String_prototype_trimEnd(_this);
|
14
14
|
};
|
15
15
|
|
16
|
-
export const
|
17
|
-
return
|
16
|
+
export const __ByteString_prototype_trimEnd = (_this: string) => {
|
17
|
+
return __ByteString_prototype_trimRight(_this);
|
18
18
|
};
|
@@ -1,10 +1,10 @@
|
|
1
1
|
// @porf --funsafe-no-unlikely-proto-checks
|
2
2
|
|
3
3
|
export const __Array_isArray = (x: unknown): boolean =>
|
4
|
-
// Porffor.wasm`local.get ${x+1}` == Porffor.TYPES.
|
5
|
-
Porffor.rawType(x) == Porffor.TYPES.
|
4
|
+
// Porffor.wasm`local.get ${x+1}` == Porffor.TYPES.array;
|
5
|
+
Porffor.rawType(x) == Porffor.TYPES.array;
|
6
6
|
|
7
|
-
export const
|
7
|
+
export const __Array_prototype_slice = (_this: any[], start: number, end: number) => {
|
8
8
|
const len: i32 = _this.length;
|
9
9
|
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
|
10
10
|
|
@@ -44,7 +44,7 @@ export const ___array_prototype_slice = (_this: any[], start: number, end: numbe
|
|
44
44
|
return out;
|
45
45
|
};
|
46
46
|
|
47
|
-
export const
|
47
|
+
export const __Array_prototype_indexOf = (_this: any[], searchElement: any, position: number) => {
|
48
48
|
const len: i32 = _this.length;
|
49
49
|
if (position > 0) {
|
50
50
|
if (position > len) position = len;
|
@@ -58,7 +58,7 @@ export const ___array_prototype_indexOf = (_this: any[], searchElement: any, pos
|
|
58
58
|
return -1;
|
59
59
|
};
|
60
60
|
|
61
|
-
export const
|
61
|
+
export const __Array_prototype_lastIndexOf = (_this: any[], searchElement: any, position: number) => {
|
62
62
|
const len: i32 = _this.length;
|
63
63
|
if (position > 0) {
|
64
64
|
if (position > len) position = len;
|
@@ -72,7 +72,7 @@ export const ___array_prototype_lastIndexOf = (_this: any[], searchElement: any,
|
|
72
72
|
return -1;
|
73
73
|
};
|
74
74
|
|
75
|
-
export const
|
75
|
+
export const __Array_prototype_includes = (_this: any[], searchElement: any, position: number) => {
|
76
76
|
const len: i32 = _this.length;
|
77
77
|
if (position > 0) {
|
78
78
|
if (position > len) position = len;
|
@@ -86,7 +86,7 @@ export const ___array_prototype_includes = (_this: any[], searchElement: any, po
|
|
86
86
|
return false;
|
87
87
|
};
|
88
88
|
|
89
|
-
export const
|
89
|
+
export const __Array_prototype_with = (_this: any[], index: number, value: any) => {
|
90
90
|
const len: i32 = _this.length;
|
91
91
|
if (index < 0) {
|
92
92
|
index = len + index;
|
@@ -111,7 +111,7 @@ export const ___array_prototype_with = (_this: any[], index: number, value: any)
|
|
111
111
|
return out;
|
112
112
|
};
|
113
113
|
|
114
|
-
export const
|
114
|
+
export const __Array_prototype_reverse = (_this: any[]) => {
|
115
115
|
const len: i32 = _this.length;
|
116
116
|
|
117
117
|
let start: i32 = 0;
|
@@ -127,7 +127,7 @@ export const ___array_prototype_reverse = (_this: any[]) => {
|
|
127
127
|
};
|
128
128
|
|
129
129
|
// todo: this has memory/allocation bugs so sometimes crashes :(
|
130
|
-
export const
|
130
|
+
export const __Array_prototype_toReversed = (_this: any[]) => {
|
131
131
|
const len: i32 = _this.length;
|
132
132
|
|
133
133
|
let start: i32 = 0;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// @porf --funsafe-no-unlikely-proto-checks
|
2
|
+
|
3
|
+
// 20.3.3.2 Boolean.prototype.toString ()
|
4
|
+
// https://tc39.es/ecma262/#sec-boolean.prototype.tostring
|
5
|
+
export const __Boolean_prototype_toString = (_this: boolean) => {
|
6
|
+
// 1. Let b be ? ThisBooleanValue(this value).
|
7
|
+
// 2. If b is true, return "true"; else return "false".
|
8
|
+
let out: bytestring = '';
|
9
|
+
if (_this) out = 'true';
|
10
|
+
else out = 'false';
|
11
|
+
|
12
|
+
return out;
|
13
|
+
};
|
14
|
+
|
15
|
+
// 20.3.3.3 Boolean.prototype.valueOf ()
|
16
|
+
// https://tc39.es/ecma262/#sec-boolean.prototype.valueof
|
17
|
+
export const __Boolean_prototype_valueOf = (_this: boolean) => {
|
18
|
+
// 1. Return ? ThisBooleanValue(this value).
|
19
|
+
return _this;
|
20
|
+
};
|
@@ -776,13 +776,13 @@ export const Date$constructor = (v0: unknown, v1: unknown, v2: unknown, v3: unkn
|
|
776
776
|
let tv: number = 0;
|
777
777
|
|
778
778
|
// b. If value is an Object and value has a [[DateValue]] internal slot, then
|
779
|
-
if (valueType == Porffor.TYPES.
|
779
|
+
if (valueType == Porffor.TYPES.date) {
|
780
780
|
// i. Let tv be value.[[DateValue]].
|
781
781
|
tv = __Porffor_date_read(value);
|
782
782
|
} else {
|
783
783
|
// c. Else,
|
784
784
|
// ii. If v is a String, then
|
785
|
-
if (Porffor.fastOr(valueType == Porffor.TYPES.string, valueType == Porffor.TYPES.
|
785
|
+
if (Porffor.fastOr(valueType == Porffor.TYPES.string, valueType == Porffor.TYPES.bytestring)) {
|
786
786
|
// 1. Assert: The next step never returns an abrupt completion because v is a String.
|
787
787
|
|
788
788
|
// 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the parse method (21.4.3.2).
|
@@ -852,7 +852,7 @@ export const Date$constructor = (v0: unknown, v1: unknown, v2: unknown, v3: unkn
|
|
852
852
|
|
853
853
|
// 21.4.4.2 Date.prototype.getDate ()
|
854
854
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getdate
|
855
|
-
export const
|
855
|
+
export const __Date_prototype_getDate = (_this: Date) => {
|
856
856
|
// 1. Let dateObject be the this value.
|
857
857
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
858
858
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -867,7 +867,7 @@ export const ___date_prototype_getDate = (_this: Date) => {
|
|
867
867
|
|
868
868
|
// 21.4.4.3 Date.prototype.getDay ()
|
869
869
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getday
|
870
|
-
export const
|
870
|
+
export const __Date_prototype_getDay = (_this: Date) => {
|
871
871
|
// 1. Let dateObject be the this value.
|
872
872
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
873
873
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -882,7 +882,7 @@ export const ___date_prototype_getDay = (_this: Date) => {
|
|
882
882
|
|
883
883
|
// 21.4.4.4 Date.prototype.getFullYear ()
|
884
884
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getfullyear
|
885
|
-
export const
|
885
|
+
export const __Date_prototype_getFullYear = (_this: Date) => {
|
886
886
|
// 1. Let dateObject be the this value.
|
887
887
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
888
888
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -897,7 +897,7 @@ export const ___date_prototype_getFullYear = (_this: Date) => {
|
|
897
897
|
|
898
898
|
// 21.4.4.5 Date.prototype.getHours ()
|
899
899
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.gethours
|
900
|
-
export const
|
900
|
+
export const __Date_prototype_getHours = (_this: Date) => {
|
901
901
|
// 1. Let dateObject be the this value.
|
902
902
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
903
903
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -912,7 +912,7 @@ export const ___date_prototype_getHours = (_this: Date) => {
|
|
912
912
|
|
913
913
|
// 21.4.4.6 Date.prototype.getMilliseconds ()
|
914
914
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmilliseconds
|
915
|
-
export const
|
915
|
+
export const __Date_prototype_getMilliseconds = (_this: Date) => {
|
916
916
|
// 1. Let dateObject be the this value.
|
917
917
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
918
918
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -927,7 +927,7 @@ export const ___date_prototype_getMilliseconds = (_this: Date) => {
|
|
927
927
|
|
928
928
|
// 21.4.4.7 Date.prototype.getMinutes ()
|
929
929
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getminutes
|
930
|
-
export const
|
930
|
+
export const __Date_prototype_getMinutes = (_this: Date) => {
|
931
931
|
// 1. Let dateObject be the this value.
|
932
932
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
933
933
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -942,7 +942,7 @@ export const ___date_prototype_getMinutes = (_this: Date) => {
|
|
942
942
|
|
943
943
|
// 21.4.4.8 Date.prototype.getMonth ()
|
944
944
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmonth
|
945
|
-
export const
|
945
|
+
export const __Date_prototype_getMonth = (_this: Date) => {
|
946
946
|
// 1. Let dateObject be the this value.
|
947
947
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
948
948
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -957,7 +957,7 @@ export const ___date_prototype_getMonth = (_this: Date) => {
|
|
957
957
|
|
958
958
|
// 21.4.4.9 Date.prototype.getSeconds ()
|
959
959
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getseconds
|
960
|
-
export const
|
960
|
+
export const __Date_prototype_getSeconds = (_this: Date) => {
|
961
961
|
// 1. Let dateObject be the this value.
|
962
962
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
963
963
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -972,7 +972,7 @@ export const ___date_prototype_getSeconds = (_this: Date) => {
|
|
972
972
|
|
973
973
|
// 21.4.4.10 Date.prototype.getTime ()
|
974
974
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.gettime
|
975
|
-
export const
|
975
|
+
export const __Date_prototype_getTime = (_this: Date) => {
|
976
976
|
// 1. Let dateObject be the this value.
|
977
977
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
978
978
|
// 3. Return dateObject.[[DateValue]].
|
@@ -981,7 +981,7 @@ export const ___date_prototype_getTime = (_this: Date) => {
|
|
981
981
|
|
982
982
|
// 21.4.4.11 Date.prototype.getTimezoneOffset ()
|
983
983
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.gettimezoneoffset
|
984
|
-
export const
|
984
|
+
export const __Date_prototype_getTimezoneOffset = (_this: Date) => {
|
985
985
|
// 1. Let dateObject be the this value.
|
986
986
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
987
987
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -996,7 +996,7 @@ export const ___date_prototype_getTimezoneOffset = (_this: Date) => {
|
|
996
996
|
|
997
997
|
// 21.4.4.12 Date.prototype.getUTCDate ()
|
998
998
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcdate
|
999
|
-
export const
|
999
|
+
export const __Date_prototype_getUTCDate = (_this: Date) => {
|
1000
1000
|
// 1. Let dateObject be the this value.
|
1001
1001
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1002
1002
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1011,7 +1011,7 @@ export const ___date_prototype_getUTCDate = (_this: Date) => {
|
|
1011
1011
|
|
1012
1012
|
// 21.4.4.13 Date.prototype.getUTCDay ()
|
1013
1013
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcday
|
1014
|
-
export const
|
1014
|
+
export const __Date_prototype_getUTCDay = (_this: Date) => {
|
1015
1015
|
// 1. Let dateObject be the this value.
|
1016
1016
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1017
1017
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1026,7 +1026,7 @@ export const ___date_prototype_getUTCDay = (_this: Date) => {
|
|
1026
1026
|
|
1027
1027
|
// 21.4.4.14 Date.prototype.getUTCFullYear ()
|
1028
1028
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcfullyear
|
1029
|
-
export const
|
1029
|
+
export const __Date_prototype_getUTCFullYear = (_this: Date) => {
|
1030
1030
|
// 1. Let dateObject be the this value.
|
1031
1031
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1032
1032
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1041,7 +1041,7 @@ export const ___date_prototype_getUTCFullYear = (_this: Date) => {
|
|
1041
1041
|
|
1042
1042
|
// 21.4.4.15 Date.prototype.getUTCHours ()
|
1043
1043
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutchours
|
1044
|
-
export const
|
1044
|
+
export const __Date_prototype_getUTCHours = (_this: Date) => {
|
1045
1045
|
// 1. Let dateObject be the this value.
|
1046
1046
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1047
1047
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1056,7 +1056,7 @@ export const ___date_prototype_getUTCHours = (_this: Date) => {
|
|
1056
1056
|
|
1057
1057
|
// 21.4.4.16 Date.prototype.getUTCMilliseconds ()
|
1058
1058
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcmilliseconds
|
1059
|
-
export const
|
1059
|
+
export const __Date_prototype_getUTCMilliseconds = (_this: Date) => {
|
1060
1060
|
// 1. Let dateObject be the this value.
|
1061
1061
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1062
1062
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1071,7 +1071,7 @@ export const ___date_prototype_getUTCMilliseconds = (_this: Date) => {
|
|
1071
1071
|
|
1072
1072
|
// 21.4.4.17 Date.prototype.getUTCMinutes ()
|
1073
1073
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcminutes
|
1074
|
-
export const
|
1074
|
+
export const __Date_prototype_getUTCMinutes = (_this: Date) => {
|
1075
1075
|
// 1. Let dateObject be the this value.
|
1076
1076
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1077
1077
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1086,7 +1086,7 @@ export const ___date_prototype_getUTCMinutes = (_this: Date) => {
|
|
1086
1086
|
|
1087
1087
|
// 21.4.4.18 Date.prototype.getUTCMonth ()
|
1088
1088
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcmonth
|
1089
|
-
export const
|
1089
|
+
export const __Date_prototype_getUTCMonth = (_this: Date) => {
|
1090
1090
|
// 1. Let dateObject be the this value.
|
1091
1091
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1092
1092
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1101,7 +1101,7 @@ export const ___date_prototype_getUTCMonth = (_this: Date) => {
|
|
1101
1101
|
|
1102
1102
|
// 21.4.4.19 Date.prototype.getUTCSeconds ()
|
1103
1103
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcseconds
|
1104
|
-
export const
|
1104
|
+
export const __Date_prototype_getUTCSeconds = (_this: Date) => {
|
1105
1105
|
// 1. Let dateObject be the this value.
|
1106
1106
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1107
1107
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1117,7 +1117,7 @@ export const ___date_prototype_getUTCSeconds = (_this: Date) => {
|
|
1117
1117
|
|
1118
1118
|
// 21.4.4.20 Date.prototype.setDate (date)
|
1119
1119
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setdate
|
1120
|
-
export const
|
1120
|
+
export const __Date_prototype_setDate = (_this: Date, date: any) => {
|
1121
1121
|
// 1. Let dateObject be the this value.
|
1122
1122
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1123
1123
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1147,7 +1147,7 @@ export const ___date_prototype_setDate = (_this: Date, date: any) => {
|
|
1147
1147
|
|
1148
1148
|
// 21.4.4.21 Date.prototype.setFullYear (year [, month [, date ]])
|
1149
1149
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setfullyear
|
1150
|
-
export const
|
1150
|
+
export const __Date_prototype_setFullYear = (_this: Date, year: any, month: any, date: any) => {
|
1151
1151
|
// 1. Let dateObject be the this value.
|
1152
1152
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1153
1153
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1185,7 +1185,7 @@ export const ___date_prototype_setFullYear = (_this: Date, year: any, month: any
|
|
1185
1185
|
|
1186
1186
|
// 21.4.4.22 Date.prototype.setHours (hour [, min [, sec [, ms ]]])
|
1187
1187
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.sethours
|
1188
|
-
export const
|
1188
|
+
export const __Date_prototype_setHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
|
1189
1189
|
// 1. Let dateObject be the this value.
|
1190
1190
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1191
1191
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1235,7 +1235,7 @@ export const ___date_prototype_setHours = (_this: Date, hour: any, min: any, sec
|
|
1235
1235
|
|
1236
1236
|
// 21.4.4.23 Date.prototype.setMilliseconds (ms)
|
1237
1237
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmilliseconds
|
1238
|
-
export const
|
1238
|
+
export const __Date_prototype_setMilliseconds = (_this: Date, ms: any) => {
|
1239
1239
|
// 1. Let dateObject be the this value.
|
1240
1240
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1241
1241
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1266,7 +1266,7 @@ export const ___date_prototype_setMilliseconds = (_this: Date, ms: any) => {
|
|
1266
1266
|
|
1267
1267
|
// 21.4.4.24 Date.prototype.setMinutes (min [, sec [, ms ]])
|
1268
1268
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setminutes
|
1269
|
-
export const
|
1269
|
+
export const __Date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms: any) => {
|
1270
1270
|
// 1. Let dateObject be the this value.
|
1271
1271
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1272
1272
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1310,7 +1310,7 @@ export const ___date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms
|
|
1310
1310
|
|
1311
1311
|
// 21.4.4.25 Date.prototype.setMonth (month [, date ])
|
1312
1312
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmonth
|
1313
|
-
export const
|
1313
|
+
export const __Date_prototype_setMonth = (_this: Date, month: any, date: any) => {
|
1314
1314
|
// 1. Let dateObject be the this value.
|
1315
1315
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1316
1316
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1348,7 +1348,7 @@ export const ___date_prototype_setMonth = (_this: Date, month: any, date: any) =
|
|
1348
1348
|
|
1349
1349
|
// 21.4.4.26 Date.prototype.setSeconds (sec [, ms ])
|
1350
1350
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setseconds
|
1351
|
-
export const
|
1351
|
+
export const __Date_prototype_setSeconds = (_this: Date, sec: any, ms: any) => {
|
1352
1352
|
// 1. Let dateObject be the this value.
|
1353
1353
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1354
1354
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1387,7 +1387,7 @@ export const ___date_prototype_setSeconds = (_this: Date, sec: any, ms: any) =>
|
|
1387
1387
|
|
1388
1388
|
// 21.4.4.27 Date.prototype.setTime (time)
|
1389
1389
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.settime
|
1390
|
-
export const
|
1390
|
+
export const __Date_prototype_setTime = (_this: Date, time: any) => {
|
1391
1391
|
// 1. Let dateObject be the this value.
|
1392
1392
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1393
1393
|
// 3. Let t be ? ToNumber(time).
|
@@ -1405,7 +1405,7 @@ export const ___date_prototype_setTime = (_this: Date, time: any) => {
|
|
1405
1405
|
|
1406
1406
|
// 21.4.4.28 Date.prototype.setUTCDate (date)
|
1407
1407
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcdate
|
1408
|
-
export const
|
1408
|
+
export const __Date_prototype_setUTCDate = (_this: Date, date: any) => {
|
1409
1409
|
// 1. Let dateObject be the this value.
|
1410
1410
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1411
1411
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1432,7 +1432,7 @@ export const ___date_prototype_setUTCDate = (_this: Date, date: any) => {
|
|
1432
1432
|
|
1433
1433
|
// 21.4.4.29 Date.prototype.setUTCFullYear (year [, month [, date ]])
|
1434
1434
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcfullyear
|
1435
|
-
export const
|
1435
|
+
export const __Date_prototype_setUTCFullYear = (_this: Date, year: any, month: any, date: any) => {
|
1436
1436
|
// 1. Let dateObject be the this value.
|
1437
1437
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1438
1438
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1469,7 +1469,7 @@ export const ___date_prototype_setUTCFullYear = (_this: Date, year: any, month:
|
|
1469
1469
|
|
1470
1470
|
// 21.4.4.30 Date.prototype.setUTCHours (hour [, min [, sec [, ms ]]])
|
1471
1471
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutchours
|
1472
|
-
export const
|
1472
|
+
export const __Date_prototype_setUTCHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
|
1473
1473
|
// 1. Let dateObject be the this value.
|
1474
1474
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1475
1475
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1516,7 +1516,7 @@ export const ___date_prototype_setUTCHours = (_this: Date, hour: any, min: any,
|
|
1516
1516
|
|
1517
1517
|
// 21.4.4.31 Date.prototype.setUTCMilliseconds (ms)
|
1518
1518
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcmilliseconds
|
1519
|
-
export const
|
1519
|
+
export const __Date_prototype_setUTCMilliseconds = (_this: Date, ms: any) => {
|
1520
1520
|
// 1. Let dateObject be the this value.
|
1521
1521
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1522
1522
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1544,7 +1544,7 @@ export const ___date_prototype_setUTCMilliseconds = (_this: Date, ms: any) => {
|
|
1544
1544
|
|
1545
1545
|
// 21.4.4.32 Date.prototype.setUTCMinutes (min [, sec [, ms ]])
|
1546
1546
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcminutes
|
1547
|
-
export const
|
1547
|
+
export const __Date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any, ms: any) => {
|
1548
1548
|
// 1. Let dateObject be the this value.
|
1549
1549
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1550
1550
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1585,7 +1585,7 @@ export const ___date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any,
|
|
1585
1585
|
|
1586
1586
|
// 21.4.4.33 Date.prototype.setUTCMonth (month [, date ])
|
1587
1587
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcmonth
|
1588
|
-
export const
|
1588
|
+
export const __Date_prototype_setUTCMonth = (_this: Date, month: any, date: any) => {
|
1589
1589
|
// 1. Let dateObject be the this value.
|
1590
1590
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1591
1591
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1620,7 +1620,7 @@ export const ___date_prototype_setUTCMonth = (_this: Date, month: any, date: any
|
|
1620
1620
|
|
1621
1621
|
// 21.4.4.34 Date.prototype.setUTCSeconds (sec [, ms ])
|
1622
1622
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcseconds
|
1623
|
-
export const
|
1623
|
+
export const __Date_prototype_setUTCSeconds = (_this: Date, sec: any, ms: any) => {
|
1624
1624
|
// 1. Let dateObject be the this value.
|
1625
1625
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1626
1626
|
// 3. Let t be dateObject.[[DateValue]].
|
@@ -1766,7 +1766,7 @@ export const __ecma262_ToUTCDTSF = (t: number): bytestring => {
|
|
1766
1766
|
|
1767
1767
|
// 21.4.4.36 Date.prototype.toISOString ()
|
1768
1768
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.toisostring
|
1769
|
-
export const
|
1769
|
+
export const __Date_prototype_toISOString = (_this: Date) => {
|
1770
1770
|
// 1. Let dateObject be the this value.
|
1771
1771
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1772
1772
|
// 3. Let tv be dateObject.[[DateValue]].
|
@@ -1789,7 +1789,7 @@ export const ___date_prototype_toISOString = (_this: Date) => {
|
|
1789
1789
|
|
1790
1790
|
// 21.4.4.37 Date.prototype.toJSON (key)
|
1791
1791
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tojson
|
1792
|
-
export const
|
1792
|
+
export const __Date_prototype_toJSON = (_this: Date, key: any) => {
|
1793
1793
|
// 1. Let O be ? ToObject(this value).
|
1794
1794
|
// 2. Let tv be ? ToPrimitive(O, number).
|
1795
1795
|
// todo: use generic Number() once it supports Date
|
@@ -1799,7 +1799,7 @@ export const ___date_prototype_toJSON = (_this: Date, key: any) => {
|
|
1799
1799
|
if (!Number.isFinite(tv)) return null;
|
1800
1800
|
|
1801
1801
|
// 4. Return ? Invoke(O, "toISOString").
|
1802
|
-
return
|
1802
|
+
return __Date_prototype_toISOString(_this);
|
1803
1803
|
};
|
1804
1804
|
|
1805
1805
|
|
@@ -1915,7 +1915,7 @@ export const __ecma262_ToDateString = (tv: number) => {
|
|
1915
1915
|
|
1916
1916
|
// 21.4.4.41 Date.prototype.toString ()
|
1917
1917
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tostring
|
1918
|
-
export const
|
1918
|
+
export const __Date_prototype_toString = (_this: Date) => {
|
1919
1919
|
// 1. Let dateObject be the this value.
|
1920
1920
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1921
1921
|
// 3. Let tv be dateObject.[[DateValue]].
|
@@ -1927,7 +1927,7 @@ export const ___date_prototype_toString = (_this: Date) => {
|
|
1927
1927
|
|
1928
1928
|
// 21.4.4.42 Date.prototype.toTimeString ()
|
1929
1929
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.totimestring
|
1930
|
-
export const
|
1930
|
+
export const __Date_prototype_toTimeString = (_this: Date) => {
|
1931
1931
|
// 1. Let dateObject be the this value.
|
1932
1932
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1933
1933
|
// 3. Let tv be dateObject.[[DateValue]].
|
@@ -1955,7 +1955,7 @@ export const ___date_prototype_toTimeString = (_this: Date) => {
|
|
1955
1955
|
|
1956
1956
|
// 21.4.4.35 Date.prototype.toDateString ()
|
1957
1957
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.todatestring
|
1958
|
-
export const
|
1958
|
+
export const __Date_prototype_toDateString = (_this: Date) => {
|
1959
1959
|
// 1. Let dateObject be the this value.
|
1960
1960
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1961
1961
|
// 3. Let tv be dateObject.[[DateValue]].
|
@@ -1980,7 +1980,7 @@ export const ___date_prototype_toDateString = (_this: Date) => {
|
|
1980
1980
|
|
1981
1981
|
// 21.4.4.43 Date.prototype.toUTCString ()
|
1982
1982
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.toutcstring
|
1983
|
-
export const
|
1983
|
+
export const __Date_prototype_toUTCString = (_this: Date) => {
|
1984
1984
|
// 1. Let dateObject be the this value.
|
1985
1985
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
1986
1986
|
// 3. Let tv be dateObject.[[DateValue]].
|
@@ -2035,32 +2035,31 @@ export const ___date_prototype_toUTCString = (_this: Date) => {
|
|
2035
2035
|
|
2036
2036
|
// 21.4.4.38 Date.prototype.toLocaleDateString ([ reserved1 [, reserved2 ]])
|
2037
2037
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocaledatestring
|
2038
|
-
export const
|
2039
|
-
return
|
2038
|
+
export const __Date_prototype_toLocaleDateString = (_this: Date, reserved1: any, reserved2: any) => {
|
2039
|
+
return __Date_prototype_toDateString(_this);
|
2040
2040
|
};
|
2041
2041
|
|
2042
2042
|
// 21.4.4.39 Date.prototype.toLocaleString ([ reserved1 [, reserved2 ]])
|
2043
2043
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocalestring
|
2044
|
-
export const
|
2045
|
-
return
|
2044
|
+
export const __Date_prototype_toLocaleString = (_this: Date, reserved1: any, reserved2: any) => {
|
2045
|
+
return __Date_prototype_toString(_this);
|
2046
2046
|
};
|
2047
2047
|
|
2048
2048
|
// 21.4.4.40 Date.prototype.toLocaleTimeString ([ reserved1 [, reserved2 ]])
|
2049
2049
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocaletimestring
|
2050
|
-
export const
|
2051
|
-
return
|
2050
|
+
export const __Date_prototype_toLocaleTimeString = (_this: Date, reserved1: any, reserved2: any) => {
|
2051
|
+
return __Date_prototype_toTimeString(_this);
|
2052
2052
|
};
|
2053
2053
|
|
2054
|
-
|
2055
2054
|
// 21.4.4.44 Date.prototype.valueOf ()
|
2056
|
-
|
2055
|
+
// https://tc39.es/ecma262/#sec-date.prototype.valueof
|
2056
|
+
export const __Date_prototype_valueOf = (_this: Date) => {
|
2057
2057
|
// 1. Let dateObject be the this value.
|
2058
2058
|
// 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
|
2059
2059
|
// 3. Return dateObject.[[DateValue]].
|
2060
2060
|
return __Porffor_date_read(_this);
|
2061
2061
|
};
|
2062
2062
|
|
2063
|
-
|
2064
2063
|
// 21.4.2.1 Date (...values)
|
2065
2064
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
|
2066
2065
|
export const Date = (): bytestring => {
|
@@ -13,7 +13,7 @@ export const escape = (input: string|bytestring): bytestring => {
|
|
13
13
|
|
14
14
|
let i: i32 = Porffor.wasm`local.get ${input}`;
|
15
15
|
|
16
|
-
if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.
|
16
|
+
if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.bytestring) {
|
17
17
|
const endPtr: i32 = i + len;
|
18
18
|
while (i < endPtr) {
|
19
19
|
const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
|
package/compiler/builtins/int.ts
CHANGED
@@ -17,7 +17,7 @@ export const parseInt = (input: string|bytestring, radix: number): f64 => {
|
|
17
17
|
let nMax: f64 = 58;
|
18
18
|
if (radix < 10) nMax = 48 + radix;
|
19
19
|
|
20
|
-
// if (Porffor.rawType(input) == Porffor.TYPES.
|
20
|
+
// if (Porffor.rawType(input) == Porffor.TYPES.bytestring) input = __ByteString_prototype_trimStart(input);
|
21
21
|
// else input = __String_prototype_trimStart(input);
|
22
22
|
|
23
23
|
let n: f64 = NaN;
|
@@ -28,7 +28,7 @@ export const parseInt = (input: string|bytestring, radix: number): f64 => {
|
|
28
28
|
|
29
29
|
let negative: boolean = false;
|
30
30
|
|
31
|
-
if (Porffor.rawType(input) == Porffor.TYPES.
|
31
|
+
if (Porffor.rawType(input) == Porffor.TYPES.bytestring) {
|
32
32
|
const endPtr: f64 = i + len;
|
33
33
|
|
34
34
|
// check start of string
|
@@ -524,4 +524,11 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
524
524
|
out.length = outPtr - Porffor.wasm`local.get ${out}`;
|
525
525
|
|
526
526
|
return out;
|
527
|
-
};
|
527
|
+
};
|
528
|
+
|
529
|
+
// 21.1.3.7 Number.prototype.valueOf ()
|
530
|
+
// https://tc39.es/ecma262/#sec-number.prototype.valueof
|
531
|
+
export const __Number_prototype_valueOf = (_this: number) => {
|
532
|
+
// 1. Return ? ThisNumberValue(this value).
|
533
|
+
return _this;
|
534
|
+
};
|