feature. See also
. The project being documented here (as the example) is the Zig library itself.
AstGen.assignOp
fn assignOp(
gz: *GenZir,
scope: *Scope,
infix_node: Ast.Node.Index,
op_inst_tag: Zir.Inst.Tag,
) InnerError!void
File
Code
fn assignOp(
gz: *GenZir,
scope: *Scope,
infix_node: Ast.Node.Index,
op_inst_tag: Zir.Inst.Tag,
) InnerError!void {
try emitDbgNode(gz, infix_node);
const astgen = gz.astgen;
const tree = astgen.tree;
const lhs_node, const rhs_node = tree.nodeData(infix_node).node_and_node;
const lhs_ptr = try lvalExpr(gz, scope, lhs_node);
const cursor = switch (op_inst_tag) {
.add, .sub, .mul, .div, .mod_rem => maybeAdvanceSourceCursorToMainToken(gz, infix_node),
else => undefined,
};
const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node);
const rhs_res_ty = switch (op_inst_tag) {
.add,
.sub,
=> try gz.add(.{
.tag = .extended,
.data = .{ .extended = .{
.opcode = .inplace_arith_result_ty,
.small = @backingInt(@as(Zir.Inst.InplaceOp, switch (op_inst_tag) {
.add => .add_eq,
.sub => .sub_eq,
else => unreachable,
})),
.operand = @backingInt(lhs),
} },
}),
else => try gz.addUnNode(.typeof, lhs, infix_node),
};
const rhs = try expr(gz, scope, .{ .rl = .{ .ty = rhs_res_ty } }, rhs_node);
switch (op_inst_tag) {
.add, .sub, .mul, .div, .mod_rem => {
try emitDbgStmt(gz, cursor);
},
else => {},
}
const result = try gz.addPlNode(op_inst_tag, infix_node, Zir.Inst.Bin{
.lhs = lhs,
.rhs = rhs,
});
_ = try gz.addPlNode(.store_node, infix_node, Zir.Inst.Bin{
.lhs = lhs_ptr,
.rhs = result,
});
}