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 {...@@ -1007,7 +1007,7 @@ pub const Scope = struct {
1007 return gz.zir_code.decl.tokSrcLoc(token_index);1007 return gz.zir_code.decl.tokSrcLoc(token_index);
1008 }1008 }
10091009
1010 pub fn addFnTypeCc(gz: *GenZir, args: struct {1010 pub fn addFnTypeCc(gz: *GenZir, tag: zir.Inst.Tag, args: struct {
1011 param_types: []const zir.Inst.Ref,1011 param_types: []const zir.Inst.Ref,
1012 ret_ty: zir.Inst.Ref,1012 ret_ty: zir.Inst.Ref,
1013 cc: zir.Inst.Ref,1013 cc: zir.Inst.Ref,
...@@ -1026,24 +1026,24 @@ pub const Scope = struct {...@@ -1026,24 +1026,24 @@ pub const Scope = struct {
1026 }) catch unreachable; // Capacity is ensured above.1026 }) catch unreachable; // Capacity is ensured above.
1027 gz.zir_code.extra.appendSliceAssumeCapacity(args.param_types);1027 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);
1030 gz.zir_code.instructions.appendAssumeCapacity(.{1030 gz.zir_code.instructions.appendAssumeCapacity(.{
1031 .tag = .fn_type_cc,1031 .tag = tag,
1032 .data = .{ .fn_type = .{1032 .data = .{ .fn_type = .{
1033 .return_type = args.ret_ty,1033 .return_type = args.ret_ty,
1034 .payload_index = payload_index,1034 .payload_index = payload_index,
1035 } },1035 } },
1036 });1036 });
1037 const result = @intCast(zir.Inst.Ref, new_index + gz.zir_code.ref_start_index);1037 gz.instructions.appendAssumeCapacity(new_index);
1038 gz.instructions.appendAssumeCapacity(result);1038 return new_index + gz.zir_code.ref_start_index;
1039 return result;
1040 }1039 }
10411040
1042 pub fn addFnType(1041 pub fn addFnType(
1043 gz: *GenZir,1042 gz: *GenZir,
1043 tag: zir.Inst.Tag,
1044 ret_ty: zir.Inst.Ref,1044 ret_ty: zir.Inst.Ref,
1045 param_types: []const zir.Inst.Ref,1045 param_types: []const zir.Inst.Ref,
1046 ) !zir.Inst.Index {1046 ) !zir.Inst.Ref {
1047 assert(ret_ty != 0);1047 assert(ret_ty != 0);
1048 const gpa = gz.zir_code.gpa;1048 const gpa = gz.zir_code.gpa;
1049 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1049 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
...@@ -1056,20 +1056,19 @@ pub const Scope = struct {...@@ -1056,20 +1056,19 @@ pub const Scope = struct {
1056 }) catch unreachable; // Capacity is ensured above.1056 }) catch unreachable; // Capacity is ensured above.
1057 gz.zir_code.extra.appendSliceAssumeCapacity(param_types);1057 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);
1060 gz.zir_code.instructions.appendAssumeCapacity(.{1060 gz.zir_code.instructions.appendAssumeCapacity(.{
1061 .tag = .fn_type_cc,1061 .tag = tag,
1062 .data = .{ .fn_type = .{1062 .data = .{ .fn_type = .{
1063 .return_type = ret_ty,1063 .return_type = ret_ty,
1064 .payload_index = payload_index,1064 .payload_index = payload_index,
1065 } },1065 } },
1066 });1066 });
1067 const result = @intCast(zir.Inst.Ref, new_index + gz.zir_code.ref_start_index);1067 gz.instructions.appendAssumeCapacity(new_index);
1068 gz.instructions.appendAssumeCapacity(result);1068 return new_index + gz.zir_code.ref_start_index;
1069 return result;
1070 }1069 }
10711070
1072 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Index {1071 pub fn addInt(gz: *GenZir, integer: u64) !zir.Inst.Ref {
1073 return gz.add(.{1072 return gz.add(.{
1074 .tag = .int,1073 .tag = .int,
1075 .data = .{ .int = integer },1074 .data = .{ .int = integer },
...@@ -1171,11 +1170,10 @@ pub const Scope = struct {...@@ -1171,11 +1170,10 @@ pub const Scope = struct {
1171 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);1170 try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1);
1172 try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1);1171 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);
1175 gz.zir_code.instructions.appendAssumeCapacity(inst);1174 gz.zir_code.instructions.appendAssumeCapacity(inst);
1176 const result = @intCast(zir.Inst.Ref, new_index + gz.zir_code.ref_start_index);1175 gz.instructions.appendAssumeCapacity(new_index);
1177 gz.instructions.appendAssumeCapacity(result);1176 return new_index + gz.zir_code.ref_start_index;
1178 return result;
1179 }1177 }
1180 };1178 };
11811179
...@@ -1232,7 +1230,7 @@ pub const WipZirCode = struct {...@@ -1232,7 +1230,7 @@ pub const WipZirCode = struct {
1232 extra: std.ArrayListUnmanaged(u32) = .{},1230 extra: std.ArrayListUnmanaged(u32) = .{},
1233 /// The end of special indexes. `zir.Inst.Ref` subtracts against this number to convert1231 /// The end of special indexes. `zir.Inst.Ref` subtracts against this number to convert
1234 /// to `zir.Inst.Index`. The default here is correct if there are 0 parameters.1232 /// 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,
1236 decl: *Decl,1234 decl: *Decl,
1237 gpa: *Allocator,1235 gpa: *Allocator,
1238 arena: *Allocator,1236 arena: *Allocator,
...@@ -2034,14 +2032,14 @@ fn astgenAndSemaFn(...@@ -2034,14 +2032,14 @@ fn astgenAndSemaFn(
20342032
2035 const fn_type_inst: zir.Inst.Ref = if (cc != 0) fn_type: {2033 const fn_type_inst: zir.Inst.Ref = if (cc != 0) fn_type: {
2036 const tag: zir.Inst.Tag = if (is_var_args) .fn_type_cc_var_args else .fn_type_cc;2034 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, .{
2038 .ret_ty = return_type_inst,2036 .ret_ty = return_type_inst,
2039 .param_types = param_types,2037 .param_types = param_types,
2040 .cc = cc,2038 .cc = cc,
2041 });2039 });
2042 } else fn_type: {2040 } else fn_type: {
2043 const tag: zir.Inst.Tag = if (is_var_args) .fn_type_var_args else .fn_type;2041 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);
2045 };2043 };
20462044
2047 // We need the memory for the Type to go into the arena for the Decl2045 // We need the memory for the Type to go into the arena for the Decl