mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 00:14:06 +02:00
compiler: compile match exprs
This commit is contained in:
parent
8726468c55
commit
ece66bd2b8
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user