diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 690dbbfc0c..d272248265 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -251,8 +251,8 @@ fn num_binop(symbol: Symbol, var_store: &mut VarStore, op: LowLevel) -> Def { ) } -/// Num a, Num a -> Bool -fn num_bool_binop(symbol: Symbol, var_store: &mut VarStore, op: LowLevel) -> Def { +/// Num a, Num a -> b +fn num_num_other_binop(symbol: Symbol, var_store: &mut VarStore, op: LowLevel) -> Def { let num_var = var_store.fresh(); let bool_var = var_store.fresh(); let body = RunLowLevel { @@ -381,27 +381,27 @@ fn num_mul(symbol: Symbol, var_store: &mut VarStore) -> Def { /// Num.isGt : Num a, Num a -> Bool fn num_gt(symbol: Symbol, var_store: &mut VarStore) -> Def { - num_bool_binop(symbol, var_store, LowLevel::NumGt) + num_num_other_binop(symbol, var_store, LowLevel::NumGt) } /// Num.isGte : Num a, Num a -> Bool fn num_gte(symbol: Symbol, var_store: &mut VarStore) -> Def { - num_bool_binop(symbol, var_store, LowLevel::NumGte) + num_num_other_binop(symbol, var_store, LowLevel::NumGte) } /// Num.isLt : Num a, Num a -> Bool fn num_lt(symbol: Symbol, var_store: &mut VarStore) -> Def { - num_bool_binop(symbol, var_store, LowLevel::NumLt) + num_num_other_binop(symbol, var_store, LowLevel::NumLt) } -/// Num.isLte : Num a, Num a -> Num a +/// Num.isLte : Num a, Num a -> Bool fn num_lte(symbol: Symbol, var_store: &mut VarStore) -> Def { - num_bool_binop(symbol, var_store, LowLevel::NumLte) + num_num_other_binop(symbol, var_store, LowLevel::NumLte) } /// Num.compare : Num a, Num a -> [ LT, EQ, GT ] fn num_compare(symbol: Symbol, var_store: &mut VarStore) -> Def { - num_bool_binop(symbol, var_store, LowLevel::NumCompare) + num_num_other_binop(symbol, var_store, LowLevel::NumCompare) } /// Num.sin : Float -> Float diff --git a/compiler/gen/tests/gen_num.rs b/compiler/gen/tests/gen_num.rs index fe6799a7a4..a155e90891 100644 --- a/compiler/gen/tests/gen_num.rs +++ b/compiler/gen/tests/gen_num.rs @@ -13,15 +13,7 @@ mod helpers; #[cfg(test)] mod gen_num { - /* - use inkwell::passes::PassManager; - use inkwell::types::BasicType; - use inkwell::OptimizationLevel; - use roc_gen::llvm::build::{build_proc, build_proc_header}; - use roc_gen::llvm::convert::basic_type_from_layout; - use roc_mono::layout::Layout; - use roc_types::subs::Subs; - */ + use roc_std::RocOrder; #[test] fn f64_sqrt() { @@ -584,86 +576,16 @@ mod gen_num { #[test] fn int_compare() { - assert_evals_to!( - indoc!( - r#" - when Num.compare 0 1 is - LT -> 0 - EQ -> 1 - GT -> 2 - "# - ), - 0, - i64 - ); - - assert_evals_to!( - indoc!( - r#" - when Num.compare 1 1 is - LT -> 0 - EQ -> 1 - GT -> 2 - "# - ), - 1, - i64 - ); - - assert_evals_to!( - indoc!( - r#" - when Num.compare 1 0 is - LT -> 0 - EQ -> 1 - GT -> 2 - "# - ), - 2, - i64 - ); + assert_evals_to!("Num.compare 0 1", RocOrder::Lt, RocOrder); + assert_evals_to!("Num.compare 1 1", RocOrder::Eq, RocOrder); + assert_evals_to!("Num.compare 1 0", RocOrder::Gt, RocOrder); } #[test] fn float_compare() { - assert_evals_to!( - indoc!( - r#" - when Num.compare 0 3.14 is - LT -> 0 - EQ -> 1 - GT -> 2 - "# - ), - 0, - i64 - ); - - assert_evals_to!( - indoc!( - r#" - when Num.compare 3.14 3.14 is - LT -> 0 - EQ -> 1 - GT -> 2 - "# - ), - 1, - i64 - ); - - assert_evals_to!( - indoc!( - r#" - when Num.compare 3.14 0 is - LT -> 0 - EQ -> 1 - GT -> 2 - "# - ), - 2, - i64 - ); + assert_evals_to!("Num.compare 0.01 3.14", RocOrder::Lt, RocOrder); + assert_evals_to!("Num.compare 3.14 3.14", RocOrder::Eq, RocOrder); + assert_evals_to!("Num.compare 3.14 0.01", RocOrder::Gt, RocOrder); } #[test] diff --git a/roc_std/src/lib.rs b/roc_std/src/lib.rs index a501f7f26c..50f9fcbd86 100644 --- a/roc_std/src/lib.rs +++ b/roc_std/src/lib.rs @@ -11,6 +11,14 @@ extern "C" { const REFCOUNT_1: usize = isize::MIN as usize; +#[repr(u8)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum RocOrder { + Eq = 0, + Gt = 1, + Lt = 2, +} + //#[macro_export] //macro_rules! roclist { // () => (