mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
add new layer to the Num types
This commit is contained in:
parent
4d692af639
commit
aa4b376134
10 changed files with 441 additions and 92 deletions
|
@ -38,143 +38,213 @@ pub fn aliases() -> MutMap<Symbol, BuiltinAlias> {
|
|||
},
|
||||
);
|
||||
|
||||
// Integer : [ @Integer ]
|
||||
// Integer range : [ @Integer range ]
|
||||
add_alias(
|
||||
Symbol::NUM_INTEGER,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: integer_alias_content(),
|
||||
vars: vec![Located::at(Region::zero(), "range".into())],
|
||||
typ: integer_alias_content(flex(TVAR1)),
|
||||
},
|
||||
);
|
||||
|
||||
// I128 Num Integer
|
||||
// Signed128 : [ @Signed128 ]
|
||||
add_alias(
|
||||
Symbol::NUM_SIGNED128,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: signed128_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I128 : Num (Integer Signed128)
|
||||
add_alias(
|
||||
Symbol::NUM_I128,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(signed128_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// U128 : Num Integer
|
||||
// U128 : Num (Integer Unsigned128)
|
||||
add_alias(
|
||||
Symbol::NUM_U128,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(unsigned128_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// I64 Num Integer
|
||||
// Signed64 : [ @Signed64 ]
|
||||
add_alias(
|
||||
Symbol::NUM_SIGNED64,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: signed64_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I64 : Num (Integer Signed64)
|
||||
add_alias(
|
||||
Symbol::NUM_I64,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(signed64_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// U64 : Num Integer
|
||||
// U64 : Num (Integer Unsigned64)
|
||||
add_alias(
|
||||
Symbol::NUM_U64,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(unsigned64_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// I32 Num Integer
|
||||
// Signed32 : [ @Signed32 ]
|
||||
add_alias(
|
||||
Symbol::NUM_SIGNED32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: signed32_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I32 : Num (Integer Signed32)
|
||||
add_alias(
|
||||
Symbol::NUM_I32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(signed32_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// U32 : Num Integer
|
||||
// U32 : Num (Integer Unsigned32)
|
||||
add_alias(
|
||||
Symbol::NUM_U32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(unsigned32_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// I16 Num Integer
|
||||
// Signed16 : [ @Signed16 ]
|
||||
add_alias(
|
||||
Symbol::NUM_SIGNED16,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: signed16_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I16 : Num (Integer Signed16)
|
||||
add_alias(
|
||||
Symbol::NUM_I16,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(signed16_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// U16 : Num Integer
|
||||
// U16 : Num (Integer Unsigned16)
|
||||
add_alias(
|
||||
Symbol::NUM_U16,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(unsigned16_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// I8 Num Integer
|
||||
// Signed8 : [ @Signed8 ]
|
||||
add_alias(
|
||||
Symbol::NUM_SIGNED8,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: signed8_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// I8 : Num (Integer Signed8)
|
||||
add_alias(
|
||||
Symbol::NUM_I8,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(signed8_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// U8 : Num Integer
|
||||
// U8 : Num (Integer Unsigned8)
|
||||
add_alias(
|
||||
Symbol::NUM_U8,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: int_alias_content(),
|
||||
typ: int_alias_content(unsigned8_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// FloatingPoint : [ @FloatingPoint ]
|
||||
// Binary64 : [ @Binary64 ]
|
||||
add_alias(
|
||||
Symbol::NUM_BINARY64,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: binary64_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// Binary32 : [ @Binary32 ]
|
||||
add_alias(
|
||||
Symbol::NUM_BINARY32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: vec![],
|
||||
typ: binary32_alias_content(),
|
||||
},
|
||||
);
|
||||
|
||||
// FloatingPoint range : [ @FloatingPoint range ]
|
||||
add_alias(
|
||||
Symbol::NUM_FLOATINGPOINT,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: floatingpoint_alias_content(),
|
||||
vars: vec![Located::at(Region::zero(), "range".into())],
|
||||
typ: floatingpoint_alias_content(flex(TVAR1)),
|
||||
},
|
||||
);
|
||||
|
||||
// F64 : Num FloatingPoint
|
||||
// F64 : Num (FloatingPoint Binary64)
|
||||
add_alias(
|
||||
Symbol::NUM_F64,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: float_alias_content(),
|
||||
typ: float_alias_content(binary64_type()),
|
||||
},
|
||||
);
|
||||
|
||||
// F32 : Num FloatingPoint
|
||||
// F32 : Num (FloatingPoint Binary32)
|
||||
add_alias(
|
||||
Symbol::NUM_F32,
|
||||
BuiltinAlias {
|
||||
region: Region::zero(),
|
||||
vars: Vec::new(),
|
||||
typ: float_alias_content(),
|
||||
typ: float_alias_content(binary32_type()),
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -226,57 +296,233 @@ fn num_alias_content(range: SolvedType) -> SolvedType {
|
|||
// FLOATING POINT
|
||||
|
||||
#[inline(always)]
|
||||
pub fn floatingpoint_type() -> SolvedType {
|
||||
pub fn floatingpoint_type(range: SolvedType) -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_FLOATINGPOINT,
|
||||
Vec::new(),
|
||||
Box::new(floatingpoint_alias_content()),
|
||||
vec![("range".into(), range.clone())],
|
||||
Box::new(floatingpoint_alias_content(range)),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn floatingpoint_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_FLOATINGPOINT, Vec::new())
|
||||
fn floatingpoint_alias_content(range: SolvedType) -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_FLOATINGPOINT, vec![range])
|
||||
}
|
||||
|
||||
// FLOAT
|
||||
|
||||
#[inline(always)]
|
||||
pub fn float_type() -> SolvedType {
|
||||
SolvedType::Alias(Symbol::NUM_F64, Vec::new(), Box::new(float_alias_content()))
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_F64,
|
||||
Vec::new(),
|
||||
Box::new(float_alias_content(binary64_type())),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn float_alias_content() -> SolvedType {
|
||||
num_type(floatingpoint_type())
|
||||
fn float_alias_content(typ: SolvedType) -> SolvedType {
|
||||
num_type(floatingpoint_type(typ))
|
||||
}
|
||||
|
||||
// INT
|
||||
|
||||
#[inline(always)]
|
||||
pub fn int_type() -> SolvedType {
|
||||
SolvedType::Alias(Symbol::NUM_I64, Vec::new(), Box::new(int_alias_content()))
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_I64,
|
||||
Vec::new(),
|
||||
Box::new(int_alias_content(signed64_type())),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn int_alias_content() -> SolvedType {
|
||||
num_type(integer_type())
|
||||
fn int_alias_content(range: SolvedType) -> SolvedType {
|
||||
num_type(integer_type(range))
|
||||
}
|
||||
|
||||
// INTEGER
|
||||
|
||||
#[inline(always)]
|
||||
pub fn integer_type() -> SolvedType {
|
||||
pub fn integer_type(range: SolvedType) -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_INTEGER,
|
||||
Vec::new(),
|
||||
Box::new(integer_alias_content()),
|
||||
vec![("range".into(), range.clone())],
|
||||
Box::new(integer_alias_content(range)),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn integer_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_INTEGER, Vec::new())
|
||||
fn integer_alias_content(range: SolvedType) -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_INTEGER, vec![range])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn binary64_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_BINARY64,
|
||||
vec![],
|
||||
Box::new(binary64_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn binary64_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_BINARY64, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn binary32_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_BINARY32,
|
||||
vec![],
|
||||
Box::new(binary32_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn binary32_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_BINARY32, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn signed128_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_SIGNED128,
|
||||
vec![],
|
||||
Box::new(signed128_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn signed128_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_SIGNED128, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn signed64_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_SIGNED64,
|
||||
vec![],
|
||||
Box::new(signed64_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn signed64_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_SIGNED64, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn signed32_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_SIGNED32,
|
||||
vec![],
|
||||
Box::new(signed32_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn signed32_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_SIGNED32, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn signed16_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_SIGNED16,
|
||||
vec![],
|
||||
Box::new(signed16_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn signed16_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_SIGNED16, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn signed8_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_SIGNED8,
|
||||
vec![],
|
||||
Box::new(signed8_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn signed8_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_SIGNED8, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unsigned128_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_UNSIGNED128,
|
||||
vec![],
|
||||
Box::new(unsigned128_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unsigned128_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_UNSIGNED128, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unsigned64_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_UNSIGNED64,
|
||||
vec![],
|
||||
Box::new(unsigned64_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unsigned64_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_UNSIGNED64, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unsigned32_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_UNSIGNED32,
|
||||
vec![],
|
||||
Box::new(unsigned32_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unsigned32_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_UNSIGNED32, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unsigned16_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_UNSIGNED16,
|
||||
vec![],
|
||||
Box::new(unsigned16_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unsigned16_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_UNSIGNED16, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn unsigned8_type() -> SolvedType {
|
||||
SolvedType::Alias(
|
||||
Symbol::NUM_UNSIGNED8,
|
||||
vec![],
|
||||
Box::new(unsigned8_alias_content()),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unsigned8_alias_content() -> SolvedType {
|
||||
single_private_tag(Symbol::NUM_AT_UNSIGNED8, vec![])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue