porffor 0.56.3 → 0.56.5
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/2c.js +31 -17
- package/compiler/builtins/array.ts +57 -21
- package/compiler/builtins/arraybuffer.ts +4 -6
- package/compiler/builtins/dataview.ts +2 -3
- package/compiler/builtins/date.ts +2 -5
- package/compiler/builtins/json.ts +7 -8
- package/compiler/builtins/{z_map.ts → map.ts} +26 -29
- package/compiler/builtins/object.ts +16 -23
- package/compiler/builtins/porffor.d.ts +1 -0
- package/compiler/builtins/reflect.ts +1 -2
- package/compiler/builtins/set.ts +8 -92
- package/compiler/builtins/typedarray.js +58 -18
- package/compiler/builtins/{z_weakmap.ts → weakmap.ts} +5 -9
- package/compiler/builtins/{z_weakset.ts → weakset.ts} +3 -7
- package/compiler/builtins/z_ecma262.ts +17 -21
- package/compiler/builtins_precompiled.js +725 -612
- package/compiler/codegen.js +6 -0
- package/package.json +1 -1
- package/r.cjs +101 -8
- package/runner/index.js +1 -1
- package/foo +0 -0
package/compiler/builtins/set.ts
CHANGED
@@ -1,50 +1,5 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
|
-
// dark wasm magic for dealing with memory, sorry.
|
4
|
-
export const __Porffor_set_read = (set: Set, index: number): any => {
|
5
|
-
Porffor.wasm`
|
6
|
-
local offset i32
|
7
|
-
local.get ${index}
|
8
|
-
i32.to_u
|
9
|
-
i32.const 9
|
10
|
-
i32.mul
|
11
|
-
local.get ${set}
|
12
|
-
i32.to_u
|
13
|
-
i32.add
|
14
|
-
local.set offset
|
15
|
-
|
16
|
-
local.get offset
|
17
|
-
f64.load 0 4
|
18
|
-
|
19
|
-
local.get offset
|
20
|
-
i32.load8_u 0 12
|
21
|
-
return`;
|
22
|
-
};
|
23
|
-
|
24
|
-
export const __Porffor_set_write = (set: Set, index: number, value: any): boolean => {
|
25
|
-
Porffor.wasm`
|
26
|
-
local offset i32
|
27
|
-
local.get ${index}
|
28
|
-
i32.to_u
|
29
|
-
i32.const 9
|
30
|
-
i32.mul
|
31
|
-
local.get ${set}
|
32
|
-
i32.to_u
|
33
|
-
i32.add
|
34
|
-
local.set offset
|
35
|
-
|
36
|
-
local.get offset
|
37
|
-
local.get ${value}
|
38
|
-
f64.store 0 4
|
39
|
-
|
40
|
-
local.get offset
|
41
|
-
local.get ${value+1}
|
42
|
-
i32.store8 0 12`;
|
43
|
-
|
44
|
-
return true;
|
45
|
-
};
|
46
|
-
|
47
|
-
|
48
3
|
export const __Set_prototype_size$get = (_this: Set) => {
|
49
4
|
return Porffor.wasm.i32.load(_this, 0, 0);
|
50
5
|
};
|
@@ -55,8 +10,7 @@ export const __Set_prototype_values = (_this: Set) => {
|
|
55
10
|
|
56
11
|
const out: any[] = __Porffor_allocate();
|
57
12
|
for (let i: number = 0; i < size; i++) {
|
58
|
-
|
59
|
-
Porffor.array.fastPush(out, val);
|
13
|
+
Porffor.array.fastPush(out, (_this as any[])[i]);
|
60
14
|
}
|
61
15
|
|
62
16
|
return out;
|
@@ -70,7 +24,7 @@ export const __Set_prototype_has = (_this: Set, value: any) => {
|
|
70
24
|
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
71
25
|
|
72
26
|
for (let i: number = 0; i < size; i++) {
|
73
|
-
if (
|
27
|
+
if ((_this as any[])[i] === value) return true;
|
74
28
|
}
|
75
29
|
|
76
30
|
return false;
|
@@ -81,7 +35,7 @@ export const __Set_prototype_add = (_this: Set, value: any) => {
|
|
81
35
|
|
82
36
|
// check if already in set
|
83
37
|
for (let i: number = 0; i < size; i++) {
|
84
|
-
if (
|
38
|
+
if ((_this as any[])[i] === value) return _this;
|
85
39
|
}
|
86
40
|
|
87
41
|
// not, add it
|
@@ -89,55 +43,18 @@ export const __Set_prototype_add = (_this: Set, value: any) => {
|
|
89
43
|
Porffor.wasm.i32.store(_this, size + 1, 0, 0);
|
90
44
|
|
91
45
|
// write new value at end
|
92
|
-
|
46
|
+
(_this as any[])[size] = value;
|
93
47
|
|
94
48
|
return _this;
|
95
49
|
};
|
96
50
|
|
97
51
|
export const __Set_prototype_delete = (_this: Set, value: any) => {
|
98
|
-
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
99
|
-
|
100
52
|
// check if already in set
|
53
|
+
const size: number = Porffor.wasm.i32.load(_this, 0, 0);
|
101
54
|
for (let i: number = 0; i < size; i++) {
|
102
|
-
if (
|
55
|
+
if ((_this as any[])[i] === value) {
|
103
56
|
// found, delete
|
104
|
-
|
105
|
-
Porffor.wasm.i32.store(_this, size - 1, 0, 0);
|
106
|
-
|
107
|
-
// offset all elements after by -1 ind
|
108
|
-
Porffor.wasm`
|
109
|
-
local offset i32
|
110
|
-
local.get ${i}
|
111
|
-
i32.to_u
|
112
|
-
i32.const 9
|
113
|
-
i32.mul
|
114
|
-
local.get ${_this}
|
115
|
-
i32.to_u
|
116
|
-
i32.add
|
117
|
-
i32.const 4
|
118
|
-
i32.add
|
119
|
-
local.set offset
|
120
|
-
|
121
|
-
;; dst = offset (this element)
|
122
|
-
local.get offset
|
123
|
-
|
124
|
-
;; src = offset + 9 (this element + 1 element)
|
125
|
-
local.get offset
|
126
|
-
i32.const 9
|
127
|
-
i32.add
|
128
|
-
|
129
|
-
;; size = (size - i - 1) * 9
|
130
|
-
local.get ${size}
|
131
|
-
local.get ${i}
|
132
|
-
f64.sub
|
133
|
-
i32.to_u
|
134
|
-
i32.const 1
|
135
|
-
i32.sub
|
136
|
-
i32.const 9
|
137
|
-
i32.mul
|
138
|
-
|
139
|
-
memory.copy 0 0`;
|
140
|
-
|
57
|
+
Porffor.array.fastRemove(_this, i, size);
|
141
58
|
return true;
|
142
59
|
}
|
143
60
|
}
|
@@ -148,8 +65,7 @@ memory.copy 0 0`;
|
|
148
65
|
|
149
66
|
export const __Set_prototype_clear = (_this: Set) => {
|
150
67
|
// just set size to 0
|
151
|
-
// do not need to delete any as will
|
152
|
-
// and will be overwritten with new add
|
68
|
+
// do not need to delete any as old will just be overwritten
|
153
69
|
Porffor.wasm.i32.store(_this, 0, 0, 0);
|
154
70
|
};
|
155
71
|
|
@@ -18,10 +18,9 @@ export default async () => {
|
|
18
18
|
let len: i32 = 0;
|
19
19
|
let bufferPtr: i32;
|
20
20
|
|
21
|
-
const type: i32 = Porffor.type(arg);
|
22
21
|
if (Porffor.fastOr(
|
23
|
-
type == Porffor.TYPES.arraybuffer,
|
24
|
-
type == Porffor.TYPES.sharedarraybuffer
|
22
|
+
Porffor.type(arg) == Porffor.TYPES.arraybuffer,
|
23
|
+
Porffor.type(arg) == Porffor.TYPES.sharedarraybuffer
|
25
24
|
)) {
|
26
25
|
bufferPtr = Porffor.wasm\`local.get \${arg}\`;
|
27
26
|
|
@@ -45,17 +44,17 @@ export default async () => {
|
|
45
44
|
Porffor.wasm.i32.store(outPtr, bufferPtr, 0, 4);
|
46
45
|
|
47
46
|
if (Porffor.fastOr(
|
48
|
-
type == Porffor.TYPES.array,
|
49
|
-
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
50
|
-
type == Porffor.TYPES.set,
|
51
|
-
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.float64array)
|
47
|
+
Porffor.type(arg) == Porffor.TYPES.array,
|
48
|
+
Porffor.type(arg) == Porffor.TYPES.string, Porffor.type(arg) == Porffor.TYPES.bytestring,
|
49
|
+
Porffor.type(arg) == Porffor.TYPES.set,
|
50
|
+
Porffor.fastAnd(Porffor.type(arg) >= Porffor.TYPES.uint8array, Porffor.type(arg) <= Porffor.TYPES.float64array)
|
52
51
|
)) {
|
53
52
|
let i: i32 = 0;
|
54
53
|
for (const x of arg) {
|
55
54
|
out[i++] = x;
|
56
55
|
}
|
57
56
|
len = i;
|
58
|
-
} else if (type == Porffor.TYPES.number) {
|
57
|
+
} else if (Porffor.type(arg) == Porffor.TYPES.number) {
|
59
58
|
len = Math.trunc(arg);
|
60
59
|
}
|
61
60
|
|
@@ -75,17 +74,14 @@ export const __${name}_from = (arg: any, mapFn: any): ${name} => {
|
|
75
74
|
const arr: any[] = Porffor.allocate();
|
76
75
|
let len: i32 = 0;
|
77
76
|
|
78
|
-
const type = Porffor.type(arg);
|
79
77
|
if (Porffor.fastOr(
|
80
|
-
type == Porffor.TYPES.array,
|
81
|
-
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
82
|
-
type == Porffor.TYPES.set,
|
83
|
-
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.float64array)
|
78
|
+
Porffor.type(arg) == Porffor.TYPES.array,
|
79
|
+
Porffor.type(arg) == Porffor.TYPES.string, Porffor.type(arg) == Porffor.TYPES.bytestring,
|
80
|
+
Porffor.type(arg) == Porffor.TYPES.set,
|
81
|
+
Porffor.fastAnd(Porffor.type(arg) >= Porffor.TYPES.uint8array, Porffor.type(arg) <= Porffor.TYPES.float64array)
|
84
82
|
)) {
|
85
|
-
const hasMapFn = Porffor.type(mapFn) != Porffor.TYPES.undefined;
|
86
|
-
|
87
83
|
let i: i32 = 0;
|
88
|
-
if (
|
84
|
+
if (Porffor.type(mapFn) != Porffor.TYPES.undefined) {
|
89
85
|
if (Porffor.type(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
|
90
86
|
|
91
87
|
for (const x of arg) {
|
@@ -132,8 +128,6 @@ export const __${name}_prototype_at = (_this: ${name}, index: number) => {
|
|
132
128
|
|
133
129
|
export const __${name}_prototype_slice = (_this: ${name}, start: number, end: number) => {
|
134
130
|
const len: i32 = _this.length;
|
135
|
-
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
|
136
|
-
|
137
131
|
start |= 0;
|
138
132
|
end |= 0;
|
139
133
|
|
@@ -162,6 +156,52 @@ export const __${name}_prototype_slice = (_this: ${name}, start: number, end: nu
|
|
162
156
|
return out;
|
163
157
|
};
|
164
158
|
|
159
|
+
export const __${name}_prototype_set = (_this: ${name}, array: any, offset: number) => {
|
160
|
+
const len: i32 = _this.length;
|
161
|
+
|
162
|
+
offset |= 0;
|
163
|
+
if (Porffor.fastOr(offset < 0, offset > len)) throw new RangeError('Offset out of bounds');
|
164
|
+
|
165
|
+
if (Porffor.fastOr(
|
166
|
+
Porffor.type(array) == Porffor.TYPES.array,
|
167
|
+
Porffor.type(array) == Porffor.TYPES.string, Porffor.type(array) == Porffor.TYPES.bytestring,
|
168
|
+
Porffor.type(array) == Porffor.TYPES.set,
|
169
|
+
Porffor.fastAnd(Porffor.type(array) >= Porffor.TYPES.uint8array, Porffor.type(array) <= Porffor.TYPES.float64array)
|
170
|
+
)) {
|
171
|
+
let i: i32 = offset;
|
172
|
+
for (const x of array) {
|
173
|
+
_this[i++] = Porffor.type(x) == Porffor.TYPES.number ? x : 0;
|
174
|
+
if (i > len) throw new RangeError('Array is too long for given offset');
|
175
|
+
}
|
176
|
+
}
|
177
|
+
};
|
178
|
+
|
179
|
+
export const __${name}_prototype_subarray = (_this: ${name}, start: number, end: any) => {
|
180
|
+
const len: i32 = _this.length;
|
181
|
+
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
|
182
|
+
|
183
|
+
start |= 0;
|
184
|
+
end |= 0;
|
185
|
+
|
186
|
+
if (start < 0) {
|
187
|
+
start = len + start;
|
188
|
+
if (start < 0) start = 0;
|
189
|
+
}
|
190
|
+
if (start > len) start = len;
|
191
|
+
if (end < 0) {
|
192
|
+
end = len + end;
|
193
|
+
if (end < 0) end = 0;
|
194
|
+
}
|
195
|
+
if (end > len) end = len;
|
196
|
+
|
197
|
+
const out: ${name} = Porffor.allocateBytes(12);
|
198
|
+
Porffor.wasm.i32.store(out, end - start, 0, 0);
|
199
|
+
Porffor.wasm.i32.store(out, Porffor.wasm.i32.load(_this, 0, 4) + start * ${name}.BYTES_PER_ELEMENT, 0, 4);
|
200
|
+
Porffor.wasm.i32.store(out, Porffor.wasm.i32.load(_this, 0, 8) + start * ${name}.BYTES_PER_ELEMENT, 0, 8);
|
201
|
+
|
202
|
+
return out;
|
203
|
+
};
|
204
|
+
|
165
205
|
${typedArrayFuncs.reduce((acc, x) => acc + x.replace('// @porf-typed-array\n', '').replaceAll('Array', name).replaceAll('any[]', name) + '\n\n', '')}
|
166
206
|
`;
|
167
207
|
|
@@ -1,21 +1,18 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
export const __WeakMap_prototype_has = (_this: WeakMap, key: any) => {
|
4
|
-
|
5
|
-
return __Map_prototype_has(map, key);
|
4
|
+
return __Map_prototype_has(_this as Map, key);
|
6
5
|
};
|
7
6
|
|
8
7
|
export const __WeakMap_prototype_set = (_this: WeakMap, key: any, value: any) => {
|
9
8
|
if (!Porffor.object.isObjectOrSymbol(key)) throw new TypeError('Value in WeakSet needs to be an object or symbol');
|
10
9
|
|
11
|
-
|
12
|
-
__Map_prototype_set(map, key, value);
|
10
|
+
__Map_prototype_set(_this as Map, key, value);
|
13
11
|
return _this;
|
14
12
|
};
|
15
13
|
|
16
14
|
export const __WeakMap_prototype_delete = (_this: WeakMap, key: any) => {
|
17
|
-
|
18
|
-
return __Map_prototype_delete(map, key);
|
15
|
+
return __Map_prototype_delete(_this as Map, key);
|
19
16
|
};
|
20
17
|
|
21
18
|
export const WeakMap = function (iterable: any): WeakMap {
|
@@ -23,10 +20,9 @@ export const WeakMap = function (iterable: any): WeakMap {
|
|
23
20
|
|
24
21
|
const out: WeakMap = Porffor.allocateBytes(8);
|
25
22
|
|
26
|
-
const keys:
|
27
|
-
Porffor.wasm.i32.store(out, keys, 0, 0);
|
28
|
-
|
23
|
+
const keys: any[] = Porffor.allocate();
|
29
24
|
const vals: any[] = Porffor.allocate();
|
25
|
+
Porffor.wasm.i32.store(out, keys, 0, 0);
|
30
26
|
Porffor.wasm.i32.store(out, vals, 0, 4);
|
31
27
|
|
32
28
|
if (iterable != null) for (const x of iterable) {
|
@@ -1,28 +1,24 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
export const __WeakSet_prototype_has = (_this: WeakSet, value: any) => {
|
4
|
-
|
5
|
-
return __Set_prototype_has(set, value);
|
4
|
+
return __Set_prototype_has(_this as Set, value);
|
6
5
|
};
|
7
6
|
|
8
7
|
export const __WeakSet_prototype_add = (_this: WeakSet, value: any) => {
|
9
8
|
if (!Porffor.object.isObjectOrSymbol(value)) throw new TypeError('Value in WeakSet needs to be an object or symbol');
|
10
9
|
|
11
|
-
|
12
|
-
__Set_prototype_add(set, value);
|
10
|
+
__Set_prototype_add(_this as Set, value);
|
13
11
|
return _this;
|
14
12
|
};
|
15
13
|
|
16
14
|
export const __WeakSet_prototype_delete = (_this: WeakSet, value: any) => {
|
17
|
-
|
18
|
-
return __Set_prototype_delete(set, value);
|
15
|
+
return __Set_prototype_delete(_this as Set, value);
|
19
16
|
};
|
20
17
|
|
21
18
|
export const WeakSet = function (iterable: any): WeakSet {
|
22
19
|
if (!new.target) throw new TypeError("Constructor WeakSet requires 'new'");
|
23
20
|
|
24
21
|
const out: WeakSet = __Porffor_allocate();
|
25
|
-
|
26
22
|
if (iterable != null) for (const x of iterable) {
|
27
23
|
__WeakSet_prototype_add(out, x);
|
28
24
|
}
|
@@ -28,20 +28,18 @@ export const __ecma262_ToPrimitive_String = (input: any): any => {
|
|
28
28
|
// 7.1.4 ToNumber (argument)
|
29
29
|
// https://tc39.es/ecma262/#sec-tonumber
|
30
30
|
export const __ecma262_ToNumber = (argument: unknown): number => {
|
31
|
-
const t: i32 = Porffor.type(argument);
|
32
|
-
|
33
31
|
// 1. If argument is a Number, return argument.
|
34
|
-
if (
|
32
|
+
if (Porffor.type(argument) == Porffor.TYPES.number) return argument;
|
35
33
|
|
36
34
|
// 2. If argument is either a Symbol or a BigInt, throw a TypeError exception.
|
37
35
|
if (Porffor.fastOr(
|
38
|
-
|
39
|
-
|
36
|
+
Porffor.type(argument) == Porffor.TYPES.symbol,
|
37
|
+
Porffor.type(argument) == Porffor.TYPES.bigint)) throw new TypeError('Cannot convert Symbol or BigInt to a number');
|
40
38
|
|
41
39
|
// 3. If argument is undefined, return NaN.
|
42
40
|
if (Porffor.fastOr(
|
43
|
-
|
44
|
-
|
41
|
+
Porffor.type(argument) == Porffor.TYPES.undefined,
|
42
|
+
Porffor.type(argument) == Porffor.TYPES.empty)) return NaN;
|
45
43
|
|
46
44
|
// 4. If argument is either null or false, return +0𝔽.
|
47
45
|
if (Porffor.fastOr(
|
@@ -54,8 +52,8 @@ export const __ecma262_ToNumber = (argument: unknown): number => {
|
|
54
52
|
|
55
53
|
// 6. If argument is a String, return StringToNumber(argument).
|
56
54
|
if (Porffor.fastOr(
|
57
|
-
|
58
|
-
|
55
|
+
Porffor.type(argument) == Porffor.TYPES.string,
|
56
|
+
Porffor.type(argument) == Porffor.TYPES.bytestring)) return __ecma262_StringToNumber(argument);
|
59
57
|
|
60
58
|
// 7. Assert: argument is an Object.
|
61
59
|
// 8. Let primValue be ? ToPrimitive(argument, number).
|
@@ -124,27 +122,25 @@ export const __ecma262_ToIndex = (value: unknown): number => {
|
|
124
122
|
// 7.1.17 ToString (argument)
|
125
123
|
// https://tc39.es/ecma262/#sec-tostring
|
126
124
|
export const __ecma262_ToString = (argument: unknown): any => {
|
127
|
-
const type: i32 = Porffor.type(argument);
|
128
|
-
|
129
125
|
// 1. If argument is a String, return argument.
|
130
126
|
if (Porffor.fastOr(
|
131
|
-
type == Porffor.TYPES.string,
|
132
|
-
type == Porffor.TYPES.bytestring)) return argument;
|
127
|
+
Porffor.type(argument) == Porffor.TYPES.string,
|
128
|
+
Porffor.type(argument) == Porffor.TYPES.bytestring)) return argument;
|
133
129
|
|
134
130
|
// 2. If argument is a Symbol, throw a TypeError exception.
|
135
|
-
if (type == Porffor.TYPES.symbol) throw new TypeError('Cannot convert a Symbol value to a string');
|
131
|
+
if (Porffor.type(argument) == Porffor.TYPES.symbol) throw new TypeError('Cannot convert a Symbol value to a string');
|
136
132
|
|
137
133
|
// 3. If argument is undefined, return "undefined".
|
138
134
|
if (Porffor.fastOr(
|
139
|
-
type == Porffor.TYPES.undefined,
|
140
|
-
type == Porffor.TYPES.empty)) return 'undefined';
|
135
|
+
Porffor.type(argument) == Porffor.TYPES.undefined,
|
136
|
+
Porffor.type(argument) == Porffor.TYPES.empty)) return 'undefined';
|
141
137
|
|
142
138
|
// 4. If argument is null, return "null".
|
143
139
|
if (Porffor.fastAnd(
|
144
|
-
type == Porffor.TYPES.object,
|
140
|
+
Porffor.type(argument) == Porffor.TYPES.object,
|
145
141
|
argument == 0)) return 'null';
|
146
142
|
|
147
|
-
if (type == Porffor.TYPES.boolean) {
|
143
|
+
if (Porffor.type(argument) == Porffor.TYPES.boolean) {
|
148
144
|
// 5. If argument is true, return "true".
|
149
145
|
if (argument == true) return 'true';
|
150
146
|
|
@@ -153,15 +149,15 @@ export const __ecma262_ToString = (argument: unknown): any => {
|
|
153
149
|
}
|
154
150
|
|
155
151
|
// 7. If argument is a Number, return Number::toString(argument, 10).
|
156
|
-
if (type == Porffor.TYPES.number) return __Number_prototype_toString(argument, 10);
|
152
|
+
if (Porffor.type(argument) == Porffor.TYPES.number) return __Number_prototype_toString(argument, 10);
|
157
153
|
|
158
154
|
// 8. If argument is a BigInt, return BigInt::toString(argument, 10).
|
159
155
|
if (Porffor.comptime.flag`hasType.bigint`) {
|
160
|
-
if (type == Porffor.TYPES.bigint) return __Porffor_bigint_toString(argument, 10);
|
156
|
+
if (Porffor.type(argument) == Porffor.TYPES.bigint) return __Porffor_bigint_toString(argument, 10);
|
161
157
|
}
|
162
158
|
|
163
159
|
// hack: StringObject -> String
|
164
|
-
if (type == Porffor.TYPES.stringobject) {
|
160
|
+
if (Porffor.type(argument) == Porffor.TYPES.stringobject) {
|
165
161
|
return argument as string;
|
166
162
|
}
|
167
163
|
|