From 25ec2dbc1e2302d1138749262b588d3e438fcd55 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sat, 17 Oct 2020 18:04:53 -0600 Subject: Add builtin.Signedness, use it instead of is_signed --- src/value.zig | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/value.zig') diff --git a/src/value.zig b/src/value.zig index 8cbffecab6..4271ae66f4 100644 --- a/src/value.zig +++ b/src/value.zig @@ -929,11 +929,10 @@ pub const Value = extern union { .bool_true, => { const info = ty.intInfo(target); - if (info.signed) { - return info.bits >= 2; - } else { - return info.bits >= 1; - } + return switch (info.signedness) { + .signed => info.bits >= 2, + .unsigned => info.bits >= 1, + }; }, .int_u64 => switch (ty.zigTypeTag()) { @@ -941,7 +940,7 @@ pub const Value = extern union { const x = self.cast(Payload.Int_u64).?.int; if (x == 0) return true; const info = ty.intInfo(target); - const needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signed); + const needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed); return info.bits >= needed_bits; }, .ComptimeInt => return true, @@ -952,7 +951,7 @@ pub const Value = extern union { const x = self.cast(Payload.Int_i64).?.int; if (x == 0) return true; const info = ty.intInfo(target); - if (!info.signed and x < 0) + if (info.signedness == .unsigned and x < 0) return false; @panic("TODO implement i64 intFitsInType"); }, @@ -962,7 +961,7 @@ pub const Value = extern union { .int_big_positive => switch (ty.zigTypeTag()) { .Int => { const info = ty.intInfo(target); - return self.cast(Payload.IntBigPositive).?.asBigInt().fitsInTwosComp(info.signed, info.bits); + return self.cast(Payload.IntBigPositive).?.asBigInt().fitsInTwosComp(info.signedness, info.bits); }, .ComptimeInt => return true, else => unreachable, @@ -970,7 +969,7 @@ pub const Value = extern union { .int_big_negative => switch (ty.zigTypeTag()) { .Int => { const info = ty.intInfo(target); - return self.cast(Payload.IntBigNegative).?.asBigInt().fitsInTwosComp(info.signed, info.bits); + return self.cast(Payload.IntBigNegative).?.asBigInt().fitsInTwosComp(info.signedness, info.bits); }, .ComptimeInt => return true, else => unreachable, -- cgit v1.2.3