diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-01-22 00:36:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-22 00:36:50 -0500 |
| commit | a51c76541d60da81ef53e0ab1f221a80d9956bd5 (patch) | |
| tree | 023a1f1fbc02b646214b70d78dad0acb7ec158f3 /src/value.zig | |
| parent | f85c01d4c7520d2242626f4c0684ab97e47af373 (diff) | |
| parent | aa626deadddcf26a5789d29d5ba88c978ee53b89 (diff) | |
| download | zig-a51c76541d60da81ef53e0ab1f221a80d9956bd5.tar.gz zig-a51c76541d60da81ef53e0ab1f221a80d9956bd5.zip | |
Merge pull request #14403 from Vexu/fixes
Misc fixes
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/value.zig b/src/value.zig index 5d38bcb7a9..306e31c0a7 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2076,13 +2076,22 @@ pub const Value = extern union { /// For vectors, returns true if comparison is true for ALL elements. /// /// Note that `!compareAllWithZero(.eq, ...) != compareAllWithZero(.neq, ...)` - pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator) bool { - return compareAllWithZeroAdvanced(lhs, op, null) catch unreachable; + pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator, mod: *Module) bool { + return compareAllWithZeroAdvancedExtra(lhs, op, mod, null) catch unreachable; } pub fn compareAllWithZeroAdvanced( lhs: Value, op: std.math.CompareOperator, + sema: *Sema, + ) Module.CompileError!bool { + return compareAllWithZeroAdvancedExtra(lhs, op, sema.mod, sema); + } + + pub fn compareAllWithZeroAdvancedExtra( + lhs: Value, + op: std.math.CompareOperator, + mod: *Module, opt_sema: ?*Sema, ) Module.CompileError!bool { if (lhs.isInf()) { @@ -2095,10 +2104,25 @@ pub const Value = extern union { } switch (lhs.tag()) { - .repeated => return lhs.castTag(.repeated).?.data.compareAllWithZeroAdvanced(op, opt_sema), + .repeated => return lhs.castTag(.repeated).?.data.compareAllWithZeroAdvancedExtra(op, mod, opt_sema), .aggregate => { for (lhs.castTag(.aggregate).?.data) |elem_val| { - if (!(try elem_val.compareAllWithZeroAdvanced(op, opt_sema))) return false; + if (!(try elem_val.compareAllWithZeroAdvancedExtra(op, mod, opt_sema))) return false; + } + return true; + }, + .str_lit => { + const str_lit = lhs.castTag(.str_lit).?.data; + const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; + for (bytes) |byte| { + if (!std.math.compare(byte, op, 0)) return false; + } + return true; + }, + .bytes => { + const bytes = lhs.castTag(.bytes).?.data; + for (bytes) |byte| { + if (!std.math.compare(byte, op, 0)) return false; } return true; }, @@ -3103,7 +3127,7 @@ pub const Value = extern union { .int_i64, .int_big_positive, .int_big_negative, - => compareAllWithZero(self, .eq), + => self.orderAgainstZero().compare(.eq), .undef => unreachable, .unreachable_value => unreachable, |
