refactor unique int/float

This commit is contained in:
Folkert 2020-12-22 15:17:59 +01:00
parent 143376d04c
commit 9754648280

View file

@ -431,16 +431,27 @@ fn unique_num(val_type: Type, uvar: Variable) -> Type {
attr_type(Bool::variable(uvar), num_utype)
}
fn unique_integer(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) {
fn unique_midlevel<F>(var_store: &mut VarStore, val_type: Type, transform: F) -> (Variable, Type)
where
F: Fn(Type) -> Type,
{
let num_uvar = var_store.fresh();
let val_utype = attr_type(Bool::variable(num_uvar), val_type);
let num_type = num_integer(val_utype);
let num_type = transform(val_utype);
(num_uvar, num_type)
}
fn unique_integer(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) {
unique_midlevel(var_store, val_type, num_integer)
}
fn unique_floatingpoint(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) {
unique_midlevel(var_store, val_type, num_floatingpoint)
}
fn unique_int(var_store: &mut VarStore) -> (Variable, Type) {
let (var1, typ) = unique_integer(var_store, num_signed64());
@ -449,16 +460,6 @@ fn unique_int(var_store: &mut VarStore) -> (Variable, Type) {
(var1, typ)
}
fn unique_floatingpoint(var_store: &mut VarStore, val_type: Type) -> (Variable, Type) {
let num_uvar = var_store.fresh();
let val_utype = attr_type(Bool::variable(num_uvar), val_type);
let num_type = num_floatingpoint(val_utype);
(num_uvar, num_type)
}
fn unique_float(var_store: &mut VarStore) -> (Variable, Type) {
let (var1, typ) = unique_floatingpoint(var_store, num_binary64());