diff --git a/src/bc_gen.zig b/src/bc_gen.zig index b0974c1b5..b5724c5f4 100644 --- a/src/bc_gen.zig +++ b/src/bc_gen.zig @@ -1132,12 +1132,11 @@ fn genSlice(c: *Chunk, idx: usize, cstr: Cstr, nodeId: cy.NodeId) !GenValue { } var args: [3]GenValue = undefined; - const recIdx = c.ir.advanceExpr(idx, .preSlice); - args[0] = try genExpr(c, recIdx, Cstr.simple); + args[0] = try genExpr(c, data.recLoc, Cstr.simple); try pushUnwindValue(c, args[0]); - args[1] = try genExpr(c, data.left, Cstr.simple); + args[1] = try genExpr(c, data.leftLoc, Cstr.simple); try pushUnwindValue(c, args[1]); - args[2] = try genExpr(c, data.right, Cstr.simple); + args[2] = try genExpr(c, data.rightLoc, Cstr.simple); try pushUnwindValue(c, args[2]); try pushInlineTernExpr(c, .sliceList, args[0].reg, args[1].reg, args[2].reg, inst.dst, nodeId); @@ -2880,8 +2879,7 @@ fn genTryExpr(c: *Chunk, idx: usize, cstr: Cstr, nodeId: cy.NodeId) !GenValue { fn genCondExpr(c: *Chunk, idx: usize, cstr: Cstr, nodeId: cy.NodeId) !GenValue { _ = nodeId; const data = c.ir.getExprData(idx, .condExpr); - const condIdx = c.ir.advanceExpr(idx, .condExpr); - const condNodeId = c.ir.getNode(condIdx); + const condNodeId = c.ir.getNode(data.condLoc); var finalCstr = cstr; if (!finalCstr.isExact()) { @@ -2890,7 +2888,7 @@ fn genCondExpr(c: *Chunk, idx: usize, cstr: Cstr, nodeId: cy.NodeId) !GenValue { } // Cond. - const condv = try genExpr(c, condIdx, Cstr.simple); + const condv = try genExpr(c, data.condLoc, Cstr.simple); const condFalseJump = try c.pushEmptyJumpNotCond(condv.reg); diff --git a/src/ir.zig b/src/ir.zig index bbc639056..9337b3952 100644 --- a/src/ir.zig +++ b/src/ir.zig @@ -190,6 +190,7 @@ pub const Captured = struct { }; pub const CondExpr = struct { + condLoc: Loc, body: u32, elseBody: u32, }; @@ -384,8 +385,9 @@ pub const Prepare = union { pub const Slice = struct { recvT: TypeId, - left: u32, - right: u32, + recLoc: Loc, + leftLoc: Loc, + rightLoc: Loc, }; pub const BinOp = struct { diff --git a/src/sema.zig b/src/sema.zig index 5592f7ef8..08047d0b8 100644 --- a/src/sema.zig +++ b/src/sema.zig @@ -3621,7 +3621,7 @@ pub const ChunkExt = struct { const ifBranch = c.ast.node(node.data.condExpr.ifBranch); - _ = try c.semaExpr(ifBranch.data.ifBranch.cond, .{}); + const cond = try c.semaExpr(ifBranch.data.ifBranch.cond, .{}); const body = try c.semaExpr(ifBranch.data.ifBranch.bodyHead, .{}); var elseBody: ExprResult = undefined; if (node.data.condExpr.elseExpr != cy.NullNode) { @@ -3629,7 +3629,11 @@ pub const ChunkExt = struct { } else { elseBody = try c.semaNone(nodeId); } - c.ir.setExprData(irIdx, .condExpr, .{ .body = body.irIdx, .elseBody = elseBody.irIdx }); + c.ir.setExprData(irIdx, .condExpr, .{ + .condLoc = cond.irIdx, + .body = body.irIdx, + .elseBody = elseBody.irIdx, + }); const dynamic = body.type.dynamic or elseBody.type.dynamic; if (body.type.id == elseBody.type.id) { @@ -3726,8 +3730,9 @@ pub const ChunkExt = struct { c.ir.setExprData(preIdx, .preSlice, .{ .slice = .{ .recvT = recv.type.id, - .left = left.irIdx, - .right = right.irIdx, + .recLoc = recv.irIdx, + .leftLoc = left.irIdx, + .rightLoc = right.irIdx, }, }); return ExprResult.initStatic(preIdx, bt.List);