unsigned integer constraint (uint)
This commit is contained in:
@@ -44,6 +44,7 @@ BOOL :: Type(29)
|
||||
FLOAT :: Type(30)
|
||||
RANGE :: Type(31)
|
||||
ANYOPAQUE :: Type(32)
|
||||
UINT :: Type(33)
|
||||
|
||||
DYNAMIC_START :: Type(64)
|
||||
|
||||
@@ -59,6 +60,7 @@ Kind :: enum u8 {
|
||||
Void,
|
||||
Anyopaque,
|
||||
Int_Constraint,
|
||||
Uint_Constraint,
|
||||
Float_Constraint,
|
||||
Range_Constraint,
|
||||
Scalar,
|
||||
@@ -595,6 +597,8 @@ kind :: proc(value: Type, store: ^Store = nil) -> Kind {
|
||||
return .Anyopaque
|
||||
case INT:
|
||||
return .Int_Constraint
|
||||
case UINT:
|
||||
return .Uint_Constraint
|
||||
case FLOAT:
|
||||
return .Float_Constraint
|
||||
case RANGE:
|
||||
@@ -642,7 +646,7 @@ is_bool :: proc(value: Type) -> bool {
|
||||
}
|
||||
|
||||
is_constraint :: proc(value: Type) -> bool {
|
||||
return value == INT || value == FLOAT || value == RANGE
|
||||
return value == INT || value == UINT || value == FLOAT || value == RANGE
|
||||
}
|
||||
|
||||
// constraint_target reports the concrete type a constraint binding (local, or a
|
||||
@@ -656,6 +660,8 @@ constraint_target :: proc(constraint, inferred: Type, store: ^Store = nil) -> Ty
|
||||
switch constraint {
|
||||
case INT:
|
||||
return inferred if is_concrete_integer(inferred) else INVALID
|
||||
case UINT:
|
||||
return inferred if is_unsigned(inferred) else INVALID
|
||||
case FLOAT:
|
||||
if is_float(inferred) {
|
||||
return inferred
|
||||
@@ -673,6 +679,8 @@ constraint_accepts :: proc(constraint, concrete: Type, store: ^Store = nil) -> b
|
||||
switch constraint {
|
||||
case INT:
|
||||
return is_concrete_integer(concrete)
|
||||
case UINT:
|
||||
return is_unsigned(concrete)
|
||||
case FLOAT:
|
||||
return is_float(concrete)
|
||||
case RANGE:
|
||||
@@ -1686,6 +1694,19 @@ smallest_signed_for_literal :: proc(value: i64) -> Type {
|
||||
return I64
|
||||
}
|
||||
|
||||
smallest_unsigned_for_literal :: proc(value: u64) -> Type {
|
||||
if value <= 255 {
|
||||
return U8
|
||||
}
|
||||
if value <= 65535 {
|
||||
return U16
|
||||
}
|
||||
if value <= 4294967295 {
|
||||
return U32
|
||||
}
|
||||
return U64
|
||||
}
|
||||
|
||||
name :: proc(value: Type) -> string {
|
||||
switch value {
|
||||
case INVALID: return "<invalid>"
|
||||
@@ -1693,6 +1714,7 @@ name :: proc(value: Type) -> string {
|
||||
case ANYOPAQUE: return "anyopaque"
|
||||
case BOOL: return "bool"
|
||||
case INT: return "int"
|
||||
case UINT: return "uint"
|
||||
case FLOAT: return "float"
|
||||
case RANGE: return "range"
|
||||
case I8: return "i8"
|
||||
|
||||
Reference in New Issue
Block a user