Support Num.toStr for dec

This commit is contained in:
Ayaz Hafiz 2022-07-13 12:13:21 -04:00
parent b7c312d449
commit 66b8d145a9
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
6 changed files with 53 additions and 4 deletions

View file

@ -112,10 +112,28 @@ pub fn str_from_float<'a, 'ctx, 'env>(
call_str_bitcode_fn(env, &[float], &bitcode::STR_FROM_FLOAT[float_width])
}
/// Dec.toStr : Dec -> Str
pub fn dec_to_str<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
dec: BasicValueEnum<'ctx>,
) -> BasicValueEnum<'ctx> {
let float = load_symbol(scope, &int_symbol);
let dec = dec.into_int_value();
call_str_bitcode_fn(env, &[float], bitcode::STR_FROM_FLOAT)
let int_64 = env.context.i128_type().const_int(64, false);
let int_64_type = env.context.i64_type();
let dec_right_shift = env
.builder
.build_right_shift(dec, int_64, false, "dec_left_bits");
let right_bits = env.builder.build_int_cast(dec, int_64_type, "");
let left_bits = env.builder.build_int_cast(dec_right_shift, int_64_type, "");
call_str_bitcode_fn(
env,
&[right_bits.into(), left_bits.into()],
bitcode::DEC_TO_STR,
)
}
/// Str.equal : Str, Str -> Bool