porffor 0.41.2 → 0.41.4
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/_internal_string.ts +0 -4
- package/compiler/builtins/object.ts +2 -1
- package/compiler/builtins/porffor.d.ts +4 -2
- package/compiler/builtins/string_f64.ts +30 -5
- package/compiler/builtins/z_ecma262.ts +6 -0
- package/compiler/builtins_precompiled.js +59 -58
- package/compiler/codegen.js +132 -97
- package/compiler/types.js +1 -0
- package/compiler/wrap.js +2 -0
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -16,7 +16,6 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
|
|
16
16
|
|
17
17
|
// todo/perf: just use a.toString()?
|
18
18
|
a = ecma262.ToString(a);
|
19
|
-
at = Porffor.rawType(a);
|
20
19
|
}
|
21
20
|
|
22
21
|
if ((bt | 0b10000000) != Porffor.TYPES.bytestring) {
|
@@ -31,7 +30,6 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
|
|
31
30
|
|
32
31
|
// todo/perf: just use b.toString()?
|
33
32
|
b = ecma262.ToString(b);
|
34
|
-
bt = Porffor.rawType(b);
|
35
33
|
}
|
36
34
|
|
37
35
|
return Porffor.strcmp(a, b);
|
@@ -45,14 +43,12 @@ export const __Porffor_concatStrings = (a: any, b: any): boolean => {
|
|
45
43
|
// a is not string or bytestring
|
46
44
|
// todo/perf: just use a.toString()?
|
47
45
|
a = ecma262.ToString(a);
|
48
|
-
at = Porffor.rawType(a);
|
49
46
|
}
|
50
47
|
|
51
48
|
if ((bt | 0b10000000) != Porffor.TYPES.bytestring) {
|
52
49
|
// b is not string or bytestring
|
53
50
|
// todo/perf: just use b.toString()?
|
54
51
|
b = ecma262.ToString(b);
|
55
|
-
bt = Porffor.rawType(b);
|
56
52
|
}
|
57
53
|
|
58
54
|
return Porffor.strcat(a, b);
|
@@ -703,7 +703,8 @@ export const __Object_prototype_toString = (_this: any) => {
|
|
703
703
|
t == Porffor.TYPES.numberobject)) return out = '[object Number]';
|
704
704
|
if (Porffor.fastOr(
|
705
705
|
t == Porffor.TYPES.string,
|
706
|
-
t == Porffor.TYPES.bytestring
|
706
|
+
t == Porffor.TYPES.bytestring,
|
707
|
+
t == Porffor.TYPES.stringobject)) return out = '[object String]';
|
707
708
|
if (t == Porffor.TYPES.date) return out = '[object Date]';
|
708
709
|
if (t == Porffor.TYPES.regexp) return out = '[object RegExp]';
|
709
710
|
|
@@ -4,7 +4,8 @@ export type f64 = number;
|
|
4
4
|
export type bytestring = string;
|
5
5
|
|
6
6
|
export type BooleanObject = Boolean;
|
7
|
-
export type NumberObject =
|
7
|
+
export type NumberObject = Number;
|
8
|
+
export type StringObject = String;
|
8
9
|
|
9
10
|
type PorfforGlobal = {
|
10
11
|
wasm: {
|
@@ -146,5 +147,6 @@ declare global {
|
|
146
147
|
type bytestring = string;
|
147
148
|
|
148
149
|
type BooleanObject = Boolean;
|
149
|
-
type NumberObject =
|
150
|
+
type NumberObject = Number;
|
151
|
+
type StringObject = String;
|
150
152
|
}
|
@@ -1,10 +1,35 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
|
-
//
|
4
|
-
//
|
5
|
-
export const String = function (
|
6
|
-
|
7
|
-
|
3
|
+
// 22.1.1.1 String (value)
|
4
|
+
// https://tc39.es/ecma262/#sec-string-constructor-string-value
|
5
|
+
export const String = function (...args: any[]): string|bytestring|StringObject {
|
6
|
+
let s: bytestring|string = '';
|
7
|
+
|
8
|
+
// 1. If value is not present, then
|
9
|
+
// a. Let s be the empty String.
|
10
|
+
// s is already empty
|
11
|
+
|
12
|
+
// 2. Else,
|
13
|
+
if (args.length > 0) {
|
14
|
+
const value: any = args[0];
|
15
|
+
|
16
|
+
// a. If NewTarget is undefined and value is a Symbol, return SymbolDescriptiveString(value).
|
17
|
+
if (!new.target && Porffor.rawType(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
|
18
|
+
|
19
|
+
// b. Let s be ? ToString(value).
|
20
|
+
s = ecma262.ToString(value);
|
21
|
+
}
|
22
|
+
|
23
|
+
// 3. If NewTarget is undefined, return s.
|
24
|
+
if (!new.target) return s;
|
25
|
+
|
26
|
+
// 4. Return StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, "%String.prototype%")).
|
27
|
+
|
28
|
+
// force bytestrings to strings
|
29
|
+
if (Porffor.rawType(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
|
30
|
+
|
31
|
+
const O: StringObject = s;
|
32
|
+
return O;
|
8
33
|
};
|
9
34
|
|
10
35
|
export const __String_fromCharCode = (...codes: any[]): bytestring|string => {
|
@@ -154,6 +154,12 @@ export const __ecma262_ToString = (argument: unknown): any => {
|
|
154
154
|
|
155
155
|
// 8. If argument is a BigInt, return BigInt::toString(argument, 10).
|
156
156
|
|
157
|
+
// hack: StringObject -> String
|
158
|
+
if (type == Porffor.TYPES.stringobject) {
|
159
|
+
const remap: string = argument;
|
160
|
+
return remap;
|
161
|
+
}
|
162
|
+
|
157
163
|
// 9. Assert: argument is an Object.
|
158
164
|
// 10. Let primValue be ? ToPrimitive(argument, string).
|
159
165
|
const primValue: any = __ecma262_ToPrimitive_String(argument);
|