mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
feat: Num.toStr
* add type for Num.toStr * create new lowlevel * delete types and Symbol for fromInt and fromFloat * leave LowLevel::{StrFromFloat,StrFromInt} * match on LowLevel::NumToStr and figure out the layout to decide which build function to delegate to
This commit is contained in:
parent
d67cc883ca
commit
f995a07029
8 changed files with 65 additions and 75 deletions
|
@ -5522,6 +5522,24 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
|
||||
list_join(env, parent, list, outer_list_layout)
|
||||
}
|
||||
NumToStr => {
|
||||
// Num.toStr : Num a -> Str
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
||||
let (num, num_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
|
||||
match num_layout {
|
||||
Layout::Builtin(Builtin::Int(int_width)) => {
|
||||
let int = num.into_int_value();
|
||||
|
||||
str_from_int(env, int, *int_width)
|
||||
}
|
||||
Layout::Builtin(Builtin::Float(_float_width)) => {
|
||||
str_from_float(env, scope, args[0])
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
NumAbs | NumNeg | NumRound | NumSqrtUnchecked | NumLogUnchecked | NumSin | NumCos
|
||||
| NumCeiling | NumFloor | NumToFloat | NumIsFinite | NumAtan | NumAcos | NumAsin => {
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
|
|
@ -406,7 +406,7 @@ pub fn str_from_utf8<'a, 'ctx, 'env>(
|
|||
decode_from_utf8_result(env, result_ptr).into()
|
||||
}
|
||||
|
||||
/// Str.fromInt : Int -> Str
|
||||
/// Str.fromFloat : Int -> Str
|
||||
pub fn str_from_float<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue