c bool support and c-integer coercion
This commit is contained in:
@@ -1094,6 +1094,20 @@ can_widen :: proc(from, to: Type) -> bool {
|
||||
bits(from) < bits(to)
|
||||
}
|
||||
|
||||
// can_coerce_c_integer reports whether `from` may implicitly convert to `to`
|
||||
// under C's integer conversion rules. Brolang keeps its own exact-width scalars
|
||||
// strict (`u32 -> i32` is rejected), but C interop types deliberately follow C:
|
||||
// virtually every C library relies on it — e.g. an unsigned-backed enum constant
|
||||
// (`c_uint`) passed to an `int` (`c_int`) parameter — so disallowing it would
|
||||
// make C interop cumbersome. Scope: widening (sext/zext) and same-width
|
||||
// signedness changes (no-op reinterpret); narrowing is intentionally excluded so
|
||||
// lossy conversions stay an error, matching brolang's trap-on-narrow philosophy.
|
||||
can_coerce_c_integer :: proc(from, to: Type) -> bool {
|
||||
return from != to && is_c(from) && is_c(to) &&
|
||||
is_concrete_integer(from) && is_concrete_integer(to) &&
|
||||
bits(from) <= bits(to)
|
||||
}
|
||||
|
||||
widest :: proc(a, b: Type) -> Type {
|
||||
if equal(a, b) && is_concrete_scalar(a) {
|
||||
return a
|
||||
|
||||
Reference in New Issue
Block a user