mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Merge branch 'int-float-size-gen' into temp_numbers
This commit is contained in:
commit
c33cab57f2
14 changed files with 493 additions and 85 deletions
|
@ -11,30 +11,50 @@ use roc_types::types::Reason;
|
|||
use roc_types::types::Type::{self, *};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn int_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
||||
pub fn int_literal(
|
||||
num_var: Variable,
|
||||
percision_var: Variable,
|
||||
expected: Expected<Type>,
|
||||
region: Region,
|
||||
) -> Constraint {
|
||||
let num_type = Variable(num_var);
|
||||
let reason = Reason::IntLiteral;
|
||||
let expected_literal = ForReason(reason, num_int(Type::Variable(num_var)), region);
|
||||
|
||||
exists(
|
||||
vec![num_var],
|
||||
And(vec![
|
||||
Eq(num_type.clone(), expected_literal, Category::Int, region),
|
||||
Eq(
|
||||
num_type.clone(),
|
||||
ForReason(reason, num_int(Type::Variable(percision_var)), region),
|
||||
Category::Int,
|
||||
region,
|
||||
),
|
||||
Eq(num_type, expected, Category::Int, region),
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn float_literal(num_var: Variable, expected: Expected<Type>, region: Region) -> Constraint {
|
||||
pub fn float_literal(
|
||||
num_var: Variable,
|
||||
percision_var: Variable,
|
||||
expected: Expected<Type>,
|
||||
region: Region,
|
||||
) -> Constraint {
|
||||
let num_type = Variable(num_var);
|
||||
let reason = Reason::FloatLiteral;
|
||||
let expected_literal = ForReason(reason, num_float(Type::Variable(num_var)), region);
|
||||
|
||||
dbg!(&expected);
|
||||
|
||||
exists(
|
||||
vec![num_var],
|
||||
And(vec![
|
||||
Eq(num_type.clone(), expected_literal, Category::Float, region),
|
||||
Eq(
|
||||
num_type.clone(),
|
||||
ForReason(reason, num_float(Type::Variable(percision_var)), region),
|
||||
Category::Float,
|
||||
region,
|
||||
),
|
||||
Eq(num_type, expected, Category::Float, region),
|
||||
]),
|
||||
)
|
||||
|
|
|
@ -96,7 +96,7 @@ pub fn constrain_expr(
|
|||
expected: Expected<Type>,
|
||||
) -> Constraint {
|
||||
match expr {
|
||||
Int(var, _) => int_literal(*var, expected, region),
|
||||
Int(var, percision, _) => int_literal(*var, *percision, expected, region),
|
||||
Num(var, _) => exists(
|
||||
vec![*var],
|
||||
Eq(
|
||||
|
@ -106,7 +106,7 @@ pub fn constrain_expr(
|
|||
region,
|
||||
),
|
||||
),
|
||||
Float(var, _) => float_literal(*var, expected, region),
|
||||
Float(var, percision, _) => float_literal(*var, *percision, expected, region),
|
||||
EmptyRecord => constrain_empty_record(region, expected),
|
||||
Expr::Record { record_var, fields } => {
|
||||
if fields.is_empty() {
|
||||
|
|
|
@ -426,6 +426,7 @@ fn unique_int(
|
|||
let num_uvar1 = var_store.fresh();
|
||||
let num_uvar2 = var_store.fresh();
|
||||
let num_uvar3 = var_store.fresh();
|
||||
let num_uvar4 = var_store.fresh();
|
||||
|
||||
let inner_type = Type::Variable(inner_var);
|
||||
let attr_inner_type = attr_type(Bool::variable(num_uvar1), inner_type);
|
||||
|
@ -444,6 +445,7 @@ fn unique_float(
|
|||
let num_uvar1 = var_store.fresh();
|
||||
let num_uvar2 = var_store.fresh();
|
||||
let num_uvar3 = var_store.fresh();
|
||||
let num_uvar4 = var_store.fresh();
|
||||
|
||||
let inner_type = Type::Variable(inner_var);
|
||||
let attr_inner_type = attr_type(Bool::variable(num_uvar1), inner_type);
|
||||
|
@ -484,7 +486,7 @@ pub fn constrain_expr(
|
|||
]),
|
||||
)
|
||||
}
|
||||
Int(var, _) => {
|
||||
Int(var, _, _) => {
|
||||
let (a, b, c, num_type) = unique_int(*var, var_store);
|
||||
|
||||
exists(
|
||||
|
@ -500,7 +502,7 @@ pub fn constrain_expr(
|
|||
]),
|
||||
)
|
||||
}
|
||||
Float(var, _) => {
|
||||
Float(var, _, _) => {
|
||||
let (a, b, c, num_type) = unique_float(*var, var_store);
|
||||
|
||||
exists(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue