Float.div implemented, Int.div WIP-ish

This commit is contained in:
Mario Rogic 2020-03-08 18:32:48 +00:00
parent 17e9f0b8c3
commit a5c2844f54
4 changed files with 69 additions and 7 deletions

View file

@ -574,6 +574,20 @@ fn call_by_name<'a, B: Backend>(
builder.ins().ineg(num)
}
Symbol::FLOAT_DIV => {
debug_assert!(args.len() == 2);
let a = build_arg(&args[0], env, scope, module, builder, procs);
let b = build_arg(&args[1], env, scope, module, builder, procs);
builder.ins().fdiv(a, b)
}
// Symbol::INT_DIV => {
// debug_assert!(args.len() == 2);
// let a = build_arg(&args[0], env, scope, module, builder, procs);
// let b = build_arg(&args[1], env, scope, module, builder, procs);
//
// builder.ins().sdiv(a, b)
// }
Symbol::LIST_GET_UNSAFE => {
debug_assert!(args.len() == 2);

View file

@ -578,6 +578,28 @@ fn call_with_args<'a, 'ctx, 'env>(
BasicValueEnum::IntValue(int_val)
}
Symbol::FLOAT_DIV => {
debug_assert!(args.len() == 2);
let float_val = env.builder.build_float_div(
args[0].into_float_value(),
args[1].into_float_value(),
"DIV_F64",
);
BasicValueEnum::FloatValue(float_val)
}
// Symbol::INT_DIV => {
// debug_assert!(args.len() == 2);
//
// let int_val = env.builder.build_int_signed_div(
// args[0].into_int_value(),
// args[1].into_int_value(),
// "DIV_I64",
// );
//
// BasicValueEnum::IntValue(int_val)
// }
Symbol::LIST_GET_UNSAFE => {
debug_assert!(args.len() == 2);

View file

@ -838,6 +838,19 @@ mod test_gen {
);
}
#[test]
fn gen_div_f64() {
assert_evals_to!(
indoc!(
r#"
48.0 / 2.0
"#
),
24.0,
f64
);
}
#[test]
fn gen_order_of_arithmetic_ops() {
assert_evals_to!(
@ -853,15 +866,28 @@ mod test_gen {
#[test]
// https://math.berkeley.edu/~gbergman/misc/numbers/ord_ops.html
fn gen_order_of_arithmetic_ops_complex() {
// fn gen_order_of_arithmetic_ops_complex() {
// assert_evals_to!(
// indoc!(
// r#"
// 48 / 2 * (9 + 3)
// "#
// ),
// 288,
// i64
// );
// }
#[test]
fn gen_order_of_arithmetic_ops_complex_float() {
assert_evals_to!(
indoc!(
r#"
48 / 2 * (9 + 3)
48.0 / 2.0 + 3.0
"#
),
288,
i64
24.0,
f64
);
}