porffor 0.50.19 → 0.50.20
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 +0 -1
- package/compiler/builtins.js +0 -6
- package/compiler/builtins_precompiled.js +443 -443
- package/compiler/codegen.js +47 -18
- package/compiler/wrap.js +0 -3
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -305,7 +305,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
305
305
|
|
306
306
|
case 'DebuggerStatement':
|
307
307
|
return cacheAst(decl, [
|
308
|
-
[ Opcodes.call, importedFuncs.debugger ],
|
308
|
+
// [ Opcodes.call, importedFuncs.debugger ],
|
309
309
|
number(UNDEFINED)
|
310
310
|
]);
|
311
311
|
|
@@ -332,7 +332,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
332
332
|
return cacheAst(decl, generateTemplate(scope, decl));
|
333
333
|
|
334
334
|
case 'TaggedTemplateExpression':
|
335
|
-
return cacheAst(decl, generateTaggedTemplate(scope, decl, global, name));
|
335
|
+
return cacheAst(decl, generateTaggedTemplate(scope, decl, global, name, valueUnused));
|
336
336
|
|
337
337
|
case 'ExportNamedDeclaration':
|
338
338
|
if (!decl.declaration) return todo(scope, 'unsupported export declaration', true);
|
@@ -2438,26 +2438,26 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2438
2438
|
// pointer, align, offset
|
2439
2439
|
i32_load: { imms: 2, args: [ true ], returns: 1 },
|
2440
2440
|
// pointer, value, align, offset
|
2441
|
-
i32_store: { imms: 2, args: [ true, true ], returns: 0 },
|
2441
|
+
i32_store: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
|
2442
2442
|
// pointer, align, offset
|
2443
2443
|
i32_load8_u: { imms: 2, args: [ true ], returns: 1 },
|
2444
2444
|
// pointer, value, align, offset
|
2445
|
-
i32_store8: { imms: 2, args: [ true, true ], returns: 0 },
|
2445
|
+
i32_store8: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
|
2446
2446
|
// pointer, align, offset
|
2447
2447
|
i32_load16_u: { imms: 2, args: [ true ], returns: 1 },
|
2448
2448
|
// pointer, value, align, offset
|
2449
|
-
i32_store16: { imms: 2, args: [ true, true ], returns: 0 },
|
2449
|
+
i32_store16: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
|
2450
2450
|
|
2451
2451
|
// pointer, align, offset
|
2452
2452
|
f64_load: { imms: 2, args: [ true ], returns: 0 }, // 0 due to not i32
|
2453
2453
|
// pointer, value, align, offset
|
2454
|
-
f64_store: { imms: 2, args: [ true, false ], returns: 0 },
|
2454
|
+
f64_store: { imms: 2, args: [ true, false ], returns: 0, addValue: true },
|
2455
2455
|
|
2456
2456
|
// value
|
2457
2457
|
i32_const: { imms: 1, args: [], returns: 0 },
|
2458
2458
|
|
2459
2459
|
// dst, src, size, _, _
|
2460
|
-
memory_copy: { imms: 2, args: [ true, true, true ], returns: 0 }
|
2460
|
+
memory_copy: { imms: 2, args: [ true, true, true ], returns: 0, addValue: true }
|
2461
2461
|
};
|
2462
2462
|
|
2463
2463
|
const opName = name.slice('__Porffor_wasm_'.length);
|
@@ -2486,7 +2486,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2486
2486
|
return [
|
2487
2487
|
...argOut,
|
2488
2488
|
[ ...opcode, ...imms ],
|
2489
|
-
...(new Array(op.returns).fill(Opcodes.i32_from))
|
2489
|
+
...(new Array(op.returns).fill(Opcodes.i32_from)),
|
2490
|
+
...(op.addValue ? [ number(UNDEFINED) ] : [])
|
2490
2491
|
];
|
2491
2492
|
}
|
2492
2493
|
} else {
|
@@ -2689,6 +2690,11 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2689
2690
|
out.push(Opcodes.i32_trunc_sat_f64_s);
|
2690
2691
|
}
|
2691
2692
|
|
2693
|
+
if ((builtinFuncs[name] && builtinFuncs[name].returns?.length === 0) ||
|
2694
|
+
(importedFuncs[name] != null && importedFuncs[importedFuncs[name]]?.returns === 0)) {
|
2695
|
+
out.push(number(UNDEFINED));
|
2696
|
+
}
|
2697
|
+
|
2692
2698
|
return out;
|
2693
2699
|
};
|
2694
2700
|
|
@@ -3049,15 +3055,18 @@ const typeIsNotOneOf = (type, types, valtype = Valtype.i32) => {
|
|
3049
3055
|
return out;
|
3050
3056
|
};
|
3051
3057
|
|
3052
|
-
const allocVar = (scope, name, global = false, type = true) => {
|
3058
|
+
const allocVar = (scope, name, global = false, type = true, redecl = false) => {
|
3053
3059
|
const target = global ? globals : scope.locals;
|
3054
3060
|
|
3055
3061
|
// already declared
|
3056
3062
|
if (Object.hasOwn(target, name)) {
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3063
|
+
if (redecl) {
|
3064
|
+
// force change old local name(s)
|
3065
|
+
target['#redecl_' + name + uniqId()] = target[name];
|
3066
|
+
if (type) target['#redecl_' + name + '#type' + uniqId()] = target[name + '#type'];
|
3067
|
+
} else {
|
3068
|
+
return target[name].idx;
|
3069
|
+
}
|
3061
3070
|
}
|
3062
3071
|
|
3063
3072
|
let idx = global ? globals['#ind']++ : scope.localInd++;
|
@@ -4300,7 +4309,10 @@ const inferLoopEnd = scope => {
|
|
4300
4309
|
const generateIf = (scope, decl) => {
|
4301
4310
|
if (globalThis.precompile && decl.test?.tag?.name === '__Porffor_comptime_flag') {
|
4302
4311
|
const flag = decl.test.quasi.quasis[0].value.raw;
|
4303
|
-
return [
|
4312
|
+
return [
|
4313
|
+
[ null, 'comptime_flag', flag, decl.consequent, '#', Prefs ],
|
4314
|
+
number(UNDEFINED)
|
4315
|
+
];
|
4304
4316
|
}
|
4305
4317
|
|
4306
4318
|
const out = truthy(scope, generate(scope, decl.test), getNodeType(scope, decl.test), false, true);
|
@@ -5148,7 +5160,19 @@ const generateLabel = (scope, decl) => {
|
|
5148
5160
|
const name = decl.label.name;
|
5149
5161
|
scope.labels.set(name, depth.length);
|
5150
5162
|
|
5151
|
-
|
5163
|
+
const out = generate(scope, decl.body);
|
5164
|
+
|
5165
|
+
// if block statement, wrap in block to allow for breaking
|
5166
|
+
if (decl.body.type === 'BlockStatement') {
|
5167
|
+
out.unshift([ Opcodes.block, Blocktype.void ]);
|
5168
|
+
out.push(
|
5169
|
+
[ Opcodes.drop ],
|
5170
|
+
[ Opcodes.end ],
|
5171
|
+
number(UNDEFINED)
|
5172
|
+
);
|
5173
|
+
}
|
5174
|
+
|
5175
|
+
return out;
|
5152
5176
|
};
|
5153
5177
|
|
5154
5178
|
const ensureTag = (exceptionMode = Prefs.exceptionMode ?? 'stack') => {
|
@@ -6260,7 +6284,7 @@ export const generateTemplate = (scope, decl) => {
|
|
6260
6284
|
return generate(scope, current);
|
6261
6285
|
};
|
6262
6286
|
|
6263
|
-
const generateTaggedTemplate = (scope, decl, global = false, name = undefined) => {
|
6287
|
+
const generateTaggedTemplate = (scope, decl, global = false, name = undefined, valueUnused = false) => {
|
6264
6288
|
const intrinsics = {
|
6265
6289
|
__Porffor_wasm: str => {
|
6266
6290
|
let out = [];
|
@@ -6307,6 +6331,11 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined) =
|
|
6307
6331
|
out.push([ ...inst, ...immediates.flatMap(x => encodeFunc(x)) ]);
|
6308
6332
|
}
|
6309
6333
|
|
6334
|
+
// add value to stack if value unused as 99% typically means
|
6335
|
+
// no value on stack at end of wasm
|
6336
|
+
// unless final op is return
|
6337
|
+
if (valueUnused && out.at(-1)[0] !== Opcodes.return) out.push(number(UNDEFINED));
|
6338
|
+
|
6310
6339
|
return out;
|
6311
6340
|
},
|
6312
6341
|
|
@@ -6489,7 +6518,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6489
6518
|
const { name, def, destr, type } = args[i];
|
6490
6519
|
|
6491
6520
|
func.localInd = i * 2;
|
6492
|
-
allocVar(func, name, false);
|
6521
|
+
allocVar(func, name, false, true, true);
|
6493
6522
|
|
6494
6523
|
func.localInd = localInd;
|
6495
6524
|
if (type) {
|
@@ -7034,4 +7063,4 @@ export default program => {
|
|
7034
7063
|
delete globals['#ind'];
|
7035
7064
|
|
7036
7065
|
return { funcs, globals, tags, exceptions, pages, data };
|
7037
|
-
};
|
7066
|
+
};
|
package/compiler/wrap.js
CHANGED
package/package.json
CHANGED