diff options
| author | fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com> | 2023-01-22 05:30:38 -0800 |
|---|---|---|
| committer | fn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com> | 2023-01-22 05:30:38 -0800 |
| commit | 6089ed9ee77ed034a39c2b557f4608cd8d779d3f (patch) | |
| tree | 9eaf9d78ca73d8c2dc1654e1e8beacbed1551988 /src/value.zig | |
| parent | be4468be371de34e90a86346b0f6da6f2d85bef4 (diff) | |
| parent | c0284e242f7d78955204dc8a627fecd45aa5e521 (diff) | |
| download | zig-6089ed9ee77ed034a39c2b557f4608cd8d779d3f.tar.gz zig-6089ed9ee77ed034a39c2b557f4608cd8d779d3f.zip | |
Merge branch 'master' into crc
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, |
