mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Also store f64 for things like pattern comparisons, etc
This commit is contained in:
parent
adabf70132
commit
d69b9173fc
18 changed files with 195 additions and 252 deletions
|
@ -54,6 +54,7 @@ use roc_mono::ir::{
|
|||
BranchInfo, CallType, EntryPoint, ExceptionId, JoinPointId, ModifyRc, OptLevel, ProcLayout,
|
||||
};
|
||||
use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds, UnionLayout};
|
||||
use roc_std::RocDec;
|
||||
|
||||
/// This is for Inkwell's FunctionValue::verify - we want to know the verification
|
||||
/// output in debug builds, but we don't want it to print to stdout in release builds!
|
||||
|
@ -620,15 +621,18 @@ pub fn int_with_precision<'a, 'ctx, 'env>(
|
|||
|
||||
pub fn float_with_precision<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
value_str: &str,
|
||||
value: f64,
|
||||
precision: &Builtin,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
match precision {
|
||||
Builtin::Decimal => call_bitcode_fn(
|
||||
env,
|
||||
&[env.context.f64_type().const_float(value).into()],
|
||||
bitcode::DEC_FROM_F64,
|
||||
),
|
||||
Builtin::Decimal => {
|
||||
let dec = match RocDec::from_str(value_str) {
|
||||
Some(d) => d.0,
|
||||
None => panic!("Invalid decimal for float literal = {}. TODO: Make this a nice, user-friendly error message", value),
|
||||
};
|
||||
env.context.i128_type().const_int(dec as u64, false).into()
|
||||
}
|
||||
Builtin::Float64 => env.context.f64_type().const_float(value).into(),
|
||||
Builtin::Float32 => env.context.f32_type().const_float(value).into(),
|
||||
_ => panic!("Invalid layout for float literal = {:?}", precision),
|
||||
|
@ -648,8 +652,8 @@ pub fn build_exp_literal<'a, 'ctx, 'env>(
|
|||
_ => panic!("Invalid layout for int literal = {:?}", layout),
|
||||
},
|
||||
|
||||
Float(float) => match layout {
|
||||
Layout::Builtin(builtin) => float_with_precision(env, *float, builtin),
|
||||
Float(float_str, float) => match layout {
|
||||
Layout::Builtin(builtin) => float_with_precision(env, *float_str, *float, builtin),
|
||||
_ => panic!("Invalid layout for float literal = {:?}", layout),
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue