mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
More wip
This commit is contained in:
parent
ec099bbdec
commit
b8fd6992a2
2 changed files with 72 additions and 0 deletions
|
@ -23,6 +23,7 @@ impl Constraints {
|
|||
|
||||
pub const CATEGORY_RECORD: Index<Category> = Index::new(0);
|
||||
|
||||
#[inline(always)]
|
||||
pub fn push_type(&mut self, typ: Type) -> Index<Type> {
|
||||
match typ {
|
||||
Type::EmptyRec => Self::EMPTY_RECORD,
|
||||
|
@ -31,6 +32,12 @@ impl Constraints {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn push_expected_type(&mut self, expected: Expected<Type>) -> Index<Expected<Type>> {
|
||||
Index::push_new(&mut self.expectations, expected)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn push_category(&mut self, category: Category) -> Index<Category> {
|
||||
match category {
|
||||
Category::Record => Self::CATEGORY_RECORD,
|
||||
|
@ -156,6 +163,21 @@ impl Constraints {
|
|||
|
||||
Constraint::Let(let_index)
|
||||
}
|
||||
|
||||
pub fn and_contraint<I>(&mut self, constraints: I) -> Constraint
|
||||
where
|
||||
I: IntoIterator<Item = Constraint>,
|
||||
{
|
||||
let start = self.constraints.len() as u32;
|
||||
|
||||
self.constraints.extend(constraints);
|
||||
|
||||
let end = self.constraints.len() as u32;
|
||||
|
||||
let slice = Slice::new(start, (end - start) as u16);
|
||||
|
||||
Constraint::And(slice)
|
||||
}
|
||||
}
|
||||
|
||||
static_assertions::assert_eq_size!([u8; 4 * 8], Constraint);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use roc_can::constraint::Constraint::{self, *};
|
||||
use roc_can::constraint::LetConstraint;
|
||||
use roc_can::constraint_soa::Constraints;
|
||||
use roc_can::expected::Expected::{self, *};
|
||||
use roc_can::num::{FloatBound, FloatWidth, IntBound, IntWidth, NumericBound, SignDemand};
|
||||
use roc_collections::all::SendMap;
|
||||
|
@ -82,6 +83,55 @@ pub fn float_literal(
|
|||
) -> Constraint {
|
||||
let reason = Reason::FloatLiteral;
|
||||
|
||||
let value_is_float_literal = Eq(
|
||||
num_type.clone(),
|
||||
ForReason(reason, num_float(Type::Variable(precision_var)), region),
|
||||
Category::Float,
|
||||
region,
|
||||
);
|
||||
|
||||
let expected_float = Eq(num_type, expected, Category::Float, region);
|
||||
|
||||
let mut constrs = Vec::with_capacity(3);
|
||||
let num_type = {
|
||||
let constrs: &mut Vec<Constraint> = &mut constrs;
|
||||
let num_type = Variable(num_var);
|
||||
let category = Category::Float;
|
||||
let range = bound.bounded_range();
|
||||
|
||||
let total_num_type = num_type;
|
||||
|
||||
match range.len() {
|
||||
0 => total_num_type,
|
||||
1 => {
|
||||
let actual_type = Variable(range[0]);
|
||||
constrs.push(Eq(
|
||||
total_num_type.clone(),
|
||||
Expected::ForReason(Reason::NumericLiteralSuffix, actual_type, region),
|
||||
category,
|
||||
region,
|
||||
));
|
||||
total_num_type
|
||||
}
|
||||
_ => RangedNumber(Box::new(total_num_type), range),
|
||||
}
|
||||
};
|
||||
constrs.extend(vec![]);
|
||||
|
||||
exists(vec![num_var, precision_var], And(constrs))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn float_literal_soa(
|
||||
constraints: &mut Constraints,
|
||||
num_var: Variable,
|
||||
precision_var: Variable,
|
||||
expected: Expected<Type>,
|
||||
region: Region,
|
||||
bound: FloatBound,
|
||||
) -> Constraint {
|
||||
let reason = Reason::FloatLiteral;
|
||||
|
||||
let mut constrs = Vec::with_capacity(3);
|
||||
let num_type = add_numeric_bound_constr(
|
||||
&mut constrs,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue