fn addParam(
gz: *GenZir,
param_gz: *GenZir,
/// Previous parameters, which might be referenced in `param_gz` (the new parameter type).
/// `ref`s of these instructions will be put into this param's type body, and removed from `AstGen.ref_table`.
prev_param_insts: []const Zir.Inst.Index,
ty_is_generic: bool,
tag: Zir.Inst.Tag,
/// Absolute token index. This function does the conversion to Decl offset.
abs_tok_index: Ast.TokenIndex,
name: Zir.NullTerminatedString,
) !Zir.Inst.Index gz: *GenZirparam_gz: *GenZirprev_param_insts: []const Zir.Inst.IndexPrevious parameters, which might be referenced in param_gz (the new parameter type). refs of these instructions will be put into this param's type body, and removed from AstGen.ref_table.
ty_is_generic: booltag: Zir.Inst.Tagabs_tok_index: Ast.TokenIndexAbsolute token index. This function does the conversion to Decl offset.
name: Zir.NullTerminatedString11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870 fn addParam(
gz: *GenZir,
param_gz: *GenZir,
/// Previous parameters, which might be referenced in `param_gz` (the new parameter type).
/// `ref`s of these instructions will be put into this param's type body, and removed from `AstGen.ref_table`.
prev_param_insts: []const Zir.Inst.Index,
ty_is_generic: bool,
tag: Zir.Inst.Tag,
/// Absolute token index. This function does the conversion to Decl offset.
abs_tok_index: Ast.TokenIndex,
name: Zir.NullTerminatedString,
) !Zir.Inst.Index {
const gpa = gz.astgen.gpa;
const param_body = param_gz.instructionsSlice();
const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(param_body, prev_param_insts);
try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).@"struct".field_names.len + body_len);
const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
.name = name,
.type = .{
.body_len = @intCast(body_len),
.is_generic = ty_is_generic,
},
});
gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, param_body, prev_param_insts);
param_gz.unstack();
const new_index: Zir.Inst.Index = @fromBackingInt(@intCast(gz.astgen.instructions.len));
gz.astgen.instructions.appendAssumeCapacity(.{
.tag = tag,
.data = .{ .pl_tok = .{
.src_tok = gz.tokenIndexToRelative(abs_tok_index),
.payload_index = payload_index,
} },
});
gz.instructions.appendAssumeCapacity(new_index);
return new_index;
}
Supports
param_gzstacked ongz. Assumes nothing stacked onparam_gz. Unstacksparam_gz.