Skip to content

Commit

Permalink
Fix bcgen.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Feb 11, 2024
1 parent 5385b94 commit 2818639
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/bc_gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions src/ir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub const Captured = struct {
};

pub const CondExpr = struct {
condLoc: Loc,
body: u32,
elseBody: u32,
};
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 9 additions & 4 deletions src/sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3621,15 +3621,19 @@ 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) {
elseBody = try c.semaExpr(node.data.condExpr.elseExpr, .{});
} 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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2818639

Please sign in to comment.