mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
isZero, isPositive, isNegative
This commit is contained in:
parent
40cd77ec95
commit
a01bdd66c5
6 changed files with 198 additions and 87 deletions
|
@ -34,9 +34,60 @@ pub fn builtin_defs(var_store: &VarStore) -> Vec<Def> {
|
|||
int_rem(var_store),
|
||||
int_is_odd(var_store),
|
||||
int_is_even(var_store),
|
||||
int_is_zero(var_store),
|
||||
int_is_positive(var_store),
|
||||
int_is_negative(var_store),
|
||||
]
|
||||
}
|
||||
|
||||
/// Int.isNegative : Int -> Bool
|
||||
fn int_is_negative(var_store: &VarStore) -> Def {
|
||||
use crate::expr::Expr::*;
|
||||
|
||||
defn(
|
||||
Symbol::INT_IS_NEGATIVE,
|
||||
vec![Symbol::INT_IS_NEGATIVE_ARG],
|
||||
var_store,
|
||||
call(
|
||||
Symbol::NUM_LT,
|
||||
vec![Var(Symbol::INT_IS_NEGATIVE_ARG), Int(var_store.fresh(), 0)],
|
||||
var_store,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Int.isPositive : Int -> Bool
|
||||
fn int_is_positive(var_store: &VarStore) -> Def {
|
||||
use crate::expr::Expr::*;
|
||||
|
||||
defn(
|
||||
Symbol::INT_IS_POSITIVE,
|
||||
vec![Symbol::INT_IS_POSITIVE_ARG],
|
||||
var_store,
|
||||
call(
|
||||
Symbol::NUM_GT,
|
||||
vec![Var(Symbol::INT_IS_POSITIVE_ARG), Int(var_store.fresh(), 0)],
|
||||
var_store,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Int.isZero : Int -> Bool
|
||||
fn int_is_zero(var_store: &VarStore) -> Def {
|
||||
use crate::expr::Expr::*;
|
||||
|
||||
defn(
|
||||
Symbol::INT_IS_ZERO,
|
||||
vec![Symbol::INT_IS_ZERO_ARG],
|
||||
var_store,
|
||||
call(
|
||||
Symbol::INT_EQ_I64,
|
||||
vec![Var(Symbol::INT_IS_ZERO_ARG), Int(var_store.fresh(), 0)],
|
||||
var_store,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Int.isOdd : Int -> Bool
|
||||
fn int_is_odd(var_store: &VarStore) -> Def {
|
||||
use crate::expr::Expr::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue