mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Move NumWidth to roc_can
This commit is contained in:
parent
ae5766fdf5
commit
e7dcc2daa5
7 changed files with 50 additions and 92 deletions
|
@ -1,12 +1,12 @@
|
||||||
use crate::def::Def;
|
use crate::def::Def;
|
||||||
use crate::expr::{self, ClosureData, Expr::*};
|
use crate::expr::{self, ClosureData, Expr::*};
|
||||||
use crate::expr::{Expr, Field, Recursive};
|
use crate::expr::{Expr, Field, Recursive};
|
||||||
|
use crate::num::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
||||||
use crate::pattern::Pattern;
|
use crate::pattern::Pattern;
|
||||||
use roc_collections::all::SendMap;
|
use roc_collections::all::SendMap;
|
||||||
use roc_module::called_via::CalledVia;
|
use roc_module::called_via::CalledVia;
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::low_level::LowLevel;
|
use roc_module::low_level::LowLevel;
|
||||||
use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use roc_types::subs::{VarStore, Variable};
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::def::{can_defs_with_return, Def};
|
||||||
use crate::env::Env;
|
use crate::env::Env;
|
||||||
use crate::num::{
|
use crate::num::{
|
||||||
finish_parsing_base, finish_parsing_float, finish_parsing_num, float_expr_from_result,
|
finish_parsing_base, finish_parsing_float, finish_parsing_num, float_expr_from_result,
|
||||||
int_expr_from_result, num_expr_from_result,
|
int_expr_from_result, num_expr_from_result, FloatWidth, IntWidth, NumWidth, NumericBound,
|
||||||
};
|
};
|
||||||
use crate::pattern::{canonicalize_pattern, Pattern};
|
use crate::pattern::{canonicalize_pattern, Pattern};
|
||||||
use crate::procedure::References;
|
use crate::procedure::References;
|
||||||
|
@ -13,7 +13,6 @@ use roc_collections::all::{ImSet, MutMap, MutSet, SendMap};
|
||||||
use roc_module::called_via::CalledVia;
|
use roc_module::called_via::CalledVia;
|
||||||
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
|
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
|
||||||
use roc_module::low_level::LowLevel;
|
use roc_module::low_level::LowLevel;
|
||||||
use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_parse::ast::{self, EscapedChar, StrLiteral};
|
use roc_parse::ast::{self, EscapedChar, StrLiteral};
|
||||||
use roc_parse::pattern::PatternType::*;
|
use roc_parse::pattern::PatternType::*;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::env::Env;
|
use crate::env::Env;
|
||||||
use crate::expr::Expr;
|
use crate::expr::Expr;
|
||||||
use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
|
||||||
use roc_parse::ast::Base;
|
use roc_parse::ast::Base;
|
||||||
use roc_problem::can::Problem;
|
use roc_problem::can::Problem;
|
||||||
use roc_problem::can::RuntimeError::*;
|
use roc_problem::can::RuntimeError::*;
|
||||||
|
@ -336,6 +335,46 @@ fn from_str_radix<T: FromStrRadixHelper>(
|
||||||
Ok((result, bound))
|
Ok((result, bound))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
pub enum IntWidth {
|
||||||
|
U8,
|
||||||
|
U16,
|
||||||
|
U32,
|
||||||
|
U64,
|
||||||
|
U128,
|
||||||
|
I8,
|
||||||
|
I16,
|
||||||
|
I32,
|
||||||
|
I64,
|
||||||
|
I128,
|
||||||
|
Nat,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
pub enum FloatWidth {
|
||||||
|
Dec,
|
||||||
|
F32,
|
||||||
|
F64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
pub enum NumWidth {
|
||||||
|
Int(IntWidth),
|
||||||
|
Float(FloatWidth),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Describes a bound on the width of a numeric literal.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
pub enum NumericBound<W>
|
||||||
|
where
|
||||||
|
W: Copy,
|
||||||
|
{
|
||||||
|
/// There is no bound on the width.
|
||||||
|
None,
|
||||||
|
/// Must have exactly the width `W`.
|
||||||
|
Exact(W),
|
||||||
|
}
|
||||||
|
|
||||||
/// An error which can be returned when parsing an integer.
|
/// An error which can be returned when parsing an integer.
|
||||||
///
|
///
|
||||||
/// This error is used as the error type for the `from_str_radix()` functions
|
/// This error is used as the error type for the `from_str_radix()` functions
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use crate::env::Env;
|
use crate::env::Env;
|
||||||
use crate::expr::{canonicalize_expr, unescape_char, Expr, Output};
|
use crate::expr::{canonicalize_expr, unescape_char, Expr, Output};
|
||||||
use crate::num::{finish_parsing_base, finish_parsing_float, finish_parsing_num, ParsedNumResult};
|
use crate::num::{
|
||||||
|
finish_parsing_base, finish_parsing_float, finish_parsing_num, FloatWidth, IntWidth, NumWidth,
|
||||||
|
NumericBound, ParsedNumResult,
|
||||||
|
};
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||||
use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_parse::ast::{self, StrLiteral, StrSegment};
|
use roc_parse::ast::{self, StrLiteral, StrSegment};
|
||||||
use roc_parse::pattern::PatternType;
|
use roc_parse::pattern::PatternType;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use roc_can::constraint::Constraint::{self, *};
|
use roc_can::constraint::Constraint::{self, *};
|
||||||
use roc_can::constraint::LetConstraint;
|
use roc_can::constraint::LetConstraint;
|
||||||
use roc_can::expected::Expected::{self, *};
|
use roc_can::expected::Expected::{self, *};
|
||||||
|
use roc_can::num::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
||||||
use roc_collections::all::SendMap;
|
use roc_collections::all::SendMap;
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::numeric::{FloatWidth, IntWidth, NumWidth, NumericBound};
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
use roc_types::subs::Variable;
|
use roc_types::subs::Variable;
|
||||||
|
@ -331,7 +331,9 @@ impl TypedNumericBound for NumericBound<NumWidth> {
|
||||||
match self {
|
match self {
|
||||||
NumericBound::None => None,
|
NumericBound::None => None,
|
||||||
NumericBound::Exact(NumWidth::Int(iw)) => NumericBound::Exact(*iw).concrete_num_type(),
|
NumericBound::Exact(NumWidth::Int(iw)) => NumericBound::Exact(*iw).concrete_num_type(),
|
||||||
NumericBound::Exact(NumWidth::Float(fw)) => NumericBound::Exact(*fw).concrete_num_type(),
|
NumericBound::Exact(NumWidth::Float(fw)) => {
|
||||||
|
NumericBound::Exact(*fw).concrete_num_type()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ pub mod called_via;
|
||||||
pub mod ident;
|
pub mod ident;
|
||||||
pub mod low_level;
|
pub mod low_level;
|
||||||
pub mod module_err;
|
pub mod module_err;
|
||||||
pub mod numeric;
|
|
||||||
pub mod symbol;
|
pub mod symbol;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
//! Module `numeric` has utilities for numeric values in the Roc surface syntax.
|
|
||||||
|
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
||||||
pub enum IntWidth {
|
|
||||||
U8,
|
|
||||||
U16,
|
|
||||||
U32,
|
|
||||||
U64,
|
|
||||||
U128,
|
|
||||||
I8,
|
|
||||||
I16,
|
|
||||||
I32,
|
|
||||||
I64,
|
|
||||||
I128,
|
|
||||||
Nat,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for IntWidth {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
use IntWidth::*;
|
|
||||||
f.write_str(match self {
|
|
||||||
U8 => "u8",
|
|
||||||
U16 => "u16",
|
|
||||||
U32 => "u32",
|
|
||||||
U64 => "u64",
|
|
||||||
U128 => "u128",
|
|
||||||
I8 => "i8",
|
|
||||||
I16 => "i16",
|
|
||||||
I32 => "i32",
|
|
||||||
I64 => "i64",
|
|
||||||
I128 => "i128",
|
|
||||||
Nat => "nat",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
||||||
pub enum FloatWidth {
|
|
||||||
Dec,
|
|
||||||
F32,
|
|
||||||
F64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for FloatWidth {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
use FloatWidth::*;
|
|
||||||
f.write_str(match self {
|
|
||||||
Dec => "dec",
|
|
||||||
F32 => "f32",
|
|
||||||
F64 => "f64",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
||||||
pub enum NumWidth {
|
|
||||||
Int(IntWidth),
|
|
||||||
Float(FloatWidth),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for NumWidth {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
use NumWidth::*;
|
|
||||||
match self {
|
|
||||||
Int(iw) => iw.fmt(f),
|
|
||||||
Float(fw) => fw.fmt(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Describes a bound on the width of a numeric literal.
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
||||||
pub enum NumericBound<W>
|
|
||||||
where
|
|
||||||
W: Copy,
|
|
||||||
{
|
|
||||||
/// There is no bound on the width.
|
|
||||||
None,
|
|
||||||
/// Must have exactly the width `W`.
|
|
||||||
Exact(W),
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue