porffor 0.41.6 → 0.41.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/assemble.js +13 -14
- package/compiler/builtins/_internal_object.ts +3 -60
- package/compiler/builtins.js +8 -10
- package/compiler/builtins_precompiled.js +313 -310
- package/compiler/codegen.js +143 -224
- package/compiler/precompile.js +20 -22
- package/package.json +1 -1
- package/runner/index.js +2 -2
package/compiler/assemble.js
CHANGED
@@ -132,13 +132,12 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
132
132
|
encodeVector([ [
|
133
133
|
0x00,
|
134
134
|
Opcodes.i32_const, 0, Opcodes.end,
|
135
|
-
...encodeVector(funcs.map(x => unsignedLEB128(x.asmIndex)))
|
135
|
+
...encodeVector(funcs.map(x => unsignedLEB128((x.wrapperFunc ?? x).asmIndex)))
|
136
136
|
] ])
|
137
137
|
);
|
138
138
|
time('element section');
|
139
139
|
|
140
140
|
if (pages.has('func lut')) {
|
141
|
-
const offset = pages.get('func lut').ind * pageSize;
|
142
141
|
if (data.addedFuncArgcLut) {
|
143
142
|
// remove existing data
|
144
143
|
data = data.filter(x => x.page !== 'func lut');
|
@@ -150,17 +149,16 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
150
149
|
const func = funcs[i];
|
151
150
|
let name = func.name;
|
152
151
|
|
153
|
-
// real argc
|
154
|
-
let argc = func.params.length;
|
155
|
-
if (func.constr) argc -= 4;
|
156
|
-
if (!func.internal || func.typedParams) argc = Math.floor(argc / 2);
|
157
|
-
|
158
|
-
bytes.push(argc % 256, (argc / 256 | 0) % 256);
|
159
|
-
|
160
152
|
// userland exposed .length
|
161
|
-
let length = func.jsLength
|
162
|
-
|
163
|
-
|
153
|
+
let length = func.jsLength;
|
154
|
+
if (length == null) {
|
155
|
+
length = func.params.length;
|
156
|
+
if (func.constr) length -= 4;
|
157
|
+
if (!func.internal || func.typedParams) length = Math.floor(length / 2);
|
158
|
+
|
159
|
+
// remove _this from internal prototype funcs
|
160
|
+
if (func.internal && name.includes('_prototype_')) length--;
|
161
|
+
}
|
164
162
|
|
165
163
|
bytes.push(length % 256, (length / 256 | 0) % 256);
|
166
164
|
|
@@ -169,14 +167,15 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
169
167
|
if (func.constr) flags |= 0b10;
|
170
168
|
bytes.push(flags);
|
171
169
|
|
170
|
+
if (name.startsWith('#indirect_')) name = name.slice(10);
|
172
171
|
if (name.startsWith('#')) name = '';
|
173
172
|
|
174
173
|
// eg: __String_prototype_toLowerCase -> toLowerCase
|
175
174
|
if (name.startsWith('__')) name = name.split('_').pop();
|
176
175
|
|
177
|
-
bytes.push(...new Uint8Array(new Int32Array([ name.length ]).buffer));
|
176
|
+
bytes.push(...new Uint8Array(new Int32Array([ Math.min(name.length, 48 - 5 - 4) ]).buffer));
|
178
177
|
|
179
|
-
for (let i = 0; i < (
|
178
|
+
for (let i = 0; i < (48 - 3 - 4); i++) {
|
180
179
|
const c = name.charCodeAt(i);
|
181
180
|
bytes.push((c || 0) % 256);
|
182
181
|
}
|
@@ -280,24 +280,7 @@ i32.const 128
|
|
280
280
|
return`;
|
281
281
|
}
|
282
282
|
|
283
|
-
|
284
|
-
if (funcFlags & 0b10) {
|
285
|
-
// constructor func, add new.target, this args
|
286
|
-
Porffor.wasm`
|
287
|
-
f64.const 0
|
288
|
-
i32.const 0
|
289
|
-
local.get ${obj}
|
290
|
-
f64.convert_i32_u
|
291
|
-
local.get ${obj+1}
|
292
|
-
local.get ${get}
|
293
|
-
call_indirect 2 0
|
294
|
-
return`;
|
295
|
-
} else {
|
296
|
-
Porffor.wasm`
|
297
|
-
local.get ${get}
|
298
|
-
call_indirect 0 0
|
299
|
-
return`;
|
300
|
-
}
|
283
|
+
return get.call(obj);
|
301
284
|
}
|
302
285
|
|
303
286
|
// data descriptor
|
@@ -364,27 +347,7 @@ export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
|
|
364
347
|
return value;
|
365
348
|
}
|
366
349
|
|
367
|
-
|
368
|
-
if (funcFlags & 0b10) {
|
369
|
-
// constructor func, add new.target, this args
|
370
|
-
Porffor.wasm`
|
371
|
-
f64.const 0
|
372
|
-
i32.const 0
|
373
|
-
local.get ${obj}
|
374
|
-
f64.convert_i32_u
|
375
|
-
i32.const 7
|
376
|
-
local.get ${value}
|
377
|
-
local.get ${value+1}
|
378
|
-
local.get ${set}
|
379
|
-
call_indirect 3 0`;
|
380
|
-
} else {
|
381
|
-
Porffor.wasm`
|
382
|
-
local.get ${value}
|
383
|
-
local.get ${value+1}
|
384
|
-
local.get ${set}
|
385
|
-
call_indirect 1 0`;
|
386
|
-
}
|
387
|
-
|
350
|
+
set.call(obj, value);
|
388
351
|
return value;
|
389
352
|
}
|
390
353
|
|
@@ -450,27 +413,7 @@ export const __Porffor_object_setStrict = (obj: any, key: any, value: any): any
|
|
450
413
|
throw new TypeError('Cannot set property with no setter of object');
|
451
414
|
}
|
452
415
|
|
453
|
-
|
454
|
-
if (funcFlags & 0b10) {
|
455
|
-
// constructor func, add new.target, this args
|
456
|
-
Porffor.wasm`
|
457
|
-
f64.const 0
|
458
|
-
i32.const 0
|
459
|
-
local.get ${obj}
|
460
|
-
f64.convert_i32_u
|
461
|
-
i32.const 7
|
462
|
-
local.get ${value}
|
463
|
-
local.get ${value+1}
|
464
|
-
local.get ${set}
|
465
|
-
call_indirect 3 0`;
|
466
|
-
} else {
|
467
|
-
Porffor.wasm`
|
468
|
-
local.get ${value}
|
469
|
-
local.get ${value+1}
|
470
|
-
local.get ${set}
|
471
|
-
call_indirect 1 0`;
|
472
|
-
}
|
473
|
-
|
416
|
+
set.call(obj, value);
|
474
417
|
return value;
|
475
418
|
}
|
476
419
|
|
package/compiler/builtins.js
CHANGED
@@ -1002,32 +1002,30 @@ export const BuiltinFuncs = function() {
|
|
1002
1002
|
]
|
1003
1003
|
};
|
1004
1004
|
|
1005
|
-
this.
|
1005
|
+
this.__Porffor_funcLut_length = {
|
1006
1006
|
params: [ Valtype.i32 ],
|
1007
1007
|
returns: [ Valtype.i32 ],
|
1008
1008
|
returnType: TYPES.number,
|
1009
1009
|
wasm: (scope, { allocPage }) => [
|
1010
1010
|
[ Opcodes.local_get, 0 ],
|
1011
|
-
...number(
|
1011
|
+
...number(48, Valtype.i32),
|
1012
1012
|
[ Opcodes.i32_mul ],
|
1013
|
-
...
|
1014
|
-
[ Opcodes.i32_add ],
|
1015
|
-
[ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut')) ]
|
1013
|
+
[ Opcodes.i32_load16_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut')) ]
|
1016
1014
|
],
|
1017
1015
|
table: true
|
1018
1016
|
};
|
1019
1017
|
|
1020
|
-
this.
|
1018
|
+
this.__Porffor_funcLut_flags = {
|
1021
1019
|
params: [ Valtype.i32 ],
|
1022
1020
|
returns: [ Valtype.i32 ],
|
1023
1021
|
returnType: TYPES.number,
|
1024
1022
|
wasm: (scope, { allocPage }) => [
|
1025
1023
|
[ Opcodes.local_get, 0 ],
|
1026
|
-
...number(
|
1024
|
+
...number(48, Valtype.i32),
|
1027
1025
|
[ Opcodes.i32_mul ],
|
1028
1026
|
...number(2, Valtype.i32),
|
1029
1027
|
[ Opcodes.i32_add ],
|
1030
|
-
[ Opcodes.
|
1028
|
+
[ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut')) ]
|
1031
1029
|
],
|
1032
1030
|
table: true
|
1033
1031
|
};
|
@@ -1038,9 +1036,9 @@ export const BuiltinFuncs = function() {
|
|
1038
1036
|
returnType: TYPES.bytestring,
|
1039
1037
|
wasm: (scope, { allocPage }) => [
|
1040
1038
|
[ Opcodes.local_get, 0 ],
|
1041
|
-
...number(
|
1039
|
+
...number(48, Valtype.i32),
|
1042
1040
|
[ Opcodes.i32_mul ],
|
1043
|
-
...number(
|
1041
|
+
...number(3, Valtype.i32),
|
1044
1042
|
[ Opcodes.i32_add ],
|
1045
1043
|
...number(allocPage(scope, 'func lut'), Valtype.i32),
|
1046
1044
|
[ Opcodes.i32_add ]
|