mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
f32FromParts and f64FromParts for repl
This commit is contained in:
parent
473b8ef2d3
commit
11998b9cc8
12 changed files with 48 additions and 4 deletions
|
@ -113,6 +113,8 @@ comptime {
|
||||||
exportNumFn(num.greaterThanOrEqualU128, "greater_than_or_equal.u128");
|
exportNumFn(num.greaterThanOrEqualU128, "greater_than_or_equal.u128");
|
||||||
exportNumFn(num.f32ToParts, "f32_to_parts");
|
exportNumFn(num.f32ToParts, "f32_to_parts");
|
||||||
exportNumFn(num.f64ToParts, "f64_to_parts");
|
exportNumFn(num.f64ToParts, "f64_to_parts");
|
||||||
|
exportNumFn(num.f32FromParts, "f32_from_parts");
|
||||||
|
exportNumFn(num.f64FromParts, "f64_from_parts");
|
||||||
|
|
||||||
inline for (INTEGERS, 0..) |T, i| {
|
inline for (INTEGERS, 0..) |T, i| {
|
||||||
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int.");
|
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int.");
|
||||||
|
|
|
@ -660,3 +660,11 @@ pub fn f64ToParts(self: f64) callconv(.C) F64Parts {
|
||||||
.sign = u64Value >> 63 & 1 == 1,
|
.sign = u64Value >> 63 & 1 == 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn f32FromParts(parts: F32Parts) callconv(.C) f32 {
|
||||||
|
return @as(f32, @bitCast(parts.fraction | (@as(u32, parts.exponent) << 23) | (@as(u32, @intFromBool(parts.sign)) << 31)));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn f64FromParts(parts: F64Parts) callconv(.C) f64 {
|
||||||
|
return @as(f64, @bitCast(parts.fraction | (@as(u64, parts.exponent) << 52) | (@as(u64, @intFromBool(parts.sign)) << 63)));
|
||||||
|
}
|
||||||
|
|
|
@ -153,7 +153,9 @@ interface Num
|
||||||
withoutDecimalPoint,
|
withoutDecimalPoint,
|
||||||
withDecimalPoint,
|
withDecimalPoint,
|
||||||
f32ToParts,
|
f32ToParts,
|
||||||
f64ToParts
|
f64ToParts,
|
||||||
|
f32FromParts,
|
||||||
|
f64FromParts
|
||||||
]
|
]
|
||||||
imports [
|
imports [
|
||||||
Bool.{ Bool },
|
Bool.{ Bool },
|
||||||
|
@ -1420,4 +1422,8 @@ withDecimalPoint : I128 -> Dec
|
||||||
|
|
||||||
f32ToParts: F32 -> { sign : Bool, exponent : U8, fraction : U32 }
|
f32ToParts: F32 -> { sign : Bool, exponent : U8, fraction : U32 }
|
||||||
|
|
||||||
f64ToParts: F64 -> { sign : Bool, exponent : U16, fraction : U64 }
|
f64ToParts: F64 -> { sign : Bool, exponent : U16, fraction : U64 }
|
||||||
|
|
||||||
|
f32FromParts: { sign : Bool, exponent : U8, fraction : U32 } -> F32
|
||||||
|
|
||||||
|
f64FromParts: { sign : Bool, exponent : U16, fraction : U64 } -> F64
|
|
@ -336,6 +336,8 @@ pub const NUM_COUNT_TRAILING_ZERO_BITS: IntrinsicName =
|
||||||
pub const NUM_COUNT_ONE_BITS: IntrinsicName = int_intrinsic!("roc_builtins.num.count_one_bits");
|
pub const NUM_COUNT_ONE_BITS: IntrinsicName = int_intrinsic!("roc_builtins.num.count_one_bits");
|
||||||
pub const NUM_F32_TO_PARTS: &str = "roc_builtins.num.f32_to_parts";
|
pub const NUM_F32_TO_PARTS: &str = "roc_builtins.num.f32_to_parts";
|
||||||
pub const NUM_F64_TO_PARTS: &str = "roc_builtins.num.f64_to_parts";
|
pub const NUM_F64_TO_PARTS: &str = "roc_builtins.num.f64_to_parts";
|
||||||
|
pub const NUM_F32_FROM_PARTS: &str = "roc_builtins.num.f32_from_parts";
|
||||||
|
pub const NUM_F64_FROM_PARTS: &str = "roc_builtins.num.f64_from_parts";
|
||||||
|
|
||||||
pub const STR_INIT: &str = "roc_builtins.str.init";
|
pub const STR_INIT: &str = "roc_builtins.str.init";
|
||||||
pub const STR_COUNT_SEGMENTS: &str = "roc_builtins.str.count_segments";
|
pub const STR_COUNT_SEGMENTS: &str = "roc_builtins.str.count_segments";
|
||||||
|
|
|
@ -209,6 +209,8 @@ map_symbol_to_lowlevel_and_arity! {
|
||||||
NumWithDecimalPoint; NUM_WITH_DECIMAL_POINT; 1,
|
NumWithDecimalPoint; NUM_WITH_DECIMAL_POINT; 1,
|
||||||
NumF32ToParts; NUM_F32_TO_PARTS; 1,
|
NumF32ToParts; NUM_F32_TO_PARTS; 1,
|
||||||
NumF64ToParts; NUM_F64_TO_PARTS; 1,
|
NumF64ToParts; NUM_F64_TO_PARTS; 1,
|
||||||
|
NumF32FromParts; NUM_F32_FROM_PARTS; 1,
|
||||||
|
NumF64FromParts; NUM_F64_FROM_PARTS; 1,
|
||||||
|
|
||||||
Eq; BOOL_STRUCTURAL_EQ; 2,
|
Eq; BOOL_STRUCTURAL_EQ; 2,
|
||||||
NotEq; BOOL_STRUCTURAL_NOT_EQ; 2,
|
NotEq; BOOL_STRUCTURAL_NOT_EQ; 2,
|
||||||
|
|
|
@ -2049,6 +2049,16 @@ trait Backend<'a> {
|
||||||
self.build_fn_call(sym, intrinsic, args, arg_layouts, ret_layout)
|
self.build_fn_call(sym, intrinsic, args, arg_layouts, ret_layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LowLevel::NumF32FromParts => {
|
||||||
|
let intrinsic = bitcode::NUM_F32_FROM_PARTS.to_string();
|
||||||
|
self.build_fn_call(sym, intrinsic, args, arg_layouts, ret_layout)
|
||||||
|
}
|
||||||
|
|
||||||
|
LowLevel::NumF64FromParts => {
|
||||||
|
let intrinsic = bitcode::NUM_F64_FROM_PARTS.to_string();
|
||||||
|
self.build_fn_call(sym, intrinsic, args, arg_layouts, ret_layout)
|
||||||
|
}
|
||||||
|
|
||||||
x => todo!("low level, {:?}", x),
|
x => todo!("low level, {:?}", x),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1178,6 +1178,8 @@ pub(crate) fn run_low_level<'a, 'ctx>(
|
||||||
}
|
}
|
||||||
NumF32ToParts => todo!("NumF32ToParts"),
|
NumF32ToParts => todo!("NumF32ToParts"),
|
||||||
NumF64ToParts => todo!("NumF64ToParts"),
|
NumF64ToParts => todo!("NumF64ToParts"),
|
||||||
|
NumF32FromParts => todo!("NumF32FromParts"),
|
||||||
|
NumF64FromParts => todo!("NumF64FromParts"),
|
||||||
Eq => {
|
Eq => {
|
||||||
arguments_with_layouts!((lhs_arg, lhs_layout), (rhs_arg, rhs_layout));
|
arguments_with_layouts!((lhs_arg, lhs_layout), (rhs_arg, rhs_layout));
|
||||||
|
|
||||||
|
|
|
@ -2105,6 +2105,8 @@ impl<'a> LowLevelCall<'a> {
|
||||||
}
|
}
|
||||||
NumF32ToParts => todo!("NumF32ToParts"),
|
NumF32ToParts => todo!("NumF32ToParts"),
|
||||||
NumF64ToParts => todo!("NumF64ToParts"),
|
NumF64ToParts => todo!("NumF64ToParts"),
|
||||||
|
NumF32FromParts => todo!("NumF32FromParts"),
|
||||||
|
NumF64FromParts => todo!("NumF64FromParts"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,8 @@ pub enum LowLevel {
|
||||||
NumWithDecimalPoint,
|
NumWithDecimalPoint,
|
||||||
NumF32ToParts,
|
NumF32ToParts,
|
||||||
NumF64ToParts,
|
NumF64ToParts,
|
||||||
|
NumF32FromParts,
|
||||||
|
NumF64FromParts,
|
||||||
I128OfDec,
|
I128OfDec,
|
||||||
Eq,
|
Eq,
|
||||||
NotEq,
|
NotEq,
|
||||||
|
@ -345,6 +347,8 @@ map_symbol_to_lowlevel! {
|
||||||
NumWithDecimalPoint <= NUM_WITH_DECIMAL_POINT;
|
NumWithDecimalPoint <= NUM_WITH_DECIMAL_POINT;
|
||||||
NumF32ToParts <= NUM_F32_TO_PARTS;
|
NumF32ToParts <= NUM_F32_TO_PARTS;
|
||||||
NumF64ToParts <= NUM_F64_TO_PARTS;
|
NumF64ToParts <= NUM_F64_TO_PARTS;
|
||||||
|
NumF32FromParts <= NUM_F32_FROM_PARTS;
|
||||||
|
NumF64FromParts <= NUM_F64_FROM_PARTS;
|
||||||
Eq <= BOOL_STRUCTURAL_EQ;
|
Eq <= BOOL_STRUCTURAL_EQ;
|
||||||
NotEq <= BOOL_STRUCTURAL_NOT_EQ;
|
NotEq <= BOOL_STRUCTURAL_NOT_EQ;
|
||||||
And <= BOOL_AND;
|
And <= BOOL_AND;
|
||||||
|
|
|
@ -1272,6 +1272,8 @@ define_builtins! {
|
||||||
160 NUM_WITH_DECIMAL_POINT: "withDecimalPoint"
|
160 NUM_WITH_DECIMAL_POINT: "withDecimalPoint"
|
||||||
161 NUM_F32_TO_PARTS: "f32ToParts"
|
161 NUM_F32_TO_PARTS: "f32ToParts"
|
||||||
162 NUM_F64_TO_PARTS: "f64ToParts"
|
162 NUM_F64_TO_PARTS: "f64ToParts"
|
||||||
|
163 NUM_F32_FROM_PARTS: "f32FromParts"
|
||||||
|
164 NUM_F64_FROM_PARTS: "f64FromParts"
|
||||||
}
|
}
|
||||||
4 BOOL: "Bool" => {
|
4 BOOL: "Bool" => {
|
||||||
0 BOOL_BOOL: "Bool" exposed_type=true // the Bool.Bool type alias
|
0 BOOL_BOOL: "Bool" exposed_type=true // the Bool.Bool type alias
|
||||||
|
|
|
@ -1594,7 +1594,9 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
|
||||||
| NumCountTrailingZeroBits
|
| NumCountTrailingZeroBits
|
||||||
| NumCountOneBits
|
| NumCountOneBits
|
||||||
| NumF32ToParts
|
| NumF32ToParts
|
||||||
| NumF64ToParts => RC::NoRc,
|
| NumF64ToParts
|
||||||
|
| NumF32FromParts
|
||||||
|
| NumF64FromParts => RC::NoRc,
|
||||||
I128OfDec | NumWithoutDecimalPoint | NumWithDecimalPoint => RC::NoRc,
|
I128OfDec | NumWithoutDecimalPoint | NumWithDecimalPoint => RC::NoRc,
|
||||||
DictPseudoSeed => RC::NoRc,
|
DictPseudoSeed => RC::NoRc,
|
||||||
StrStartsWith | StrEndsWith => RC::NoRc,
|
StrStartsWith | StrEndsWith => RC::NoRc,
|
||||||
|
|
|
@ -1349,7 +1349,9 @@ pub(crate) fn lowlevel_borrow_signature(op: LowLevel) -> &'static [Ownership] {
|
||||||
| NumWithoutDecimalPoint
|
| NumWithoutDecimalPoint
|
||||||
| NumWithDecimalPoint
|
| NumWithDecimalPoint
|
||||||
| NumF32ToParts
|
| NumF32ToParts
|
||||||
| NumF64ToParts => &[IRRELEVANT],
|
| NumF64ToParts
|
||||||
|
| NumF32FromParts
|
||||||
|
| NumF64FromParts => &[IRRELEVANT],
|
||||||
StrStartsWith | StrEndsWith => &[BORROWED, BORROWED],
|
StrStartsWith | StrEndsWith => &[BORROWED, BORROWED],
|
||||||
StrFromUtf8 => &[OWNED],
|
StrFromUtf8 => &[OWNED],
|
||||||
StrToUtf8 => &[OWNED],
|
StrToUtf8 => &[OWNED],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue