disambiguate enum blocks and complete distinct type operations
This commit is contained in:
@@ -316,6 +316,21 @@ hide format_field_name func($T type, index usize) []u8 {
|
||||
else: compile_error!("io.print arguments must be a tuple")
|
||||
}
|
||||
}
|
||||
hide distinct_value func($Backing, $Distinct type, value Distinct) Backing {
|
||||
return ptrcast!(Backing, &value)^
|
||||
}
|
||||
|
||||
hide scalar_or_distinct_type func($T type) bool {
|
||||
match typeinfo!(T) {
|
||||
.bool: return true
|
||||
.integer: return true
|
||||
.float: return true
|
||||
.distinct: return true
|
||||
else: return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
hide write_integer func(output Writer, $T type, value T, base u64, uppercase bool) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
@@ -324,6 +339,11 @@ hide write_integer func(output Writer, $T type, value T, base u64, uppercase boo
|
||||
} else {
|
||||
try write_integer_unsigned(output, u64(value), base, uppercase)
|
||||
}
|
||||
.distinct |backing|: if scalar_or_distinct_type(backing) {
|
||||
try write_integer(output, distinct_value(backing, T, value), base, uppercase)
|
||||
} else {
|
||||
compile_error!("io.print integer format requires an integer argument")
|
||||
}
|
||||
else: compile_error!("io.print integer format requires an integer argument")
|
||||
}
|
||||
return
|
||||
@@ -351,6 +371,11 @@ hide write_float func(output Writer, $T type, value T, scientific bool) void ! W
|
||||
}
|
||||
try write_all(output, buffer[0..usize(count)])
|
||||
}
|
||||
.distinct |backing|: if scalar_or_distinct_type(backing) {
|
||||
try write_float(output, distinct_value(backing, T, value), scientific)
|
||||
} else {
|
||||
compile_error!("io.print float format requires a float argument")
|
||||
}
|
||||
else: compile_error!("io.print float format requires a float argument")
|
||||
}
|
||||
return
|
||||
@@ -360,6 +385,11 @@ hide write_decimal func(output Writer, $T type, value T) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
.integer: try write_integer(output, value, 10, false)
|
||||
.float: try write_float(output, value, false)
|
||||
.distinct |backing|: if scalar_or_distinct_type(backing) {
|
||||
try write_decimal(output, distinct_value(backing, T, value))
|
||||
} else {
|
||||
compile_error!("io.print '{d}' requires an integer or float argument")
|
||||
}
|
||||
else: compile_error!("io.print '{d}' requires an integer or float argument")
|
||||
}
|
||||
return
|
||||
@@ -374,6 +404,11 @@ hide write_character func(output Writer, $T type, value T) void ! WriteError {
|
||||
buffer [1]u8 = [u8(value)]
|
||||
try write_all(output, buffer[..])
|
||||
}
|
||||
.distinct |backing|: if scalar_or_distinct_type(backing) {
|
||||
try write_character(output, distinct_value(backing, T, value))
|
||||
} else {
|
||||
compile_error!("io.print '{c}' requires an unsigned integer that fits in u8")
|
||||
}
|
||||
else: compile_error!("io.print '{c}' requires an unsigned integer that fits in u8")
|
||||
}
|
||||
return
|
||||
@@ -401,6 +436,11 @@ hide write_default func(output Writer, $T type, value T) void ! WriteError {
|
||||
}
|
||||
return .write_failed
|
||||
}
|
||||
.distinct |backing|: if scalar_or_distinct_type(backing) {
|
||||
try write_default(output, distinct_value(backing, T, value))
|
||||
} else {
|
||||
compile_error!("io.print '{}' does not support this argument type")
|
||||
}
|
||||
else: compile_error!("io.print '{}' does not support this argument type")
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user