porffor 0.24.13 → 0.24.14
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/assemble.js +2 -5
- package/compiler/builtins/_internal_object.ts +30 -1
- package/compiler/builtins.js +15 -0
- package/compiler/builtins_precompiled.js +334 -868
- package/compiler/codegen.js +44 -110
- package/compiler/precompile.js +1 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/assemble.js
CHANGED
@@ -168,8 +168,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
168
168
|
let name = func.name;
|
169
169
|
|
170
170
|
let argc = func.params.length;
|
171
|
-
if (func.
|
172
|
-
if (func.usesThis) argc -= 2;
|
171
|
+
if (func.constr) argc -= 4;
|
173
172
|
if (!func.internal || func.typedParams) argc = Math.floor(argc / 2);
|
174
173
|
|
175
174
|
// hack: argc-- for prototype methods to remove _this hack from count
|
@@ -178,10 +177,8 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
178
177
|
bytes.push(argc % 256, (argc / 256 | 0) % 256);
|
179
178
|
|
180
179
|
let flags = 0b00000000; // 8 flag bits
|
181
|
-
if (func.returnType != null) flags |=
|
180
|
+
if (func.returnType != null) flags |= 0b01;
|
182
181
|
if (func.constr) flags |= 0b10;
|
183
|
-
if (func.newTarget) flags |= 0b100;
|
184
|
-
if (func.usesThis) flags |= 0b1000;
|
185
182
|
bytes.push(flags);
|
186
183
|
|
187
184
|
// eg: __String_prototype_toLowerCase -> toLowerCase
|
@@ -198,10 +198,24 @@ i32.const 128
|
|
198
198
|
return`;
|
199
199
|
}
|
200
200
|
|
201
|
-
Porffor.
|
201
|
+
const funcFlags: i32 = Porffor.funcLut.flags(get);
|
202
|
+
if (funcFlags & 0b10) {
|
203
|
+
// constructor func, add new.target, this args
|
204
|
+
Porffor.wasm`
|
205
|
+
f64.const 0
|
206
|
+
i32.const 0
|
207
|
+
local.get ${_this}
|
208
|
+
f64.convert_i32_u
|
209
|
+
local.get ${_this+1}
|
210
|
+
local.get ${get}
|
211
|
+
call_indirect 2 0
|
212
|
+
return`;
|
213
|
+
} else {
|
214
|
+
Porffor.wasm`
|
202
215
|
local.get ${get}
|
203
216
|
call_indirect 0 0
|
204
217
|
return`;
|
218
|
+
}
|
205
219
|
}
|
206
220
|
|
207
221
|
// data descriptor
|
@@ -262,11 +276,26 @@ export const __Porffor_object_set = (_this: object, key: any, value: any): any =
|
|
262
276
|
return value;
|
263
277
|
}
|
264
278
|
|
279
|
+
const funcFlags: i32 = Porffor.funcLut.flags(set);
|
280
|
+
if (funcFlags & 0b10) {
|
281
|
+
// constructor func, add new.target, this args
|
282
|
+
Porffor.wasm`
|
283
|
+
f64.const 0
|
284
|
+
i32.const 0
|
285
|
+
local.get ${_this}
|
286
|
+
f64.convert_i32_u
|
287
|
+
i32.const 7
|
288
|
+
local.get ${value}
|
289
|
+
local.get ${value+1}
|
290
|
+
local.get ${set}
|
291
|
+
call_indirect 3 0`;
|
292
|
+
} else {
|
265
293
|
Porffor.wasm`
|
266
294
|
local.get ${value}
|
267
295
|
local.get ${value+1}
|
268
296
|
local.get ${set}
|
269
297
|
call_indirect 1 0`;
|
298
|
+
}
|
270
299
|
|
271
300
|
return value;
|
272
301
|
}
|
package/compiler/builtins.js
CHANGED
@@ -1056,6 +1056,21 @@ export const BuiltinFuncs = function() {
|
|
1056
1056
|
]
|
1057
1057
|
};
|
1058
1058
|
|
1059
|
+
this.__Porffor_funcLut_flags = {
|
1060
|
+
params: [ Valtype.i32 ],
|
1061
|
+
returns: [ Valtype.i32 ],
|
1062
|
+
returnType: TYPES.number,
|
1063
|
+
wasm: (scope, { allocPage }) => [
|
1064
|
+
[ Opcodes.local_get, 0 ],
|
1065
|
+
...number(128, Valtype.i32),
|
1066
|
+
[ Opcodes.i32_mul ],
|
1067
|
+
...number(2, Valtype.i32),
|
1068
|
+
[ Opcodes.i32_add ],
|
1069
|
+
[ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize) ]
|
1070
|
+
],
|
1071
|
+
table: true
|
1072
|
+
};
|
1073
|
+
|
1059
1074
|
this.__Porffor_funcLut_length = {
|
1060
1075
|
params: [ Valtype.i32 ],
|
1061
1076
|
returns: [ Valtype.i32 ],
|