add float constraint type
This commit is contained in:
@@ -41,6 +41,7 @@ C_DOUBLE :: Type(27)
|
||||
C_LONGDOUBLE :: Type(28)
|
||||
|
||||
BOOL :: Type(29)
|
||||
FLOAT :: Type(30)
|
||||
|
||||
DYNAMIC_START :: Type(64)
|
||||
|
||||
@@ -55,6 +56,7 @@ Kind :: enum u8 {
|
||||
Invalid,
|
||||
Void,
|
||||
Int_Constraint,
|
||||
Float_Constraint,
|
||||
Scalar,
|
||||
Array,
|
||||
Pointer,
|
||||
@@ -295,6 +297,8 @@ kind :: proc(value: Type, store: ^Store = nil) -> Kind {
|
||||
return .Void
|
||||
case INT:
|
||||
return .Int_Constraint
|
||||
case FLOAT:
|
||||
return .Float_Constraint
|
||||
case BOOL:
|
||||
return .Scalar
|
||||
}
|
||||
@@ -334,7 +338,37 @@ is_bool :: proc(value: Type) -> bool {
|
||||
}
|
||||
|
||||
is_constraint :: proc(value: Type) -> bool {
|
||||
return value == INT
|
||||
return value == INT || value == FLOAT
|
||||
}
|
||||
|
||||
// constraint_target reports the concrete type a constraint binding takes for an
|
||||
// inferred value, or INVALID if the value's numeric family is incompatible.
|
||||
// FLOAT accepts integers by defaulting them to f64: a constant integer becomes a
|
||||
// float literal in build_constant_expr, while a runtime integer then fails the
|
||||
// cross-family f64 coercion in coerce_expr (the intended mismatch error).
|
||||
constraint_target :: proc(constraint, inferred: Type) -> Type {
|
||||
switch constraint {
|
||||
case INT:
|
||||
return inferred if is_concrete_integer(inferred) else INVALID
|
||||
case FLOAT:
|
||||
if is_float(inferred) {
|
||||
return inferred
|
||||
}
|
||||
return F64 if is_concrete_integer(inferred) else INVALID
|
||||
}
|
||||
return INVALID
|
||||
}
|
||||
|
||||
// constraint_accepts reports strict numeric-family membership, used when widening
|
||||
// a constraint binding across assignments (no integer-to-float defaulting here).
|
||||
constraint_accepts :: proc(constraint, concrete: Type) -> bool {
|
||||
switch constraint {
|
||||
case INT:
|
||||
return is_concrete_integer(concrete)
|
||||
case FLOAT:
|
||||
return is_float(concrete)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
is_c :: proc(value: Type) -> bool {
|
||||
@@ -1140,6 +1174,7 @@ name :: proc(value: Type) -> string {
|
||||
case VOID: return "void"
|
||||
case BOOL: return "bool"
|
||||
case INT: return "int"
|
||||
case FLOAT: return "float"
|
||||
case I8: return "i8"
|
||||
case I16: return "i16"
|
||||
case I32: return "i32"
|
||||
|
||||
Reference in New Issue
Block a user