mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
cleanup
This commit is contained in:
parent
98ce9f4d09
commit
d43bda83b4
5 changed files with 37 additions and 113 deletions
|
@ -4,17 +4,14 @@ use roc_module::symbol::Symbol;
|
|||
/// A bound placed on a number because of its literal value.
|
||||
/// e.g. `-5` cannot be unsigned, and 300 does not fit in a U8
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum NumericBound {
|
||||
None,
|
||||
FloatExact(FloatWidth),
|
||||
IntExact(IntWidth),
|
||||
pub enum NumericRange {
|
||||
IntAtLeastSigned(IntWidth),
|
||||
IntAtLeastEitherSign(IntWidth),
|
||||
NumAtLeastSigned(IntWidth),
|
||||
NumAtLeastEitherSign(IntWidth),
|
||||
}
|
||||
|
||||
impl NumericBound {
|
||||
impl NumericRange {
|
||||
pub fn contains_symbol(&self, symbol: Symbol) -> bool {
|
||||
match symbol {
|
||||
Symbol::NUM_I8 => self.contains_int_width(IntWidth::I8),
|
||||
|
@ -47,14 +44,13 @@ impl NumericBound {
|
|||
}
|
||||
|
||||
fn contains_int_width(&self, width: IntWidth) -> bool {
|
||||
use NumericBound::*;
|
||||
use NumericRange::*;
|
||||
|
||||
let (range_sign, at_least_width) = match self {
|
||||
IntAtLeastSigned(width) => (SignDemand::Signed, width),
|
||||
IntAtLeastEitherSign(width) => (SignDemand::NoDemand, width),
|
||||
NumAtLeastSigned(width) => (SignDemand::Signed, width),
|
||||
NumAtLeastEitherSign(width) => (SignDemand::NoDemand, width),
|
||||
_ => panic!(),
|
||||
};
|
||||
|
||||
let (actual_sign, _) = width.sign_and_width();
|
||||
|
@ -67,7 +63,7 @@ impl NumericBound {
|
|||
}
|
||||
|
||||
pub fn variable_slice(&self) -> &'static [Variable] {
|
||||
use NumericBound::*;
|
||||
use NumericRange::*;
|
||||
|
||||
match self {
|
||||
IntAtLeastSigned(width) => {
|
||||
|
@ -96,7 +92,6 @@ impl NumericBound {
|
|||
|
||||
&ALL_VARIABLES[start..]
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +262,7 @@ pub enum NumBound {
|
|||
},
|
||||
}
|
||||
|
||||
const fn int_width_to_variable(w: IntWidth) -> Variable {
|
||||
pub const fn int_width_to_variable(w: IntWidth) -> Variable {
|
||||
match w {
|
||||
IntWidth::U8 => Variable::U8,
|
||||
IntWidth::U16 => Variable::U16,
|
||||
|
@ -283,6 +278,14 @@ const fn int_width_to_variable(w: IntWidth) -> Variable {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn float_width_to_variable(w: FloatWidth) -> Variable {
|
||||
match w {
|
||||
FloatWidth::Dec => Variable::DEC,
|
||||
FloatWidth::F32 => Variable::F32,
|
||||
FloatWidth::F64 => Variable::F64,
|
||||
}
|
||||
}
|
||||
|
||||
const ALL_VARIABLES: &[Variable] = &[
|
||||
Variable::I8,
|
||||
Variable::U8,
|
||||
|
|
|
@ -2008,7 +2008,7 @@ pub enum Content {
|
|||
},
|
||||
Structure(FlatType),
|
||||
Alias(Symbol, AliasVariables, Variable, AliasKind),
|
||||
RangedNumber(Variable, crate::num::NumericBound),
|
||||
RangedNumber(Variable, crate::num::NumericRange),
|
||||
Error,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::num::NumericBound;
|
||||
use crate::num::NumericRange;
|
||||
use crate::pretty_print::Parens;
|
||||
use crate::subs::{
|
||||
GetSubsSlice, RecordFields, Subs, UnionTags, VarStore, Variable, VariableSubsSlice,
|
||||
|
@ -255,7 +255,7 @@ pub enum Type {
|
|||
/// Applying a type to some arguments (e.g. Dict.Dict String Int)
|
||||
Apply(Symbol, Vec<Type>, Region),
|
||||
Variable(Variable),
|
||||
RangedNumber(Box<Type>, NumericBound),
|
||||
RangedNumber(Box<Type>, NumericRange),
|
||||
/// A type error, which will code gen to a runtime error
|
||||
Erroneous(Problem),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue