authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-19 15:19:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-19 15:19:47-07:00
log81a935aef81cac9e8c20ad6351290b8a56a7cf65
tree5e81608e6c6929247b12e147d07d508e25a40111
parent132df14ee17f9fa19aa29bcbd10b61cb339b1340

stage2: fix some math oopsies and typos


1 files changed, 18 insertions(+), 20 deletions(-)

src/Module.zig+18-20
......@@ -1007,7 +1007,7 @@ pub const Scope = struct {
10071007 return gz.zir_code.decl.tokSrcLoc(token_index);
10081008 }
10091009
1010 pub fn addFnTypeCc(gz: *GenZir, args: struct {
1010 pub fn addFnTypeCc(gz: *GenZir, tag: zir.Inst.Tag, args: struct {
10111011 param_types: []const zir.Inst.Ref,
10121012 ret_ty: zir.Inst.Ref,
10131013 cc: zir.Inst.Ref,
......@@ -1026,24 +1026,24 @@ pub const Scope = struct {
10261026 }) catch unreachable; // Capacity is ensured above.
10271027 gz.zir_code.extra.appendSliceAssumeCapacity(args.param_types);
10281028
1029 const new_index = gz.zir_code.instructions.len;
1029 const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len);
10301030 gz.zir_code.instructions.appendAssumeCapacity(.{
1031 .tag = .fn_type_cc,
1031 .tag = tag,
10321032 .data = .{ .fn_type = .{
10331033 .return_type = args.ret_ty,
10341034 .payload_index = payload_index,
10351035 } },
10361036 });
1037 const result = @intCast(zir.Inst.Ref, new_index + gz.zir_code.ref_start_index);
1038 gz.instructions.appendAssumeCapacity(result);
1039 return result;
1037 gz.instructions.appendAssumeCapacity(new_index);
1038 return new_index + gz.zir_code.ref_start_index;
10401039 }
10411040
10421041 pub fn addFnType(
10431042 gz: *GenZir,
1043 tag: zir.Inst.Tag,
10441044 ret_ty: zir.Inst.Ref,
10451045 param_types: []const zir.Inst.Ref,
1046 ) !zir.Inst.Index {
1046 ) !zir.Inst.Ref {
10471047 assert(ret_ty != 0);
10481048 const gpa = gz.zir_code.gpa;
10491049 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
......@@ -1056,20 +1056,19 @@ pub const Scope = struct {
10561056 }) catch unreachable; // Capacity is ensured above.
10571057 gz.zir_code.extra.appendSliceAssumeCapacity(param_types);
10581058
1059 const new_index = gz.zir_code.instructions.len;
1059 const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len);
10601060 gz.zir_code.instructions.appendAssumeCapacity(.{
1061 .tag = .fn_type_cc,
1061 .tag = tag,
10621062 .data = .{ .fn_type = .{
10631063 .return_type = ret_ty,
10641064 .payload_index = payload_index,
10651065 } },
10661066 });
1067 const result = @intCast(zir.Inst.Ref, new_index + gz.zir_code.ref_start_index);
1068 gz.instructions.appendAssumeCapacity(result);
1069 return result;
1067 gz.instructions.appendAssumeCapacity(new_index);
1068 return new_index + gz.zir_code.ref_start_index;
10701069 }
10711070
1072 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Index {
1071 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Ref {
10731072 return gz.add(.{
10741073 .tag = .int,
10751074 .data = .{ .int = integer },
......@@ -1171,11 +1170,10 @@ pub const Scope = struct {
11711170 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
11721171 try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1);
11731172
1174 const new_index = gz.zir_code.instructions.len;
1173 const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len);
11751174 gz.zir_code.instructions.appendAssumeCapacity(inst);
1176 const result = @intCast(zir.Inst.Ref, new_index + gz.zir_code.ref_start_index);
1177 gz.instructions.appendAssumeCapacity(result);
1178 return result;
1175 gz.instructions.appendAssumeCapacity(new_index);
1176 return new_index + gz.zir_code.ref_start_index;
11791177 }
11801178 };
11811179
......@@ -1232,7 +1230,7 @@ pub const WipZirCode = struct {
12321230 extra: std.ArrayListUnmanaged(u32) = .{},
12331231 /// The end of special indexes. `zir.Inst.Ref` subtracts against this number to convert
12341232 /// to `zir.Inst.Index`. The default here is correct if there are 0 parameters.
1235 ref_start_index: usize = zir.const_inst_list.len,
1233 ref_start_index: u32 = zir.const_inst_list.len,
12361234 decl: *Decl,
12371235 gpa: *Allocator,
12381236 arena: *Allocator,
......@@ -2034,14 +2032,14 @@ fn astgenAndSemaFn(
20342032
20352033 const fn_type_inst: zir.Inst.Ref = if (cc != 0) fn_type: {
20362034 const tag: zir.Inst.Tag = if (is_var_args) .fn_type_cc_var_args else .fn_type_cc;
2037 break :fn_type try fn_type_scope.addFnTypeCc(.{
2035 break :fn_type try fn_type_scope.addFnTypeCc(tag, .{
20382036 .ret_ty = return_type_inst,
20392037 .param_types = param_types,
20402038 .cc = cc,
20412039 });
20422040 } else fn_type: {
20432041 const tag: zir.Inst.Tag = if (is_var_args) .fn_type_var_args else .fn_type;
2044 break :fn_type try fn_type_scope.addFnType(return_type_inst, param_types);
2042 break :fn_type try fn_type_scope.addFnType(tag, return_type_inst, param_types);
20452043 };
20462044
20472045 // We need the memory for the Type to go into the arena for the Decl