compiler: compile match exprs

This commit is contained in:
SimonFJ20 2025-03-24 12:27:26 +01:00
parent 8726468c55
commit ece66bd2b8
2 changed files with 53 additions and 5 deletions

View File

@ -675,10 +675,29 @@ export class FnLowerer {
});
condLocals.push(condLocal);
}
const condRVal = condLocals
.reduce((condRVal, condLocal) => {
const condLocal = condLocals
.slice(1)
.reduce<LocalId>((rightLocal, leftLocal) => {
const local = this.local(Ty({ tag: "int" }));
});
this.addStmt({
tag: "assign",
place: { local, proj: [] },
rval: {
tag: "binary",
binaryType: "and",
left: {
tag: "copy",
place: { local: leftLocal, proj: [] },
},
right: {
tag: "copy",
place: { local: rightLocal, proj: [] },
},
},
});
return local;
}, condLocals[0]);
return this.copyOrMoveLocal(condLocal, Ty({ tag: "int" }));
}
return todo();
}
@ -710,8 +729,34 @@ export class FnLowerer {
return;
case "bool":
return;
case "tuple":
case "tuple": {
const ty = this.ch.patTy(pat);
if (ty.kind.tag === "struct") {
const discrLocal = this.local(ty);
this.addStmt({
tag: "assign",
place: { local: discrLocal, proj: [] },
rval: discr,
});
for (const [fieldIdx, pat] of k.elems.entries()) {
if (ty.kind.data.tag !== "tuple") {
throw new Error();
}
this.lowerMatchArmPatternBindings({
tag: "use",
operand: {
tag: "move",
place: {
local: discrLocal,
proj: [{ tag: "field", fieldIdx }],
},
},
}, pat);
}
return;
}
return todo();
}
case "struct":
return todo();
}

View File

@ -178,7 +178,10 @@ export class FnLowerer {
case "binary":
case "unary":
return todo();
case "adt":
case "adt": {
console.log(rval);
return todo();
}
case "call":
case "builtin":
return todo();