porffor 0.18.6 → 0.18.7
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 +66 -1
- package/compiler/codegen.js +7 -9
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -46,7 +46,72 @@ export const __Array_prototype_slice = (_this: any[], start: number, end: number
|
|
46
46
|
return out;
|
47
47
|
};
|
48
48
|
|
49
|
-
|
49
|
+
export const __Array_prototype_splice = (_this: any[], index: any, deleteCount: any, ...values: any[]) => {
|
50
|
+
const len: i32 = _this.length;
|
51
|
+
|
52
|
+
if (Porffor.rawType(index) == Porffor.TYPES.undefined) index = len;
|
53
|
+
index |= 0;
|
54
|
+
if (index < 0) {
|
55
|
+
index = len + index;
|
56
|
+
if (index < 0) index = 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (Porffor.rawType(deleteCount) == Porffor.TYPES.undefined) deleteCount = 1;
|
60
|
+
deleteCount |= 0;
|
61
|
+
if (deleteCount < 0) deleteCount = 0;
|
62
|
+
if (deleteCount > len - index) deleteCount = len - index;
|
63
|
+
|
64
|
+
const out: any[] = Porffor.allocate();
|
65
|
+
out.length = deleteCount;
|
66
|
+
|
67
|
+
for (let i: i32 = 0; i < deleteCount; i++) {
|
68
|
+
out[i] = _this[index + i];
|
69
|
+
}
|
70
|
+
|
71
|
+
_this.length = len - deleteCount;
|
72
|
+
|
73
|
+
// memory.copy lol
|
74
|
+
Porffor.wasm`
|
75
|
+
;; dst = ptr(this) + index * sizeof element + sizeof length
|
76
|
+
local.get ${_this}
|
77
|
+
i32.to_u
|
78
|
+
local.get ${index}
|
79
|
+
i32.to_u
|
80
|
+
i32.const 9
|
81
|
+
i32.mul
|
82
|
+
i32.add
|
83
|
+
i32.const 4
|
84
|
+
i32.add
|
85
|
+
|
86
|
+
local #splice_ptr i32
|
87
|
+
local.tee #splice_ptr
|
88
|
+
|
89
|
+
;; src = dst + deletecount * sizeof element
|
90
|
+
local.get #splice_ptr
|
91
|
+
local.get ${deleteCount}
|
92
|
+
i32.to_u
|
93
|
+
i32.const 9
|
94
|
+
i32.mul
|
95
|
+
i32.add
|
96
|
+
|
97
|
+
;; size = (length - deleteCount - index) * sizeof element
|
98
|
+
local.get ${len}
|
99
|
+
i32.to_u
|
100
|
+
local.get ${deleteCount}
|
101
|
+
i32.to_u
|
102
|
+
i32.sub
|
103
|
+
local.get ${index}
|
104
|
+
i32.to_u
|
105
|
+
i32.sub
|
106
|
+
i32.const 9
|
107
|
+
i32.mul
|
108
|
+
|
109
|
+
memory.copy 0 0`;
|
110
|
+
|
111
|
+
return out;
|
112
|
+
};
|
113
|
+
|
114
|
+
// todo: unshift
|
50
115
|
|
51
116
|
// @porf-typed-array
|
52
117
|
export const __Array_prototype_fill = (_this: any[], value: any, start: any, end: any) => {
|
package/compiler/codegen.js
CHANGED
@@ -199,14 +199,8 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
199
199
|
return out;
|
200
200
|
},
|
201
201
|
|
202
|
-
__Porffor_bs: str =>
|
203
|
-
|
204
|
-
...(name ? setType(scope, name, TYPES.bytestring) : setLastType(scope, TYPES.bytestring))
|
205
|
-
],
|
206
|
-
__Porffor_s: str => [
|
207
|
-
...makeString(scope, str, global, name, false),
|
208
|
-
...(name ? setType(scope, name, TYPES.string) : setLastType(scope, TYPES.string))
|
209
|
-
],
|
202
|
+
__Porffor_bs: str => makeString(scope, str, global, name, true),
|
203
|
+
__Porffor_s: str => makeString(scope, str, global, name, false)
|
210
204
|
};
|
211
205
|
|
212
206
|
const func = decl.tag.name;
|
@@ -1383,7 +1377,11 @@ const getNodeType = (scope, node) => {
|
|
1383
1377
|
|
1384
1378
|
if (node.type === 'TaggedTemplateExpression') {
|
1385
1379
|
// hack
|
1386
|
-
|
1380
|
+
switch (node.tag.name) {
|
1381
|
+
case '__Porffor_wasm': return TYPES.number;
|
1382
|
+
case '__Porffor_bs': return TYPES.bytestring;
|
1383
|
+
case '__Porffor_s': return TYPES.string;
|
1384
|
+
}
|
1387
1385
|
}
|
1388
1386
|
|
1389
1387
|
if (scope.locals['#last_type']) return getLastType(scope);
|
package/package.json
CHANGED