implement Num.toStr for the dev backend

This commit is contained in:
Folkert 2023-04-23 18:04:34 +02:00
parent f7e3254a35
commit f45e4ed858
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 12 additions and 1 deletions

View file

@ -1109,6 +1109,17 @@ trait Backend<'a> {
arg_layouts,
ret_layout,
),
LowLevel::NumToStr => {
let arg_layout = arg_layouts[0];
let intrinsic = match self.interner().get(arg_layout) {
Layout::Builtin(Builtin::Int(width)) => &bitcode::STR_FROM_INT[width],
Layout::Builtin(Builtin::Float(width)) => &bitcode::STR_FROM_FLOAT[width],
Layout::Builtin(Builtin::Decimal) => bitcode::DEC_TO_STR,
x => internal_error!("NumToStr is not defined for {:?}", x),
};
self.build_fn_call(sym, intrinsic.to_string(), args, arg_layouts, ret_layout)
}
x => todo!("low level, {:?}", x),
}
}

View file

@ -3113,7 +3113,7 @@ fn when_on_i16() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn num_to_str() {
use roc_std::RocStr;