Make floating-point operations work (neg, add, sub, mul, div, rem,
and comparison ops.)
This commit is contained in:
parent
caa22c9341
commit
1e1ff638a3
@ -2367,6 +2367,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
|
||||
@ast.expr e, &ast.ann a) -> result {
|
||||
|
||||
auto sub = trans_expr(cx, e);
|
||||
auto e_ty = ty.expr_ty(e);
|
||||
|
||||
alt (op) {
|
||||
case (ast.bitnot) {
|
||||
@ -2379,7 +2380,12 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
|
||||
}
|
||||
case (ast.neg) {
|
||||
sub = autoderef(sub.bcx, sub.val, ty.expr_ty(e));
|
||||
ret res(sub.bcx, sub.bcx.build.Neg(sub.val));
|
||||
if(e_ty.struct == ty.ty_float) {
|
||||
ret res(sub.bcx, sub.bcx.build.FNeg(sub.val));
|
||||
}
|
||||
else {
|
||||
ret res(sub.bcx, sub.bcx.build.Neg(sub.val));
|
||||
}
|
||||
}
|
||||
case (ast.box) {
|
||||
auto e_ty = ty.expr_ty(e);
|
||||
@ -2674,17 +2680,50 @@ fn trans_vec_add(@block_ctxt cx, @ty.t t,
|
||||
fn trans_eager_binop(@block_ctxt cx, ast.binop op, @ty.t intype,
|
||||
ValueRef lhs, ValueRef rhs) -> result {
|
||||
|
||||
auto is_float = false;
|
||||
alt(intype.struct) {
|
||||
case (ty.ty_float) {
|
||||
is_float = true;
|
||||
}
|
||||
case (_) {
|
||||
is_float = false;
|
||||
}
|
||||
}
|
||||
|
||||
alt (op) {
|
||||
case (ast.add) {
|
||||
if (ty.type_is_sequence(intype)) {
|
||||
ret trans_vec_add(cx, intype, lhs, rhs);
|
||||
}
|
||||
ret res(cx, cx.build.Add(lhs, rhs));
|
||||
if (is_float) {
|
||||
ret res(cx, cx.build.FAdd(lhs, rhs));
|
||||
}
|
||||
else {
|
||||
ret res(cx, cx.build.Add(lhs, rhs));
|
||||
}
|
||||
}
|
||||
case (ast.sub) {
|
||||
if (is_float) {
|
||||
ret res(cx, cx.build.FSub(lhs, rhs));
|
||||
}
|
||||
else {
|
||||
ret res(cx, cx.build.Sub(lhs, rhs));
|
||||
}
|
||||
}
|
||||
|
||||
case (ast.mul) {
|
||||
if (is_float) {
|
||||
ret res(cx, cx.build.FMul(lhs, rhs));
|
||||
}
|
||||
else {
|
||||
ret res(cx, cx.build.Mul(lhs, rhs));
|
||||
}
|
||||
}
|
||||
case (ast.sub) { ret res(cx, cx.build.Sub(lhs, rhs)); }
|
||||
|
||||
case (ast.mul) { ret res(cx, cx.build.Mul(lhs, rhs)); }
|
||||
case (ast.div) {
|
||||
if (is_float) {
|
||||
ret res(cx, cx.build.FDiv(lhs, rhs));
|
||||
}
|
||||
if (ty.type_is_signed(intype)) {
|
||||
ret res(cx, cx.build.SDiv(lhs, rhs));
|
||||
} else {
|
||||
@ -2692,6 +2731,9 @@ fn trans_eager_binop(@block_ctxt cx, ast.binop op, @ty.t intype,
|
||||
}
|
||||
}
|
||||
case (ast.rem) {
|
||||
if (is_float) {
|
||||
ret res(cx, cx.build.FRem(lhs, rhs));
|
||||
}
|
||||
if (ty.type_is_signed(intype)) {
|
||||
ret res(cx, cx.build.SRem(lhs, rhs));
|
||||
} else {
|
||||
|
@ -245,6 +245,7 @@ fn rewrap(@t orig, &sty new) -> @t {
|
||||
case (ty_bool) { ret fld.fold_simple_ty(ty); }
|
||||
case (ty_int) { ret fld.fold_simple_ty(ty); }
|
||||
case (ty_uint) { ret fld.fold_simple_ty(ty); }
|
||||
case (ty_float) { ret fld.fold_simple_ty(ty); }
|
||||
case (ty_machine(_)) { ret fld.fold_simple_ty(ty); }
|
||||
case (ty_char) { ret fld.fold_simple_ty(ty); }
|
||||
case (ty_str) { ret fld.fold_simple_ty(ty); }
|
||||
@ -503,6 +504,9 @@ fn type_is_fp(@t ty) -> bool {
|
||||
case (_) { ret false; }
|
||||
}
|
||||
}
|
||||
case (ty_float) {
|
||||
ret true;
|
||||
}
|
||||
case (_) { ret false; }
|
||||
}
|
||||
fail;
|
||||
@ -1126,6 +1130,7 @@ fn unify_step(@hashmap[int,@ty.t] bindings, @ty.t in_expected,
|
||||
case (ty.ty_int) { ret struct_cmp(expected, actual); }
|
||||
case (ty.ty_uint) { ret struct_cmp(expected, actual); }
|
||||
case (ty.ty_machine(_)) { ret struct_cmp(expected, actual); }
|
||||
case (ty.ty_float) { ret struct_cmp(expected, actual); }
|
||||
case (ty.ty_char) { ret struct_cmp(expected, actual); }
|
||||
case (ty.ty_str) { ret struct_cmp(expected, actual); }
|
||||
case (ty.ty_type) { ret struct_cmp(expected, actual); }
|
||||
|
Loading…
Reference in New Issue
Block a user