mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-14 07:29:02 +03:00
Implemenet code gen for int div
This commit is contained in:
parent
ace50f9aac
commit
aa72619952
@ -285,13 +285,19 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||
Box::new(SolvedType::Wildcard),
|
||||
);
|
||||
|
||||
// div : Int, Int -> Result Int [ DivByZero ]*
|
||||
// // div : Int, Int -> Result Int [ DivByZero ]*
|
||||
// add_type(
|
||||
// Symbol::INT_DIV,
|
||||
// SolvedType::Func(
|
||||
// vec![int_type(), int_type()],
|
||||
// Box::new(result_type(flex(TVAR1), div_by_zero.clone())),
|
||||
// ),
|
||||
// );
|
||||
|
||||
// div : Int, Int -> Int
|
||||
add_type(
|
||||
Symbol::INT_DIV,
|
||||
SolvedType::Func(
|
||||
vec![int_type(), int_type()],
|
||||
Box::new(result_type(flex(TVAR1), div_by_zero.clone())),
|
||||
),
|
||||
SolvedType::Func(vec![int_type(), int_type()], Box::new(int_type())),
|
||||
);
|
||||
|
||||
// mod : Int, Int -> Result Int [ DivByZero ]*
|
||||
|
@ -1226,6 +1226,17 @@ fn call_with_args<'a, 'ctx, 'env>(
|
||||
Symbol::FLOAT_ROUND => call_intrinsic(LLVM_LROUND_I64_F64, env, args),
|
||||
Symbol::LIST_SET => list_set(parent, args, env, InPlace::Clone),
|
||||
Symbol::LIST_SET_IN_PLACE => list_set(parent, args, env, InPlace::InPlace),
|
||||
Symbol::INT_DIV => {
|
||||
debug_assert!(args.len() == 2);
|
||||
|
||||
let int_val = env.builder.build_int_signed_div(
|
||||
args[0].0.into_int_value(),
|
||||
args[1].0.into_int_value(),
|
||||
"div_i64",
|
||||
);
|
||||
|
||||
BasicValueEnum::IntValue(int_val)
|
||||
}
|
||||
_ => {
|
||||
let fn_val = env
|
||||
.module
|
||||
|
@ -159,6 +159,19 @@ mod gen_builtins {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_div_i64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
1000 // 100
|
||||
"#
|
||||
),
|
||||
10,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_order_of_arithmetic_ops() {
|
||||
assert_evals_to!(
|
||||
|
Loading…
Reference in New Issue
Block a user