add Str.fromInt

This commit is contained in:
Folkert 2020-12-03 23:44:27 +01:00
parent 82e87d04e3
commit 4b0b5126a1
13 changed files with 124 additions and 4 deletions

View file

@ -10,6 +10,8 @@ use roc_builtins::bitcode;
use roc_module::symbol::Symbol;
use roc_mono::layout::{Builtin, Layout};
use super::build::load_symbol;
pub static CHAR_LAYOUT: Layout = Layout::Builtin(Builtin::Int8);
/// Str.split : Str, Str -> List Str
@ -212,3 +214,16 @@ pub fn str_count_graphemes<'a, 'ctx, 'env>(
&bitcode::STR_COUNT_GRAPEHEME_CLUSTERS,
)
}
/// Str.countGraphemes : Str -> Int
pub fn str_from_int<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
scope: &Scope<'a, 'ctx>,
int_symbol: Symbol,
) -> BasicValueEnum<'ctx> {
let int = load_symbol(env, scope, &int_symbol);
let zig_result = call_bitcode_fn(env, &[int], &bitcode::STR_FROM_INT).into_struct_value();
zig_str_to_struct(env, zig_result).into()
}