@@ -1840,33 +1840,67 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
1840
1840
1841
1841
// FIXME: implement proper structural comparison.
1842
1842
1843
- fn trans_compare( @block_ctxt cx, ast. binop op,
1843
+ fn trans_compare( @block_ctxt cx, ast. binop op, @ty . t intype ,
1844
1844
ValueRef lhs, ValueRef rhs) -> ValueRef {
1845
1845
auto cmp = lib. llvm. LLVMIntEQ ;
1846
1846
alt ( op) {
1847
1847
case ( ast. eq) { cmp = lib. llvm. LLVMIntEQ ; }
1848
1848
case ( ast. ne) { cmp = lib. llvm. LLVMIntNE ; }
1849
1849
1850
- // FIXME (issue #57): switch by signedness.
1851
- case ( ast. lt) { cmp = lib. llvm. LLVMIntSLT ; }
1852
- case ( ast. le) { cmp = lib. llvm. LLVMIntSLE ; }
1853
- case ( ast. ge) { cmp = lib. llvm. LLVMIntSGE ; }
1854
- case ( ast. gt) { cmp = lib. llvm. LLVMIntSGT ; }
1850
+ case ( ast. lt) {
1851
+ if ( ty. type_is_signed( intype) ) {
1852
+ cmp = lib. llvm. LLVMIntSLT ;
1853
+ } else {
1854
+ cmp = lib. llvm. LLVMIntULT ;
1855
+ }
1856
+ }
1857
+ case ( ast. le) {
1858
+ if ( ty. type_is_signed( intype) ) {
1859
+ cmp = lib. llvm. LLVMIntSLE ;
1860
+ } else {
1861
+ cmp = lib. llvm. LLVMIntULE ;
1862
+ }
1863
+ }
1864
+ case ( ast. gt) {
1865
+ if ( ty. type_is_signed( intype) ) {
1866
+ cmp = lib. llvm. LLVMIntSGT ;
1867
+ } else {
1868
+ cmp = lib. llvm. LLVMIntUGT ;
1869
+ }
1870
+ }
1871
+ case ( ast. ge) {
1872
+ if ( ty. type_is_signed( intype) ) {
1873
+ cmp = lib. llvm. LLVMIntSGE ;
1874
+ } else {
1875
+ cmp = lib. llvm. LLVMIntUGE ;
1876
+ }
1877
+ }
1855
1878
}
1856
1879
ret cx. build. ICmp ( cmp, lhs, rhs) ;
1857
1880
}
1858
1881
1859
- fn trans_eager_binop( @block_ctxt cx, ast. binop op,
1882
+ fn trans_eager_binop( @block_ctxt cx, ast. binop op, @ty . t intype ,
1860
1883
ValueRef lhs, ValueRef rhs) -> ValueRef {
1861
1884
1862
1885
alt ( op) {
1863
1886
case ( ast. add) { ret cx. build. Add ( lhs, rhs) ; }
1864
1887
case ( ast. sub) { ret cx. build. Sub ( lhs, rhs) ; }
1865
1888
1866
- // FIXME (issue #57): switch by signedness.
1867
1889
case ( ast. mul) { ret cx. build. Mul ( lhs, rhs) ; }
1868
- case ( ast. div) { ret cx. build. SDiv ( lhs, rhs) ; }
1869
- case ( ast. rem) { ret cx. build. SRem ( lhs, rhs) ; }
1890
+ case ( ast. div) {
1891
+ if ( ty. type_is_signed( intype) ) {
1892
+ ret cx. build. SDiv ( lhs, rhs) ;
1893
+ } else {
1894
+ ret cx. build. UDiv ( lhs, rhs) ;
1895
+ }
1896
+ }
1897
+ case ( ast. rem) {
1898
+ if ( ty. type_is_signed( intype) ) {
1899
+ ret cx. build. SRem ( lhs, rhs) ;
1900
+ } else {
1901
+ ret cx. build. URem ( lhs, rhs) ;
1902
+ }
1903
+ }
1870
1904
1871
1905
case ( ast. bitor) { ret cx. build. Or ( lhs, rhs) ; }
1872
1906
case ( ast. bitand) { ret cx. build. And ( lhs, rhs) ; }
@@ -1875,7 +1909,7 @@ fn trans_eager_binop(@block_ctxt cx, ast.binop op,
1875
1909
case ( ast. lsr) { ret cx. build. LShr ( lhs, rhs) ; }
1876
1910
case ( ast. asr) { ret cx. build. AShr ( lhs, rhs) ; }
1877
1911
case ( _) {
1878
- ret trans_compare( cx, op, lhs, rhs) ;
1912
+ ret trans_compare( cx, op, intype , lhs, rhs) ;
1879
1913
}
1880
1914
}
1881
1915
fail;
@@ -1950,10 +1984,12 @@ fn trans_binary(@block_ctxt cx, ast.binop op,
1950
1984
case ( _) {
1951
1985
// Remaining cases are eager:
1952
1986
auto lhs = trans_expr( cx, a) ;
1953
- lhs = autoderef( lhs. bcx, lhs. val, ty. expr_ty( a) ) ;
1987
+ auto lhty = ty. expr_ty( a) ;
1988
+ lhs = autoderef( lhs. bcx, lhs. val, lhty) ;
1954
1989
auto rhs = trans_expr( lhs. bcx, b) ;
1955
- rhs = autoderef( rhs. bcx, rhs. val, ty. expr_ty( b) ) ;
1956
- ret res( rhs. bcx, trans_eager_binop( rhs. bcx, op,
1990
+ auto rhty = ty. expr_ty( b) ;
1991
+ rhs = autoderef( rhs. bcx, rhs. val, rhty) ;
1992
+ ret res( rhs. bcx, trans_eager_binop( rhs. bcx, op, lhty,
1957
1993
lhs. val, rhs. val) ) ;
1958
1994
}
1959
1995
}
@@ -2142,7 +2178,8 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
2142
2178
2143
2179
case ( ast. pat_lit( ?lt, ?ann) ) {
2144
2180
auto lllit = trans_lit( cx. fcx. ccx, * lt, ann) ;
2145
- auto lleq = trans_compare( cx, ast. eq, llval, lllit) ;
2181
+ auto lltype = ty. ann_to_type( ann) ;
2182
+ auto lleq = trans_compare( cx, ast. eq, lltype, llval, lllit) ;
2146
2183
2147
2184
auto matched_cx = new_sub_block_ctxt( cx, "matched_cx" ) ;
2148
2185
cx. build. CondBr ( lleq, matched_cx. llbb, next_cx. llbb) ;
@@ -3035,7 +3072,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
3035
3072
auto lhs_val = load_scalar_or_boxed( lhs_res. res. bcx,
3036
3073
lhs_res. res. val, t) ;
3037
3074
auto rhs_res = trans_expr( lhs_res. res. bcx, src) ;
3038
- auto v = trans_eager_binop( rhs_res. bcx, op, lhs_val, rhs_res. val) ;
3075
+ auto v = trans_eager_binop( rhs_res. bcx, op, t,
3076
+ lhs_val, rhs_res. val) ;
3039
3077
// FIXME: calculate copy init-ness in typestate.
3040
3078
ret copy_ty( rhs_res. bcx, DROP_EXISTING ,
3041
3079
lhs_res. res. val, v, t) ;
0 commit comments