started on Str.toNum

This commit is contained in:
Anton-4 2021-12-01 15:15:30 +01:00
parent 68e2701948
commit eaf4e57759
7 changed files with 29 additions and 0 deletions

View file

@ -5363,6 +5363,12 @@ fn run_low_level<'a, 'ctx, 'env>(
str_trim_right(env, scope, args[0])
}
StrToNum => {
// Str.toNum : Str -> Result (Num a) [ ExpectedNum a ]*
debug_assert_eq!(args.len(), 1);
str_to_num(env, scope, args[0])
}
ListLen => {
// List.len : List * -> Int
debug_assert_eq!(args.len(), 1);

View file

@ -441,3 +441,13 @@ pub fn empty_str<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValueEnum<'c
// so the whole struct should be a const_zero
BasicValueEnum::StructValue(struct_type.const_zero())
}
/// Str.toNum : Str -> Result (Num a) [ ExpectedNum a ]*
pub fn str_to_num<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
scope: &Scope<'a, 'ctx>,
str_symbol: Symbol,
) -> BasicValueEnum<'ctx> {
let str_i128 = str_symbol_to_c_abi(env, scope, str_symbol);
call_bitcode_fn(env, &[str_i128.into()], bitcode::STR_TRIM_RIGHT)
}