diff --git a/slige/compiler/middle/ast_lower.ts b/slige/compiler/middle/ast_lower.ts index 31373ce..09c6b46 100644 --- a/slige/compiler/middle/ast_lower.ts +++ b/slige/compiler/middle/ast_lower.ts @@ -675,10 +675,29 @@ export class FnLowerer { }); condLocals.push(condLocal); } - const condRVal = condLocals - .reduce((condRVal, condLocal) => { + const condLocal = condLocals + .slice(1) + .reduce((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(); } diff --git a/slige/compiler/middle/mir_lower.ts b/slige/compiler/middle/mir_lower.ts index ed9d276..f4f0574 100644 --- a/slige/compiler/middle/mir_lower.ts +++ b/slige/compiler/middle/mir_lower.ts @@ -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();