porffor 0.58.12 → 0.58.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 +5 -3
- package/compiler/builtins/console.ts +6 -1
- package/compiler/builtins/regexp.ts +427 -45
- package/compiler/builtins.js +15 -9
- package/compiler/builtins_precompiled.js +388 -351
- package/compiler/codegen.js +38 -26
- package/compiler/wrap.js +2 -2
- package/foo.js +4 -0
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -1370,7 +1370,7 @@ const generateBinaryExp = (scope, decl) => {
|
|
1370
1370
|
};
|
1371
1371
|
|
1372
1372
|
const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
1373
|
-
Valtype, Opcodes, TYPES, TYPE_NAMES, usedTypes, typeSwitch, makeString, internalThrow,
|
1373
|
+
Valtype, Opcodes, TYPES, TYPE_NAMES, usedTypes, typeSwitch, makeString, internalThrow, funcs,
|
1374
1374
|
getNodeType, generate, generateIdent,
|
1375
1375
|
builtin: (name, offset = false) => {
|
1376
1376
|
let idx = importedFuncs[name] ?? includeBuiltin(scope, name)?.index;
|
@@ -1442,7 +1442,13 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
|
|
1442
1442
|
wasm.push(Opcodes.i32_to_u);
|
1443
1443
|
return wasm;
|
1444
1444
|
},
|
1445
|
-
allocPage: (scope, name) => allocPage({ scope, pages }, name)
|
1445
|
+
allocPage: (scope, name) => allocPage({ scope, pages }, name),
|
1446
|
+
allocLargePage: (scope, name) => {
|
1447
|
+
const _ = allocPage({ scope, pages }, name);
|
1448
|
+
allocPage({ scope, pages }, name + '#2');
|
1449
|
+
|
1450
|
+
return _;
|
1451
|
+
}
|
1446
1452
|
}, extra);
|
1447
1453
|
|
1448
1454
|
const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globalInits = {}, returns = [], returnType, localNames = [], globalNames = [], table = false, constr = false, hasRestArgument = false, usesTag = false, usesImports = false, returnTypes } = {}) => {
|
@@ -2495,6 +2501,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2495
2501
|
i32_store8: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
|
2496
2502
|
// pointer, align, offset
|
2497
2503
|
i32_load16_u: { imms: 2, args: [ true ], returns: 1 },
|
2504
|
+
// pointer, align, offset
|
2505
|
+
i32_load16_s: { imms: 2, args: [ true ], returns: 1 },
|
2498
2506
|
// pointer, value, align, offset
|
2499
2507
|
i32_store16: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
|
2500
2508
|
|
@@ -2514,35 +2522,34 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2514
2522
|
};
|
2515
2523
|
|
2516
2524
|
const opName = name.slice('__Porffor_wasm_'.length);
|
2525
|
+
if (!wasmOps[opName]) throw new Error('Unimplemented Porffor.wasm op: ' + opName);
|
2517
2526
|
|
2518
|
-
|
2519
|
-
const op = wasmOps[opName];
|
2527
|
+
const op = wasmOps[opName];
|
2520
2528
|
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2529
|
+
const argOut = [];
|
2530
|
+
for (let i = 0; i < op.args.length; i++) {
|
2531
|
+
if (!op.args[i]) globalThis.noi32F64CallConv = true;
|
2524
2532
|
|
2525
|
-
|
2526
|
-
|
2527
|
-
|
2528
|
-
|
2533
|
+
argOut.push(
|
2534
|
+
...generate(scope, decl.arguments[i]),
|
2535
|
+
...(op.args[i] ? [ Opcodes.i32_to ] : [])
|
2536
|
+
);
|
2529
2537
|
|
2530
|
-
|
2531
|
-
|
2538
|
+
globalThis.noi32F64CallConv = false;
|
2539
|
+
}
|
2532
2540
|
|
2533
|
-
|
2534
|
-
|
2541
|
+
// literals only
|
2542
|
+
const imms = decl.arguments.slice(op.args.length).map(x => x.value);
|
2535
2543
|
|
2536
|
-
|
2537
|
-
|
2544
|
+
let opcode = Opcodes[opName];
|
2545
|
+
if (!Array.isArray(opcode)) opcode = [ opcode ];
|
2538
2546
|
|
2539
|
-
|
2540
|
-
|
2541
|
-
|
2542
|
-
|
2543
|
-
|
2544
|
-
|
2545
|
-
}
|
2547
|
+
return [
|
2548
|
+
...argOut,
|
2549
|
+
[ ...opcode, ...imms ],
|
2550
|
+
...(new Array(op.returns).fill(Opcodes.i32_from)),
|
2551
|
+
...(op.addValue ? [ number(UNDEFINED) ] : [])
|
2552
|
+
];
|
2546
2553
|
} else {
|
2547
2554
|
if (!Prefs.indirectCalls) return internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, true);
|
2548
2555
|
|
@@ -4145,6 +4152,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
4145
4152
|
]),
|
4146
4153
|
...setLastType(scope)
|
4147
4154
|
], generate(scope, decl.right), getLastType(scope), getNodeType(scope, decl.right))),
|
4155
|
+
...(valtypeBinary === Valtype.i32 ? [ [ Opcodes.f64_convert_i32_s ] ] : []),
|
4148
4156
|
...getNodeType(scope, decl),
|
4149
4157
|
|
4150
4158
|
...(hash != null ? [
|
@@ -6195,8 +6203,8 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
6195
6203
|
] : [
|
6196
6204
|
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ]
|
6197
6205
|
]),
|
6198
|
-
|
6199
|
-
...
|
6206
|
+
...setLastType(scope),
|
6207
|
+
...(valtypeBinary === Valtype.i32 ? [ Opcodes.i32_trunc_sat_f64_s ] : [])
|
6200
6208
|
],
|
6201
6209
|
|
6202
6210
|
...extraBC
|
@@ -7282,6 +7290,10 @@ export default program => {
|
|
7282
7290
|
tags = [];
|
7283
7291
|
exceptions = [];
|
7284
7292
|
funcs = []; indirectFuncs = [];
|
7293
|
+
funcs.bytesPerFuncLut = () => {
|
7294
|
+
return indirectFuncs._bytesPerFuncLut ??=
|
7295
|
+
Math.min(Math.floor((pageSize * 2) / indirectFuncs.length), indirectFuncs.reduce((acc, x) => x.name.length > acc ? x.name.length : acc, 0) + 8);
|
7296
|
+
};
|
7285
7297
|
funcIndex = {};
|
7286
7298
|
depth = [];
|
7287
7299
|
pages = new Map();
|
package/compiler/wrap.js
CHANGED
@@ -351,7 +351,7 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
351
351
|
const [ flags ] = read(Uint16Array, memory, value + 4, 1);
|
352
352
|
|
353
353
|
if (Prefs.d) {
|
354
|
-
const bc = new Uint8Array(memory.buffer.slice(value +
|
354
|
+
const bc = new Uint8Array(memory.buffer.slice(value + 10));
|
355
355
|
let i = 0;
|
356
356
|
while (true) {
|
357
357
|
const opcode = bc[i++];
|
@@ -449,7 +449,7 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
449
449
|
case 0x30:
|
450
450
|
case 0x31: {
|
451
451
|
const index = bc[i++];
|
452
|
-
console.log(
|
452
|
+
console.log(`\x1b[2m${opcode === 0x30 ? 'start' : 'end'} capture ${index}\x1b[0m`);
|
453
453
|
break;
|
454
454
|
}
|
455
455
|
}
|
package/foo.js
ADDED
package/package.json
CHANGED