aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-12-21 14:33:02 +0200
committerVeikka Tuominen <git@vexu.eu>2022-12-27 15:13:14 +0200
commit54160e7f6aecb4628df633ceaef4c6d956429a3d (patch)
tree8b523c4dad676be508f680fa8840fa3430a14191 /src/value.zig
parentaf9a9a13747b1e7007e29ff4f76e700f5bd7f7cf (diff)
downloadzig-54160e7f6aecb4628df633ceaef4c6d956429a3d.tar.gz
zig-54160e7f6aecb4628df633ceaef4c6d956429a3d.zip
Sema: make overflow arithmetic builtins return tuples
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/value.zig b/src/value.zig
index a607a3551e..c86e5ab12c 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -3259,8 +3259,7 @@ pub const Value = extern union {
}
pub const OverflowArithmeticResult = struct {
- /// TODO: Rename to `overflow_bit` and make of type `u1`.
- overflowed: Value,
+ overflow_bit: Value,
wrapped_result: Value,
};
@@ -3395,11 +3394,11 @@ pub const Value = extern union {
const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
- overflowed_data[i] = of_math_result.overflowed;
+ overflowed_data[i] = of_math_result.overflow_bit;
scalar.* = of_math_result.wrapped_result;
}
return OverflowArithmeticResult{
- .overflowed = try Value.Tag.aggregate.create(arena, overflowed_data),
+ .overflow_bit = try Value.Tag.aggregate.create(arena, overflowed_data),
.wrapped_result = try Value.Tag.aggregate.create(arena, result_data),
};
}
@@ -3436,7 +3435,7 @@ pub const Value = extern union {
}
return OverflowArithmeticResult{
- .overflowed = makeBool(overflowed),
+ .overflow_bit = boolToInt(overflowed),
.wrapped_result = try fromBigInt(arena, result_bigint.toConst()),
};
}
@@ -4141,11 +4140,11 @@ pub const Value = extern union {
const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(), allocator, target);
- overflowed_data[i] = of_math_result.overflowed;
+ overflowed_data[i] = of_math_result.overflow_bit;
scalar.* = of_math_result.wrapped_result;
}
return OverflowArithmeticResult{
- .overflowed = try Value.Tag.aggregate.create(allocator, overflowed_data),
+ .overflow_bit = try Value.Tag.aggregate.create(allocator, overflowed_data),
.wrapped_result = try Value.Tag.aggregate.create(allocator, result_data),
};
}
@@ -4178,7 +4177,7 @@ pub const Value = extern union {
result_bigint.truncate(result_bigint.toConst(), info.signedness, info.bits);
}
return OverflowArithmeticResult{
- .overflowed = makeBool(overflowed),
+ .overflow_bit = boolToInt(overflowed),
.wrapped_result = try fromBigInt(allocator, result_bigint.toConst()),
};
}
@@ -5492,6 +5491,10 @@ pub const Value = extern union {
return if (x) Value.true else Value.false;
}
+ pub fn boolToInt(x: bool) Value {
+ return if (x) Value.one else Value.zero;
+ }
+
pub const RuntimeIndex = enum(u32) {
zero = 0,
comptime_field_ptr = std.math.maxInt(u32),