@@ -1536,63 +1536,49 @@ fn compare_scalar_types(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
1536
1536
// A helper function to do the actual comparison of scalar values.
1537
1537
fn compare_scalar_values ( cx : @block_ctxt , lhs : ValueRef , rhs : ValueRef ,
1538
1538
nt : scalar_type , op : ast:: binop ) -> ValueRef {
1539
- let cmp = alt nt {
1539
+ alt nt {
1540
1540
nil_type. {
1541
1541
// We don't need to do actual comparisons for nil.
1542
1542
// () == () holds but () < () does not.
1543
1543
alt op {
1544
- ast : : eq. | ast:: le. | ast:: ge. { 1 u }
1545
- ast:: ne. | ast:: lt. | ast:: gt. { 0 u }
1544
+ ast : : eq. | ast:: le. | ast:: ge. { ret C_bool ( true ) ; }
1545
+ ast:: ne. | ast:: lt. | ast:: gt. { ret C_bool ( false ) ; }
1546
1546
}
1547
1547
}
1548
1548
floating_point. {
1549
- alt op {
1549
+ let cmp = alt op {
1550
1550
ast : : eq. { lib:: llvm:: LLVMRealOEQ }
1551
1551
ast:: ne. { lib:: llvm:: LLVMRealUNE }
1552
1552
ast:: lt. { lib:: llvm:: LLVMRealOLT }
1553
1553
ast:: le. { lib:: llvm:: LLVMRealOLE }
1554
1554
ast:: gt. { lib:: llvm:: LLVMRealOGT }
1555
1555
ast:: ge. { lib:: llvm:: LLVMRealOGE }
1556
- }
1556
+ } ;
1557
+ ret FCmp ( cx, cmp, lhs, rhs) ;
1557
1558
}
1558
1559
signed_int. {
1559
- alt op {
1560
+ let cmp = alt op {
1560
1561
ast : : eq. { lib:: llvm:: LLVMIntEQ }
1561
1562
ast:: ne. { lib:: llvm:: LLVMIntNE }
1562
1563
ast:: lt. { lib:: llvm:: LLVMIntSLT }
1563
1564
ast:: le. { lib:: llvm:: LLVMIntSLE }
1564
1565
ast:: gt. { lib:: llvm:: LLVMIntSGT }
1565
1566
ast:: ge. { lib:: llvm:: LLVMIntSGE }
1566
- }
1567
+ } ;
1568
+ ret ICmp ( cx, cmp, lhs, rhs) ;
1567
1569
}
1568
1570
unsigned_int. {
1569
- alt op {
1571
+ let cmp = alt op {
1570
1572
ast : : eq. { lib:: llvm:: LLVMIntEQ }
1571
1573
ast:: ne. { lib:: llvm:: LLVMIntNE }
1572
1574
ast:: lt. { lib:: llvm:: LLVMIntULT }
1573
1575
ast:: le. { lib:: llvm:: LLVMIntULE }
1574
1576
ast:: gt. { lib:: llvm:: LLVMIntUGT }
1575
1577
ast:: ge. { lib:: llvm:: LLVMIntUGE }
1576
- }
1578
+ } ;
1579
+ ret ICmp ( cx, cmp, lhs, rhs) ;
1577
1580
}
1578
- } ;
1579
- // FIXME: This wouldn't be necessary if we could bind methods off of
1580
- // objects and therefore abstract over FCmp and ICmp (issue #435). Then
1581
- // we could just write, e.g., "cmp_fn = bind FCmp(cx, _, _, _);" in
1582
- // the above, and "auto eq_result = cmp_fn(eq_cmp, lhs, rhs);" in the
1583
- // below.
1584
-
1585
- fn generic_cmp( cx: @block_ctxt, nt: scalar_type, op: uint, lhs: ValueRef ,
1586
- rhs: ValueRef ) -> ValueRef {
1587
- let r: ValueRef ;
1588
- if nt == nil_type {
1589
- r = C_bool ( op != 0 u) ;
1590
- } else if nt == floating_point {
1591
- r = FCmp ( cx, op, lhs, rhs) ;
1592
- } else { r = ICmp ( cx, op, lhs, rhs) ; }
1593
- ret r;
1594
- }
1595
- ret generic_cmp( cx, nt, cmp, lhs, rhs) ;
1581
+ }
1596
1582
}
1597
1583
1598
1584
type val_pair_fn = fn ( @block_ctxt , ValueRef , ValueRef ) -> @block_ctxt ;
0 commit comments