@@ -307,7 +307,7 @@ struct ctxt_ {
307
307
used_unsafe : @mut HashSet < ast:: node_id > ,
308
308
}
309
309
310
- enum tbox_flag {
310
+ pub enum tbox_flag {
311
311
has_params = 1 ,
312
312
has_self = 2 ,
313
313
needs_infer = 4 ,
@@ -320,9 +320,9 @@ enum tbox_flag {
320
320
needs_subst = 1 | 2 | 8
321
321
}
322
322
323
- type t_box = & ' static t_box_ ;
323
+ pub type t_box = & ' static t_box_ ;
324
324
325
- struct t_box_ {
325
+ pub struct t_box_ {
326
326
sty : sty ,
327
327
id : uint ,
328
328
flags : uint ,
@@ -513,6 +513,57 @@ pub struct substs {
513
513
tps : ~[ t ]
514
514
}
515
515
516
+ mod primitives {
517
+ use super :: { sty, t_box_} ;
518
+
519
+ use core:: option:: None ;
520
+ use syntax:: ast;
521
+
522
+ macro_rules! def_prim_ty(
523
+ ( $name: ident, $sty: expr, $id: expr) => (
524
+ pub static $name: t_box_ = t_box_ {
525
+ sty: $sty,
526
+ id: $id,
527
+ flags: 0 ,
528
+ o_def_id: None ,
529
+ } ;
530
+ )
531
+ )
532
+
533
+ def_prim_ty ! ( TY_NIL , super :: ty_nil, 0 )
534
+ def_prim_ty ! ( TY_BOOL , super :: ty_bool, 1 )
535
+ def_prim_ty ! ( TY_INT , super :: ty_int( ast:: ty_i) , 2 )
536
+ def_prim_ty ! ( TY_CHAR , super :: ty_int( ast:: ty_char) , 3 )
537
+ def_prim_ty ! ( TY_I8 , super :: ty_int( ast:: ty_i8) , 4 )
538
+ def_prim_ty ! ( TY_I16 , super :: ty_int( ast:: ty_i16) , 5 )
539
+ def_prim_ty ! ( TY_I32 , super :: ty_int( ast:: ty_i32) , 6 )
540
+ def_prim_ty ! ( TY_I64 , super :: ty_int( ast:: ty_i64) , 7 )
541
+ def_prim_ty ! ( TY_UINT , super :: ty_uint( ast:: ty_u) , 8 )
542
+ def_prim_ty ! ( TY_U8 , super :: ty_uint( ast:: ty_u8) , 9 )
543
+ def_prim_ty ! ( TY_U16 , super :: ty_uint( ast:: ty_u16) , 10 )
544
+ def_prim_ty ! ( TY_U32 , super :: ty_uint( ast:: ty_u32) , 11 )
545
+ def_prim_ty ! ( TY_U64 , super :: ty_uint( ast:: ty_u64) , 12 )
546
+ def_prim_ty ! ( TY_FLOAT , super :: ty_float( ast:: ty_f) , 13 )
547
+ def_prim_ty ! ( TY_F32 , super :: ty_float( ast:: ty_f32) , 14 )
548
+ def_prim_ty ! ( TY_F64 , super :: ty_float( ast:: ty_f64) , 15 )
549
+
550
+ pub static TY_BOT : t_box_ = t_box_ {
551
+ sty : super :: ty_bot,
552
+ id : 16 ,
553
+ flags : super :: has_ty_bot as uint ,
554
+ o_def_id : None ,
555
+ } ;
556
+
557
+ pub static TY_ERR : t_box_ = t_box_ {
558
+ sty : super :: ty_err,
559
+ id : 17 ,
560
+ flags : super :: has_ty_err as uint ,
561
+ o_def_id : None ,
562
+ } ;
563
+
564
+ pub static LAST_PRIMITIVE_ID : uint = 18 ;
565
+ }
566
+
516
567
// NB: If you change this, you'll probably want to change the corresponding
517
568
// AST structure in libsyntax/ast.rs as well.
518
569
#[ deriving( Eq ) ]
@@ -852,7 +903,7 @@ pub fn mk_ctxt(s: session::Session,
852
903
@ctxt_ {
853
904
diag : s. diagnostic ( ) ,
854
905
interner : @mut HashMap :: new ( ) ,
855
- next_id : @mut 0 ,
906
+ next_id : @mut primitives :: LAST_PRIMITIVE_ID ,
856
907
vecs_implicitly_copyable : vecs_implicitly_copyable,
857
908
legacy_modes : legacy_modes,
858
909
cstore : s. cstore ,
@@ -901,6 +952,17 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) }
901
952
// Interns a type/name combination, stores the resulting box in cx.interner,
902
953
// and returns the box as cast to an unsafe ptr (see comments for t above).
903
954
fn mk_t_with_id ( cx : ctxt , +st : sty , o_def_id : Option < ast:: def_id > ) -> t {
955
+ // Check for primitive types.
956
+ match st {
957
+ ty_nil => return mk_nil ( cx) ,
958
+ ty_err => return mk_err ( cx) ,
959
+ ty_bool => return mk_bool ( cx) ,
960
+ ty_int( i) => return mk_mach_int ( cx, i) ,
961
+ ty_uint( u) => return mk_mach_uint ( cx, u) ,
962
+ ty_float( f) => return mk_mach_float ( cx, f) ,
963
+ _ => { }
964
+ } ;
965
+
904
966
let key = intern_key { sty : to_unsafe_ptr ( & st) , o_def_id : o_def_id } ;
905
967
match cx. interner . find ( & key) {
906
968
Some ( t) => unsafe { return cast:: transmute ( & t. sty ) ; } ,
@@ -996,49 +1058,95 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
996
1058
}
997
1059
}
998
1060
999
- pub fn mk_nil ( cx : ctxt ) -> t { mk_t ( cx, ty_nil) }
1061
+ #[ inline( always) ]
1062
+ pub fn mk_prim_t ( cx : ctxt , primitive : & ' static t_box_ ) -> t {
1063
+ unsafe {
1064
+ cast:: transmute :: < & ' static t_box_ , t > ( primitive)
1065
+ }
1066
+ }
1067
+
1068
+ #[ inline( always) ]
1069
+ pub fn mk_nil ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_NIL ) }
1000
1070
1001
- pub fn mk_err ( cx : ctxt ) -> t { mk_t ( cx, ty_err) }
1071
+ #[ inline( always) ]
1072
+ pub fn mk_err ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_ERR ) }
1002
1073
1003
- pub fn mk_bot ( cx : ctxt ) -> t { mk_t ( cx, ty_bot) }
1074
+ #[ inline( always) ]
1075
+ pub fn mk_bot ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_BOT ) }
1004
1076
1005
- pub fn mk_bool ( cx : ctxt ) -> t { mk_t ( cx, ty_bool) }
1077
+ #[ inline( always) ]
1078
+ pub fn mk_bool ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_BOOL ) }
1006
1079
1007
- pub fn mk_int ( cx : ctxt ) -> t { mk_t ( cx, ty_int ( ast:: ty_i) ) }
1080
+ #[ inline( always) ]
1081
+ pub fn mk_int ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_INT ) }
1008
1082
1009
- pub fn mk_i8 ( cx : ctxt ) -> t { mk_t ( cx, ty_int ( ast:: ty_i8) ) }
1083
+ #[ inline( always) ]
1084
+ pub fn mk_i8 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_I8 ) }
1010
1085
1011
- pub fn mk_i16 ( cx : ctxt ) -> t { mk_t ( cx, ty_int ( ast:: ty_i16) ) }
1086
+ #[ inline( always) ]
1087
+ pub fn mk_i16 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_I16 ) }
1012
1088
1013
- pub fn mk_i32 ( cx : ctxt ) -> t { mk_t ( cx, ty_int ( ast:: ty_i32) ) }
1089
+ #[ inline( always) ]
1090
+ pub fn mk_i32 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_I32 ) }
1014
1091
1015
- pub fn mk_i64 ( cx : ctxt ) -> t { mk_t ( cx, ty_int ( ast:: ty_i64) ) }
1092
+ #[ inline( always) ]
1093
+ pub fn mk_i64 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_I64 ) }
1016
1094
1017
- pub fn mk_float ( cx : ctxt ) -> t { mk_t ( cx, ty_float ( ast:: ty_f) ) }
1095
+ #[ inline( always) ]
1096
+ pub fn mk_float ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_FLOAT ) }
1018
1097
1019
- pub fn mk_uint ( cx : ctxt ) -> t { mk_t ( cx, ty_uint ( ast:: ty_u) ) }
1098
+ #[ inline( always) ]
1099
+ pub fn mk_f32 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_F32 ) }
1020
1100
1021
- pub fn mk_u8 ( cx : ctxt ) -> t { mk_t ( cx, ty_uint ( ast:: ty_u8) ) }
1101
+ #[ inline( always) ]
1102
+ pub fn mk_f64 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_F64 ) }
1022
1103
1023
- pub fn mk_u16 ( cx : ctxt ) -> t { mk_t ( cx, ty_uint ( ast:: ty_u16) ) }
1104
+ #[ inline( always) ]
1105
+ pub fn mk_uint ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_UINT ) }
1024
1106
1025
- pub fn mk_u32 ( cx : ctxt ) -> t { mk_t ( cx, ty_uint ( ast:: ty_u32) ) }
1107
+ #[ inline( always) ]
1108
+ pub fn mk_u8 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_U8 ) }
1026
1109
1027
- pub fn mk_u64 ( cx : ctxt ) -> t { mk_t ( cx, ty_uint ( ast:: ty_u64) ) }
1110
+ #[ inline( always) ]
1111
+ pub fn mk_u16 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_U16 ) }
1028
1112
1029
- pub fn mk_f32 ( cx : ctxt ) -> t { mk_t ( cx, ty_float ( ast:: ty_f32) ) }
1113
+ #[ inline( always) ]
1114
+ pub fn mk_u32 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_U32 ) }
1030
1115
1031
- pub fn mk_f64 ( cx : ctxt ) -> t { mk_t ( cx, ty_float ( ast:: ty_f64) ) }
1116
+ #[ inline( always) ]
1117
+ pub fn mk_u64 ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_U64 ) }
1032
1118
1033
- pub fn mk_mach_int ( cx : ctxt , tm : ast:: int_ty ) -> t { mk_t ( cx, ty_int ( tm) ) }
1119
+ pub fn mk_mach_int ( cx : ctxt , tm : ast:: int_ty ) -> t {
1120
+ match tm {
1121
+ ast:: ty_i => mk_int ( cx) ,
1122
+ ast:: ty_char => mk_char ( cx) ,
1123
+ ast:: ty_i8 => mk_i8 ( cx) ,
1124
+ ast:: ty_i16 => mk_i16 ( cx) ,
1125
+ ast:: ty_i32 => mk_i32 ( cx) ,
1126
+ ast:: ty_i64 => mk_i64 ( cx) ,
1127
+ }
1128
+ }
1034
1129
1035
- pub fn mk_mach_uint ( cx : ctxt , tm : ast:: uint_ty ) -> t { mk_t ( cx, ty_uint ( tm) ) }
1130
+ pub fn mk_mach_uint ( cx : ctxt , tm : ast:: uint_ty ) -> t {
1131
+ match tm {
1132
+ ast:: ty_u => mk_uint ( cx) ,
1133
+ ast:: ty_u8 => mk_u8 ( cx) ,
1134
+ ast:: ty_u16 => mk_u16 ( cx) ,
1135
+ ast:: ty_u32 => mk_u32 ( cx) ,
1136
+ ast:: ty_u64 => mk_u64 ( cx) ,
1137
+ }
1138
+ }
1036
1139
1037
1140
pub fn mk_mach_float ( cx : ctxt , tm : ast:: float_ty ) -> t {
1038
- mk_t ( cx, ty_float ( tm) )
1141
+ match tm {
1142
+ ast:: ty_f => mk_float ( cx) ,
1143
+ ast:: ty_f32 => mk_f32 ( cx) ,
1144
+ ast:: ty_f64 => mk_f64 ( cx) ,
1145
+ }
1039
1146
}
1040
1147
1041
- pub fn mk_char ( cx : ctxt ) -> t { mk_t ( cx, ty_int ( ast:: ty_char) ) }
1148
+ #[ inline( always) ]
1149
+ pub fn mk_char ( cx : ctxt ) -> t { mk_prim_t ( cx, & primitives:: TY_CHAR ) }
1042
1150
1043
1151
pub fn mk_estr ( cx : ctxt , t : vstore ) -> t {
1044
1152
mk_t ( cx, ty_estr ( t) )
0 commit comments