porffor 0.18.41 → 0.18.43
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/porffor.d.ts +1 -0
- package/compiler/builtins/set.ts +10 -1
- package/compiler/builtins/z_map.ts +84 -0
- package/compiler/generated_builtins.js +318 -262
- package/compiler/precompile.js +5 -1
- package/compiler/types.js +3 -2
- package/compiler/wrap.js +22 -0
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/builtins/set.ts
CHANGED
@@ -55,6 +55,15 @@ i32.store8 0 12`;
|
|
55
55
|
return true;
|
56
56
|
};
|
57
57
|
|
58
|
+
export const __Porffor_set_indexOf = (_this: Set, value: any): i32 => {
|
59
|
+
const size: i32 = Porffor.wasm.i32.load(_this, 0, 0);
|
60
|
+
for (let i: i32 = 0; i < size; i++) {
|
61
|
+
if (Porffor.set.read(_this, i) === value) return i;
|
62
|
+
}
|
63
|
+
|
64
|
+
return -1;
|
65
|
+
};
|
66
|
+
|
58
67
|
|
59
68
|
export const __Set_prototype_size$get = (_this: Set) => {
|
60
69
|
return Porffor.wasm.i32.load(_this, 0, 0);
|
@@ -164,7 +173,7 @@ export const __Set_prototype_clear = (_this: Set) => {
|
|
164
173
|
Porffor.wasm.i32.store(_this, 0, 0, 0);
|
165
174
|
};
|
166
175
|
|
167
|
-
export const Set = function (iterable: any):
|
176
|
+
export const Set = function (iterable: any): Set {
|
168
177
|
if (!new.target) throw new TypeError("Constructor Set requires 'new'");
|
169
178
|
|
170
179
|
const out: Set = __Porffor_allocate();
|
@@ -0,0 +1,84 @@
|
|
1
|
+
export const Map = function (iterable: any): Map {
|
2
|
+
if (!new.target) throw new TypeError("Constructor Map requires 'new'");
|
3
|
+
|
4
|
+
const out: Map = Porffor.allocateBytes(8);
|
5
|
+
|
6
|
+
const keys: Set = Porffor.allocate();
|
7
|
+
Porffor.wasm.i32.store(out, keys, 0, 0);
|
8
|
+
|
9
|
+
const vals: any[] = Porffor.allocate();
|
10
|
+
Porffor.wasm.i32.store(out, vals, 0, 4);
|
11
|
+
|
12
|
+
return out;
|
13
|
+
};
|
14
|
+
|
15
|
+
export const __Map_prototype_size$get = (_this: Map) => {
|
16
|
+
return Porffor.wasm.i32.load(Porffor.wasm.i32.load(_this, 0, 0), 0, 0);
|
17
|
+
};
|
18
|
+
|
19
|
+
export const __Map_prototype_has = (_this: Map, key: any) => {
|
20
|
+
const keys: Set = Porffor.wasm.i32.load(_this, 0, 0);
|
21
|
+
return __Set_prototype_has(key);
|
22
|
+
};
|
23
|
+
|
24
|
+
export const __Map_prototype_get = (_this: Map, key: any) => {
|
25
|
+
const keys: Set = Porffor.wasm.i32.load(_this, 0, 0);
|
26
|
+
const vals: any[] = Porffor.wasm.i32.load(_this, 0, 4);
|
27
|
+
|
28
|
+
const keyIdx: i32 = Porffor.set.indexOf(keys, key);
|
29
|
+
if (keyIdx == -1) return undefined;
|
30
|
+
|
31
|
+
return vals[keyIdx];
|
32
|
+
};
|
33
|
+
|
34
|
+
export const __Map_prototype_set = (_this: Map, key: any, value: any) => {
|
35
|
+
const keys: Set = Porffor.wasm.i32.load(_this, 0, 0);
|
36
|
+
const vals: any[] = Porffor.wasm.i32.load(_this, 0, 4);
|
37
|
+
|
38
|
+
const size: i32 = Porffor.wasm.i32.load(keys, 0, 0);
|
39
|
+
|
40
|
+
let keyIdx: i32 = Porffor.set.indexOf(keys, key);
|
41
|
+
if (keyIdx == -1) {
|
42
|
+
// add key if non-existent
|
43
|
+
keyIdx = size;
|
44
|
+
__Set_prototype_add(keys, key);
|
45
|
+
}
|
46
|
+
|
47
|
+
vals[keyIdx] = value;
|
48
|
+
|
49
|
+
return _this;
|
50
|
+
};
|
51
|
+
|
52
|
+
export const __Map_prototype_delete = (_this: Map, key: any) => {
|
53
|
+
const keys: Set = Porffor.wasm.i32.load(_this, 0, 0);
|
54
|
+
|
55
|
+
const keyIdx = Porffor.set.indexOf(keys, key);
|
56
|
+
if (keyIdx == -1) return false;
|
57
|
+
|
58
|
+
__Set_prototype_delete(key);
|
59
|
+
|
60
|
+
const vals: any[] = Porffor.wasm.i32.load(_this, 0, 4);
|
61
|
+
__Array_prototype_splice(keyIdx, 1);
|
62
|
+
|
63
|
+
return true;
|
64
|
+
};
|
65
|
+
|
66
|
+
export const __Map_prototype_clear = (_this: Map) => {
|
67
|
+
const keys: Set = Porffor.wasm.i32.load(_this, 0, 0);
|
68
|
+
__Set_prototype_clear(keys);
|
69
|
+
|
70
|
+
const vals: any[] = Porffor.wasm.i32.load(_this, 0, 4);
|
71
|
+
vals.length = 0;
|
72
|
+
};
|
73
|
+
|
74
|
+
export const __Map_prototype_forEach = (_this: Map, callbackFn: any) => {
|
75
|
+
const keys: Set = Porffor.wasm.i32.load(_this, 0, 0);
|
76
|
+
const vals: any[] = Porffor.wasm.i32.load(_this, 0, 4);
|
77
|
+
|
78
|
+
const size: i32 = Porffor.wasm.i32.load(keys, 0, 0);
|
79
|
+
|
80
|
+
let i: i32 = 0;
|
81
|
+
while (i < size) {
|
82
|
+
callbackFn(vals[i], Porffor.set.read(keys, i++), _this);
|
83
|
+
}
|
84
|
+
};
|