mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
refactor unique int/float
This commit is contained in:
parent
143376d04c
commit
9754648280
1 changed files with 13 additions and 12 deletions
|
@ -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());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue