mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-14 16:35:03 +01:00
make codegen smarter around !
This commit is contained in:
parent
1dad80f4c1
commit
0c996eb9bc
2 changed files with 15 additions and 7 deletions
|
|
@ -12,7 +12,7 @@ import { exec } from "child_process";
|
|||
const input = `
|
||||
function main() = (
|
||||
let i = 0;
|
||||
loop break;
|
||||
|
||||
loop (
|
||||
if i > 10 then break;
|
||||
|
||||
|
|
|
|||
20
src/lower.ts
20
src/lower.ts
|
|
@ -577,10 +577,14 @@ function lowerExpr(fcx: FuncContext, instrs: wasm.Instr[], expr: Expr) {
|
|||
fcx.currentBlockDepth += 2;
|
||||
const bodyInstrs: wasm.Instr[] = [];
|
||||
lowerExpr(fcx, bodyInstrs, expr.body);
|
||||
bodyInstrs.push({
|
||||
kind: "br",
|
||||
label: /*innermost control structure, the loop*/ 0,
|
||||
});
|
||||
|
||||
// For diverging bodies, we don't need to bother creating the back edge.
|
||||
if (expr.body.ty!.kind !== "never") {
|
||||
bodyInstrs.push({
|
||||
kind: "br",
|
||||
label: /*innermost control structure, the loop*/ 0,
|
||||
});
|
||||
}
|
||||
fcx.currentBlockDepth -= 2;
|
||||
|
||||
outerBlockInstrs.push({
|
||||
|
|
@ -633,11 +637,15 @@ function lowerExprBlockBody(
|
|||
const headExprs = expr.exprs.slice(0, -1);
|
||||
const tailExpr = expr.exprs[expr.exprs.length - 1];
|
||||
|
||||
headExprs.forEach((inner) => {
|
||||
for (const inner of headExprs) {
|
||||
lowerExpr(fcx, innerInstrs, inner);
|
||||
if (inner.ty!.kind === "never") {
|
||||
// The rest of the block is unreachable, so we don't bother codegening it.
|
||||
break;
|
||||
}
|
||||
const types = wasmTypeForBody(inner.ty!);
|
||||
types.forEach(() => innerInstrs.push({ kind: "drop" }));
|
||||
});
|
||||
}
|
||||
|
||||
lowerExpr(fcx, innerInstrs, tailExpr);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue