disambiguate enum blocks and complete distinct type operations

This commit is contained in:
2026-08-01 23:57:35 +02:00
parent 91aa601464
commit b9526b5f06
34 changed files with 1128 additions and 1963359 deletions
+72 -2
View File
@@ -9,8 +9,14 @@ LocalID :: distinct u32
PointID :: distinct Point
Bytes :: distinct [2]u8
WrappedID :: distinct LocalID
Signed :: distinct i32
Mask :: distinct u8
Real :: distinct f64
static_id LocalID :: LocalID(42)
static_expression LocalID :: (LocalID(3) + 5) * 2
take func(value LocalID) LocalID {
return value
@@ -26,12 +32,76 @@ main func() i32 {
wrapped WrappedID :: WrappedID(id)
remote ids.UserID :: ids.UserID(8)
remote_copy ids.UserID :: ids.make(9)
_ = static_id
if id + 1 != 8 or 1 + id != 8 { return 1 }
if id - 2 != 5 or 2 * id != 14 or id * 2 != 14 { return 2 }
if -Signed(5) != -5 { return 3 }
real Real :: Real(1.5)
if real + 0.5 != 2.0 or 0.5 + real != 2.0 or real - 0.5 != 1.0 or
real * 2.0 != 3.0 or real / 0.5 != 3.0 {
return 4
}
if !(id == 7) or !(7 == id) or !(id != 8) or !(8 != id) or
!(id < 8) or !(6 < id) or !(id <= 7) or !(7 <= id) or
!(id > 6) or !(8 > id) or !(id >= 7) or !(7 >= id) {
return 5
}
signed Signed :: Signed(-7)
if divtrunc!(signed, 3) != -2 or divfloor!(signed, 3) != -3 or
divexact!(Signed(8), 2) != 4 or divceil!(signed, 3) != -2 or
rem!(signed, 3) != -1 or mod!(signed, 3) != 2 {
return 6
}
mask Mask :: Mask(10)
if ~mask != 245 or (mask & 6) != 2 or (mask | 5) != 15 or (mask xor 3) != 9 {
return 7
}
if mask << u8(1) != 20 or mask >> u8(1) != 5 or Mask(128) <<| u8(1) != 255 {
return 8
}
arithmetic Signed = Signed(4)
arithmetic += 3
arithmetic -= 2
arithmetic *= 5
fraction Real = Real(3.0)
fraction /= 2.0
if arithmetic != 25 or fraction != 1.5 { return 9 }
bits Mask = Mask(3)
bits |= 8
bits xor= 2
bits &= 9
bits <<= u8(1)
bits >>= u8(1)
bits <<|= u8(5)
if bits != 255 { return 10 }
values [10]u8 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if values[LocalID(4)] != 4 { return 11 }
section []u8 = values[LocalID(2)..LocalID(5)]
if section.len != 3 or section[usize(0)] != 2 or section[usize(2)] != 4 { return 12 }
if u32(id) != 7 or usize(id) != 7 or f64(id) != 7.0 { return 13 }
extracted LocalID = LocalID(wrapped)
if extracted != id { return 14 }
minimum Signed = minval!(Signed)
maximum Mask = maxval!(Mask)
nested_max WrappedID = maxval!(WrappedID)
if i32(minimum) != minval!(i32) or u8(maximum) != 255 or u32(nested_max) != maxval!(u32) {
return 15
}
if static_expression != 16 { return 16 }
_ = maybe
_ = pointer
_ = point
_ = bytes
_ = wrapped
_ = remote
_ = remote_copy
return 0
+19
View File
@@ -24,6 +24,12 @@ Config :: struct {
maybe ?i32
payload Payload
}
Count :: distinct i32
Byte :: distinct u8
Ratio :: distinct f32
Inner :: distinct u32
Outer :: distinct Inner
first Config :: Config {
enabled = true,
@@ -105,6 +111,19 @@ main func(init process.Init) i32 {
}) catch |_| {
return 3
}
io.print(writer, "{} {d} {b} {o} {x} {X} {c} {e} {}\n", {
Count(i32(-42)),
Count(i32(-42)),
Byte(u8(10)),
Byte(u8(10)),
Byte(u8(255)),
Byte(u8(255)),
Byte(u8('A')),
Ratio(f32(1.5)),
Outer(Inner(u32(7))),
}) catch |_| {
return 4
}
debug.print("debug={} {x}\n", {State.idle, 42})
return 0
}