@@ -21,7 +21,7 @@ use util::ppaux::{ty_to_str, proto_ty_to_str, tys_to_str};
21
21
22
22
export ProvidedMethodSource ;
23
23
export InstantiatedTraitRef ;
24
- export TyVid , IntVid , FnVid , RegionVid , vid;
24
+ export TyVid , IntVid , FloatVid , FnVid , RegionVid , vid;
25
25
export br_hashmap;
26
26
export is_instantiable;
27
27
export node_id_to_type;
@@ -86,6 +86,7 @@ export ty_fn, FnTy, FnTyBase, FnMeta, FnSig, mk_fn;
86
86
export ty_fn_proto, ty_fn_purity, ty_fn_ret, ty_fn_ret_style, tys_in_fn_ty;
87
87
export ty_int, mk_int, mk_mach_int, mk_char;
88
88
export mk_i8, mk_u8, mk_i16, mk_u16, mk_i32, mk_u32, mk_i64, mk_u64;
89
+ export mk_f32, mk_f64;
89
90
export ty_estr, mk_estr, type_is_str;
90
91
export ty_evec, mk_evec, type_is_vec;
91
92
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
@@ -102,8 +103,8 @@ export ty_tup, mk_tup;
102
103
export ty_type, mk_type;
103
104
export ty_uint, mk_uint, mk_mach_uint;
104
105
export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
105
- export ty_infer, mk_infer, type_is_ty_var, mk_var, mk_int_var;
106
- export InferTy , TyVar , IntVar ;
106
+ export ty_infer, mk_infer, type_is_ty_var, mk_var, mk_int_var, mk_float_var ;
107
+ export InferTy , TyVar , IntVar , FloatVar ;
107
108
export ty_self, mk_self, type_has_self;
108
109
export ty_class;
109
110
export Region , bound_region, encl_region;
@@ -172,7 +173,8 @@ export ty_sort_str;
172
173
export normalize_ty;
173
174
export to_str;
174
175
export bound_const;
175
- export terr_no_integral_type, terr_ty_param_size, terr_self_substs;
176
+ export terr_no_integral_type, terr_no_floating_point_type;
177
+ export terr_ty_param_size, terr_self_substs;
176
178
export terr_in_field, terr_record_fields, terr_vstores_differ, terr_arg_count;
177
179
export terr_sorts, terr_vec, terr_str, terr_record_size, terr_tuple_size;
178
180
export terr_regions_does_not_outlive, terr_mutability, terr_purity_mismatch;
@@ -666,6 +668,7 @@ enum type_err {
666
668
terr_sorts( expected_found < t > ) ,
667
669
terr_self_substs,
668
670
terr_no_integral_type,
671
+ terr_no_floating_point_type,
669
672
}
670
673
671
674
enum param_bound {
@@ -678,21 +681,24 @@ enum param_bound {
678
681
679
682
enum TyVid = uint;
680
683
enum IntVid = uint;
684
+ enum FloatVid = uint;
681
685
enum FnVid = uint;
682
686
#[ auto_serialize]
683
687
#[ auto_deserialize]
684
688
enum RegionVid = uint;
685
689
686
690
enum InferTy {
687
691
TyVar ( TyVid ) ,
688
- IntVar ( IntVid )
692
+ IntVar ( IntVid ) ,
693
+ FloatVar ( FloatVid )
689
694
}
690
695
691
696
impl InferTy : to_bytes:: IterBytes {
692
697
pure fn iter_bytes ( +lsb0 : bool , f : to_bytes:: Cb ) {
693
698
match self {
694
699
TyVar ( ref tv) => to_bytes:: iter_bytes_2 ( & 0u8 , tv, lsb0, f) ,
695
- IntVar ( ref iv) => to_bytes:: iter_bytes_2 ( & 1u8 , iv, lsb0, f)
700
+ IntVar ( ref iv) => to_bytes:: iter_bytes_2 ( & 1u8 , iv, lsb0, f) ,
701
+ FloatVar ( ref fv) => to_bytes:: iter_bytes_2 ( & 2u8 , fv, lsb0, f)
696
702
}
697
703
}
698
704
}
@@ -758,6 +764,11 @@ impl IntVid: vid {
758
764
pure fn to_str ( ) -> ~str { fmt ! ( "<VI%u>" , self . to_uint( ) ) }
759
765
}
760
766
767
+ impl FloatVid : vid {
768
+ pure fn to_uint ( ) -> uint { * self }
769
+ pure fn to_str ( ) -> ~str { fmt ! ( "<VF%u>" , self . to_uint( ) ) }
770
+ }
771
+
761
772
impl FnVid : vid {
762
773
pure fn to_uint ( ) -> uint { * self }
763
774
pure fn to_str ( ) -> ~str { fmt ! ( "<F%u>" , self . to_uint( ) ) }
@@ -773,13 +784,15 @@ impl InferTy {
773
784
match self {
774
785
TyVar ( v) => v. to_uint ( ) << 1 ,
775
786
IntVar ( v) => ( v. to_uint ( ) << 1 ) + 1 ,
787
+ FloatVar ( v) => ( v. to_uint ( ) << 1 ) + 2
776
788
}
777
789
}
778
790
779
791
pure fn to_str ( ) -> ~str {
780
792
match self {
781
793
TyVar ( v) => v. to_str ( ) ,
782
794
IntVar ( v) => v. to_str ( ) ,
795
+ FloatVar ( v) => v. to_str ( )
783
796
}
784
797
}
785
798
}
@@ -812,6 +825,12 @@ impl IntVid : to_bytes::IterBytes {
812
825
}
813
826
}
814
827
828
+ impl FloatVid : to_bytes:: IterBytes {
829
+ pure fn iter_bytes ( +lsb0 : bool , f : to_bytes:: Cb ) {
830
+ ( * self ) . iter_bytes ( lsb0, f)
831
+ }
832
+ }
833
+
815
834
impl FnVid : to_bytes:: IterBytes {
816
835
pure fn iter_bytes ( +lsb0 : bool , f : to_bytes:: Cb ) {
817
836
( * self ) . iter_bytes ( lsb0, f)
@@ -1030,6 +1049,10 @@ fn mk_u32(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u32)) }
1030
1049
1031
1050
fn mk_u64 ( cx : ctxt ) -> t { mk_t ( cx, ty_uint ( ast:: ty_u64) ) }
1032
1051
1052
+ fn mk_f32 ( cx : ctxt ) -> t { mk_t ( cx, ty_float ( ast:: ty_f32) ) }
1053
+
1054
+ fn mk_f64 ( cx : ctxt ) -> t { mk_t ( cx, ty_float ( ast:: ty_f64) ) }
1055
+
1033
1056
fn mk_mach_int ( cx : ctxt , tm : ast:: int_ty ) -> t { mk_t ( cx, ty_int ( tm) ) }
1034
1057
1035
1058
fn mk_mach_uint ( cx : ctxt , tm : ast:: uint_ty ) -> t { mk_t ( cx, ty_uint ( tm) ) }
@@ -1110,9 +1133,9 @@ fn mk_class(cx: ctxt, class_id: ast::def_id, +substs: substs) -> t {
1110
1133
1111
1134
fn mk_var ( cx : ctxt , v : TyVid ) -> t { mk_infer ( cx, TyVar ( v) ) }
1112
1135
1113
- fn mk_int_var ( cx : ctxt , v : IntVid ) -> t {
1114
- mk_infer ( cx , IntVar ( v ) )
1115
- }
1136
+ fn mk_int_var ( cx : ctxt , v : IntVid ) -> t { mk_infer ( cx , IntVar ( v ) ) }
1137
+
1138
+ fn mk_float_var ( cx : ctxt , v : FloatVid ) -> t { mk_infer ( cx , FloatVar ( v ) ) }
1116
1139
1117
1140
fn mk_infer ( cx : ctxt , it : InferTy ) -> t { mk_t ( cx, ty_infer ( it) ) }
1118
1141
@@ -1661,7 +1684,8 @@ pure fn type_is_unique(ty: t) -> bool {
1661
1684
pure fn type_is_scalar(ty: t) -> bool {
1662
1685
match get(ty).sty {
1663
1686
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
1664
- ty_infer(IntVar(_)) | ty_type | ty_ptr(_) => true,
1687
+ ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) | ty_type |
1688
+ ty_ptr(_) => true,
1665
1689
_ => false
1666
1690
}
1667
1691
}
@@ -2428,7 +2452,7 @@ fn type_is_integral(ty: t) -> bool {
2428
2452
2429
2453
fn type_is_fp(ty: t) -> bool {
2430
2454
match get(ty).sty {
2431
- ty_float(_) => true,
2455
+ ty_infer(FloatVar(_)) | ty_float(_) => true,
2432
2456
_ => false
2433
2457
}
2434
2458
}
@@ -3260,6 +3284,7 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
3260
3284
ty_tup( _) => ~"tuple",
3261
3285
ty_infer( TyVar ( _) ) => ~"inferred type",
3262
3286
ty_infer( IntVar ( _) ) => ~"integral variable",
3287
+ ty_infer( FloatVar ( _) ) => ~"floating-point variable",
3263
3288
ty_param( _) => ~"type parameter",
3264
3289
ty_self => ~"self "
3265
3290
}
@@ -3387,6 +3412,10 @@ fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
3387
3412
~"couldn' t determine an appropriate integral type for integer \
3388
3413
literal"
3389
3414
}
3415
+ terr_no_floating_point_type => {
3416
+ ~"couldn' t determine an appropriate floating point type for \
3417
+ floating point literal"
3418
+ }
3390
3419
}
3391
3420
}
3392
3421
@@ -4000,7 +4029,7 @@ fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool {
4000
4029
match get ( ty) . sty {
4001
4030
ty_bool => tycat_bool,
4002
4031
ty_int( _) | ty_uint( _) | ty_infer( IntVar ( _) ) => tycat_int,
4003
- ty_float( _) => tycat_float,
4032
+ ty_float( _) | ty_infer ( FloatVar ( _ ) ) => tycat_float,
4004
4033
ty_rec( _) | ty_tup( _) | ty_enum( _, _) => tycat_struct,
4005
4034
ty_bot => tycat_bot,
4006
4035
_ => tycat_other
@@ -4230,6 +4259,11 @@ impl IntVid : cmp::Eq {
4230
4259
pure fn ne ( other : & IntVid ) -> bool { * self != * ( * other) }
4231
4260
}
4232
4261
4262
+ impl FloatVid : cmp:: Eq {
4263
+ pure fn eq ( other : & FloatVid ) -> bool { * self == * ( * other) }
4264
+ pure fn ne ( other : & FloatVid ) -> bool { * self != * ( * other) }
4265
+ }
4266
+
4233
4267
impl FnVid : cmp:: Eq {
4234
4268
pure fn eq ( other : & FnVid ) -> bool { * self == * ( * other) }
4235
4269
pure fn ne ( other : & FnVid ) -> bool { * self != * ( * other) }
0 commit comments