porffor 0.18.27 → 0.18.28
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 +51 -0
- package/compiler/generated_builtins.js +16 -2
- package/compiler/prototype.js +0 -43
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -36,6 +36,57 @@ export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
36
36
|
return out;
|
37
37
|
};
|
38
38
|
|
39
|
+
export const __Array_prototype_push = (_this: any[], ...items: any[]) => {
|
40
|
+
let len: i32 = _this.length;
|
41
|
+
const itemsLen: i32 = items.length;
|
42
|
+
|
43
|
+
for (let i: i32 = 0; i < itemsLen; i++) {
|
44
|
+
_this[i + len] = items[i];
|
45
|
+
}
|
46
|
+
|
47
|
+
return _this.length = len + itemsLen;
|
48
|
+
};
|
49
|
+
|
50
|
+
export const __Array_prototype_unshift = (_this: any[], ...items: any[]) => {
|
51
|
+
let len: i32 = _this.length;
|
52
|
+
const itemsLen: i32 = items.length;
|
53
|
+
|
54
|
+
// use memory.copy to move existing elements right
|
55
|
+
Porffor.wasm`;; ptr = ptr(_this) + 4
|
56
|
+
local #splice_ptr i32
|
57
|
+
local.get ${_this}
|
58
|
+
i32.to_u
|
59
|
+
i32.const 4
|
60
|
+
i32.add
|
61
|
+
local.set #splice_ptr
|
62
|
+
|
63
|
+
;; dst = ptr + itemsLen * 9
|
64
|
+
local.get #splice_ptr
|
65
|
+
local.get ${itemsLen}
|
66
|
+
i32.to_u
|
67
|
+
i32.const 9
|
68
|
+
i32.mul
|
69
|
+
i32.add
|
70
|
+
|
71
|
+
;; src = ptr
|
72
|
+
local.get #splice_ptr
|
73
|
+
|
74
|
+
;; size = len * 9
|
75
|
+
local.get ${len}
|
76
|
+
i32.to_u
|
77
|
+
i32.const 9
|
78
|
+
i32.mul
|
79
|
+
|
80
|
+
memory.copy 0 0`;
|
81
|
+
|
82
|
+
// write to now empty elements
|
83
|
+
for (let i: i32 = 0; i < itemsLen; i++) {
|
84
|
+
_this[i] = items[i];
|
85
|
+
}
|
86
|
+
|
87
|
+
return _this.length = len + itemsLen;
|
88
|
+
};
|
89
|
+
|
39
90
|
export const __Array_prototype_slice = (_this: any[], start: number, end: number) => {
|
40
91
|
const len: i32 = _this.length;
|
41
92
|
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
|
@@ -165,6 +165,20 @@ export const BuiltinFuncs = function() {
|
|
165
165
|
locals: [124,127,124,124,127,124,127,124,124,127,127,127,127,124,127,124,127,127,124,127,124,127,124,127,127,124], localNames: ["arg","arg#type","mapFn","mapFn#type","out","#last_type","len","type","type#type","hasMapFn","hasMapFn#type","i","#logicinner_tmp","#typeswitch_tmp","forof_base_pointer","forof_length","forof_counter","x","x#type","#member_setter_val_tmp","#member_setter_ptr_tmp","#indirect_arg0_type","#indirect_arg0_val","#indirect_arg1_type","#indirect_arg1_val","#indirect_arg2_type","#indirect_arg2_val","#indirect_func","#indirect_flags","__length_setter_tmp"],
|
166
166
|
table: 1,
|
167
167
|
};
|
168
|
+
this.__Array_prototype_push = {
|
169
|
+
wasm: (scope, {}) => [[32,0],[252,3],[40,1,0],[184],[33,4],[32,2],[252,3],[40,1,0],[184],[33,5],[68,0,0,0,0,0,0,0,0],[33,6],[3,64],[32,6],[32,5],[99],[4,64],[32,0],[252,3],[32,6],[32,4],[160],[252,3],[65,9],[108],[106],[34,8],[32,6],[252,3],[65,9],[108],[32,2],[252,3],[106],[34,9],[43,0,4],[32,9],[45,0,12],[33,10],[34,7],[57,0,4],[32,8],[32,10],[58,0,12],[32,6],[68,0,0,0,0,0,0,240,63],[160],[33,6],[12,1],[11],[11],[32,0],[252,3],[32,4],[32,5],[160],[34,11],[252,3],[54,1,0],[32,11],[65,0],[15]],
|
170
|
+
params: [124,127,124,127], typedParams: 1,
|
171
|
+
returns: [124,127], typedReturns: 1,
|
172
|
+
locals: [124,124,124,124,127,127,127,124], localNames: ["_this","_this#type","items","items#type","len","itemsLen","i","#member_setter_val_tmp","#member_setter_ptr_tmp","#loadArray_offset","#last_type","__length_setter_tmp"],
|
173
|
+
hasRestArgument: 1,
|
174
|
+
};
|
175
|
+
this.__Array_prototype_unshift = {
|
176
|
+
wasm: (scope, {}) => [[32,0],[252,3],[40,1,0],[184],[33,4],[32,2],[252,3],[40,1,0],[184],[33,5],[32,0],[252,3],[65,4],[106],[34,6],[32,5],[252,3],[65,9],[108],[106],[32,6],[32,4],[252,3],[65,9],[108],[252,10,0,0],[68,0,0,0,0,0,0,0,0],[33,7],[3,64],[32,7],[32,5],[99],[4,64],[32,0],[252,3],[32,7],[252,3],[65,9],[108],[106],[34,9],[32,7],[252,3],[65,9],[108],[32,2],[252,3],[106],[34,10],[43,0,4],[32,10],[45,0,12],[33,11],[34,8],[57,0,4],[32,9],[32,11],[58,0,12],[32,7],[68,0,0,0,0,0,0,240,63],[160],[33,7],[12,1],[11],[11],[32,0],[252,3],[32,4],[32,5],[160],[34,12],[252,3],[54,1,0],[32,12],[65,0],[15]],
|
177
|
+
params: [124,127,124,127], typedParams: 1,
|
178
|
+
returns: [124,127], typedReturns: 1,
|
179
|
+
locals: [124,124,127,124,124,127,127,127,124], localNames: ["_this","_this#type","items","items#type","len","itemsLen","#splice_ptr","i","#member_setter_val_tmp","#member_setter_ptr_tmp","#loadArray_offset","#last_type","__length_setter_tmp"],
|
180
|
+
hasRestArgument: 1,
|
181
|
+
};
|
168
182
|
this.__Array_prototype_slice = {
|
169
183
|
wasm: (scope, {builtin}) => [[32,0],[252,3],[40,1,0],[184],[33,6],[32,4],[65,0],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[97],[4,64],[32,6],[33,4],[11],[32,2],[68,0,0,0,0,0,0,0,0],[16, builtin('f64_|')],[33,2],[32,4],[68,0,0,0,0,0,0,0,0],[16, builtin('f64_|')],[33,4],[32,2],[68,0,0,0,0,0,0,0,0],[99],[4,64],[32,6],[32,2],[160],[34,2],[68,0,0,0,0,0,0,0,0],[99],[4,64],[68,0,0,0,0,0,0,0,0],[33,2],[11],[11],[32,2],[32,6],[100],[4,64],[32,6],[33,2],[11],[32,4],[68,0,0,0,0,0,0,0,0],[99],[4,64],[32,6],[32,4],[160],[34,4],[68,0,0,0,0,0,0,0,0],[99],[4,64],[68,0,0,0,0,0,0,0,0],[33,4],[11],[11],[32,4],[32,6],[100],[4,64],[32,6],[33,4],[11],[16, builtin('__Porffor_allocate')],[33,8],[33,7],[32,2],[32,4],[100],[4,64],[32,7],[65,208,0],[15],[11],[32,7],[33,9],[32,0],[34,10],[32,4],[68,0,0,0,0,0,0,34,64],[162],[160],[33,11],[32,10],[32,2],[68,0,0,0,0,0,0,34,64],[162],[160],[33,10],[3,64],[32,10],[32,11],[99],[4,64],[32,9],[252,2],[32,10],[252,2],[43,0,4],[57,0,4],[32,9],[252,2],[32,10],[252,2],[45,0,12],[58,0,12],[32,10],[68,0,0,0,0,0,0,34,64],[160],[33,10],[32,9],[68,0,0,0,0,0,0,34,64],[160],[33,9],[12,1],[11],[11],[32,7],[252,3],[32,4],[32,2],[161],[34,12],[252,3],[54,1,0],[32,7],[65,208,0],[15]],
|
170
184
|
params: [124,127,124,127,124,127], typedParams: 1,
|
@@ -1407,10 +1421,10 @@ export const BuiltinFuncs = function() {
|
|
1407
1421
|
locals: [], localNames: ["_this","_this#type"],
|
1408
1422
|
};
|
1409
1423
|
this.__Set_prototype_values = {
|
1410
|
-
wasm: (scope, {builtin}) => [[32,0],[252,2],[40,0,0],[183],[33,2],[16, builtin('__Porffor_allocate')],[33,4],[33,3],[68,0,0,0,0,0,0,0,0],[33,5],[3,64],[32,5],[32,2],[99],[4,64],[32,0],[65,19],[32,5],[65,0],[16, builtin('__Porffor_set_read')],[33,4],[33,6],[32,4],[33,7],[32,3],[
|
1424
|
+
wasm: (scope, {builtin,internalThrow}) => [[32,0],[252,2],[40,0,0],[183],[33,2],[16, builtin('__Porffor_allocate')],[33,4],[33,3],[68,0,0,0,0,0,0,0,0],[33,5],[3,64],[32,5],[32,2],[99],[4,64],[2,64],[32,0],[65,19],[32,5],[65,0],[16, builtin('__Porffor_set_read')],[33,4],[33,6],[32,4],[33,7],[32,3],[33,8],[65,208,0],[34,9],[33,10],[2,124],[32,10],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,8],[32,9],[65,4],[65,1],[54,1,0],[65,4],[32,6],[57,0,4],[65,4],[32,7],[58,0,12],[68,0,0,0,0,0,0,16,64],[65,208,0],[16, builtin('__Array_prototype_push')],[33,4],[12,1],[11],...internalThrow(scope, 'TypeError', `'push' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[26],[11],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[12,1],[11],[11],[32,3],[65,208,0],[15]],
|
1411
1425
|
params: [124,127], typedParams: 1,
|
1412
1426
|
returns: [124,127], typedReturns: 1,
|
1413
|
-
locals: [124,124,127,124,124,127,
|
1427
|
+
locals: [124,124,127,124,124,127,124,127,127], localNames: ["_this","_this#type","size","out","#last_type","i","val","val#type","#proto_target","#proto_target#type","#typeswitch_tmp"],
|
1414
1428
|
};
|
1415
1429
|
this.__Set_prototype_keys = {
|
1416
1430
|
wasm: (scope, {builtin}) => [[32,0],[65,19],[16, builtin('__Set_prototype_values')],[34,2],[15]],
|
package/compiler/prototype.js
CHANGED
@@ -60,46 +60,6 @@ export const PrototypeFuncs = function() {
|
|
60
60
|
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
61
61
|
],
|
62
62
|
|
63
|
-
// todo: only for 1 argument
|
64
|
-
push: (pointer, length, wNewMember, wType, iTmp, _2, _3, unusedValue) => [
|
65
|
-
// get memory offset of array at last index (length)
|
66
|
-
...length.getCachedI32(),
|
67
|
-
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
68
|
-
[ Opcodes.i32_mul ],
|
69
|
-
...pointer,
|
70
|
-
[ Opcodes.i32_add ],
|
71
|
-
[ Opcodes.local_set, iTmp ],
|
72
|
-
|
73
|
-
// store value
|
74
|
-
[ Opcodes.local_get, iTmp ],
|
75
|
-
...wNewMember,
|
76
|
-
[ Opcodes.store, 0, ValtypeSize.i32 ],
|
77
|
-
|
78
|
-
// store type
|
79
|
-
[ Opcodes.local_get, iTmp ],
|
80
|
-
...wType,
|
81
|
-
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
82
|
-
|
83
|
-
// bump array length by 1 and return it
|
84
|
-
...length.setI32([
|
85
|
-
...length.getCachedI32(),
|
86
|
-
...number(1, Valtype.i32),
|
87
|
-
[ Opcodes.i32_add ],
|
88
|
-
|
89
|
-
...(unusedValue() ? [] : [
|
90
|
-
...length.setCachedI32(),
|
91
|
-
...length.getCachedI32(),
|
92
|
-
])
|
93
|
-
]),
|
94
|
-
|
95
|
-
...(unusedValue() ? [] : [
|
96
|
-
...length.getCachedI32(),
|
97
|
-
Opcodes.i32_from_u
|
98
|
-
])
|
99
|
-
|
100
|
-
// ...length.get()
|
101
|
-
],
|
102
|
-
|
103
63
|
pop: (pointer, length, _1, _2, iTmp, _3, _4, unusedValue) => [
|
104
64
|
// if length == 0, noop
|
105
65
|
...length.getCachedI32(),
|
@@ -212,9 +172,6 @@ export const PrototypeFuncs = function() {
|
|
212
172
|
};
|
213
173
|
|
214
174
|
this[TYPES.array].at.local = Valtype.i32;
|
215
|
-
this[TYPES.array].push.returnType = TYPES.number;
|
216
|
-
this[TYPES.array].push.noArgRetLength = true;
|
217
|
-
this[TYPES.array].push.local = Valtype.i32;
|
218
175
|
this[TYPES.array].pop.local = Valtype.i32;
|
219
176
|
|
220
177
|
this[TYPES.string] = {
|
package/package.json
CHANGED