mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +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);
|
condLocals.push(condLocal);
|
||||||
}
|
}
|
||||||
const condRVal = condLocals
|
const condLocal = condLocals
|
||||||
.reduce((condRVal, condLocal) => {
|
.slice(1)
|
||||||
|
.reduce<LocalId>((rightLocal, leftLocal) => {
|
||||||
const local = this.local(Ty({ tag: "int" }));
|
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();
|
return todo();
|
||||||
}
|
}
|
||||||
@ -710,8 +729,34 @@ export class FnLowerer {
|
|||||||
return;
|
return;
|
||||||
case "bool":
|
case "bool":
|
||||||
return;
|
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();
|
return todo();
|
||||||
|
}
|
||||||
case "struct":
|
case "struct":
|
||||||
return todo();
|
return todo();
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,10 @@ export class FnLowerer {
|
|||||||
case "binary":
|
case "binary":
|
||||||
case "unary":
|
case "unary":
|
||||||
return todo();
|
return todo();
|
||||||
case "adt":
|
case "adt": {
|
||||||
|
console.log(rval);
|
||||||
|
return todo();
|
||||||
|
}
|
||||||
case "call":
|
case "call":
|
||||||
case "builtin":
|
case "builtin":
|
||||||
return todo();
|
return todo();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user