@@ -44,9 +44,9 @@ type glue_fns = rec(ValueRef activate_glue,
44
44
ValueRef exit_task_glue ,
45
45
vec[ ValueRef ] upcall_glues ) ;
46
46
47
+ tag arity { nullary; n_ary ( uint) ; }
47
48
type tag_info = rec ( type_handle th,
48
- hashmap[ ast. def_id, uint] variant_indices ,
49
- hashmap[ ast. def_id, uint] n_ary_variant_indices ) ;
49
+ mutable vec[ tup( ast. def_id, arity) ] variants ) ;
50
50
51
51
state type crate_ctxt = rec ( session. session sess,
52
52
ModuleRef llmod,
@@ -55,7 +55,7 @@ state type crate_ctxt = rec(session.session sess,
55
55
hashmap[ str, ValueRef ] fn_names,
56
56
hashmap[ ast. def_id , ValueRef ] fn_ids,
57
57
hashmap[ ast. def_id , @ast. item ] items,
58
- hashmap[ ast. def_id , tag_info] tags,
58
+ hashmap[ ast. def_id , @ tag_info] tags,
59
59
@glue_fns glues,
60
60
namegen names,
61
61
str path) ;
@@ -1133,14 +1133,22 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
1133
1133
case ( ast. def_variant ( ?tid, ?vid) ) {
1134
1134
check ( cx. fcx . ccx . tags . contains_key ( tid) ) ;
1135
1135
auto info = cx. fcx . ccx . tags . get ( tid) ;
1136
- if ( info. n_ary_variant_indices . contains_key ( vid) ) {
1137
- cx. fcx . ccx . sess . unimpl ( "n-ary tag constructors in " +
1138
- "trans" ) ;
1139
- } else {
1140
- // Nullary tag variant case.
1141
- auto idx = info. variant_indices . get ( vid) ;
1142
- auto elems = vec ( C_int ( idx as int ) ) ;
1143
- ret tup( res ( cx, C_struct ( elems) ) , false ) ;
1136
+ auto i = 0 ;
1137
+ for ( tup( ast. def_id, arity) v in info. variants) {
1138
+ if ( vid == v. _0 ) {
1139
+ alt ( v. _1 ) {
1140
+ case ( nullary) {
1141
+ auto elems = vec ( C_int ( i) ) ;
1142
+ ret tup ( res ( cx, C_struct ( elems) ) , false ) ;
1143
+ }
1144
+ case ( n_ary ( _) ) {
1145
+ cx. fcx . ccx . sess . unimpl ( "n-ary tag " +
1146
+ "constructor in " +
1147
+ "trans" ) ;
1148
+ }
1149
+ }
1150
+ }
1151
+ i += 1 ;
1144
1152
}
1145
1153
}
1146
1154
case ( _) {
@@ -1716,17 +1724,15 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
1716
1724
let vec[ TypeRef ] variant_tys = vec ( ) ;
1717
1725
1718
1726
auto info = cx. tags . get ( tag_id) ;
1719
- auto variant_indices = info. variant_indices ;
1720
- auto n_ary_variant_indices = info. n_ary_variant_indices ;
1727
+ let vec[ tup ( ast. def_id , arity) ] variant_info = vec ( ) ;
1721
1728
1722
1729
auto tag_ty;
1723
1730
if ( _vec. len [ ast. variant ] ( variants) == 0 u) {
1724
1731
tag_ty = T_struct ( vec ( T_int ( ) ) ) ;
1725
1732
} else {
1726
- auto variant_idx = 0 u;
1727
- auto n_ary_variant_idx = 0 u;
1728
-
1733
+ auto n_ary_idx = 0 u;
1729
1734
for ( ast. variant variant in variants) {
1735
+ auto arity_info;
1730
1736
if ( _vec. len [ @ast. ty ] ( variant. args ) > 0 u) {
1731
1737
let vec[ TypeRef ] lltys = vec ( ) ;
1732
1738
@@ -1741,18 +1747,20 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
1741
1747
1742
1748
variant_tys += vec ( T_struct ( lltys) ) ;
1743
1749
1744
- n_ary_variant_indices. insert ( variant. id ,
1745
- n_ary_variant_idx) ;
1746
- n_ary_variant_idx += 1 u;
1750
+ arity_info = n_ary ( n_ary_idx) ;
1751
+ n_ary_idx += 1 u;
1752
+ } else {
1753
+ arity_info = nullary;
1747
1754
}
1748
1755
1749
- variant_indices. insert ( variant. id , variant_idx) ;
1750
- variant_idx += 1 u;
1756
+ variant_info += vec ( tup ( variant. id , arity_info) ) ;
1751
1757
}
1752
1758
1753
1759
tag_ty = T_struct ( vec ( T_int ( ) , T_union ( variant_tys) ) ) ;
1754
1760
}
1755
1761
1762
+ info. variants = variant_info;
1763
+
1756
1764
auto th = cx. tags . get ( tag_id) . th . llth ;
1757
1765
llvm. LLVMRefineType ( llvm. LLVMResolveTypeHandle ( th) , tag_ty) ;
1758
1766
}
@@ -1782,9 +1790,9 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
1782
1790
case ( ast. item_tag ( _, ?variants, _, ?tag_id) ) {
1783
1791
auto vi = new_def_hash[ uint] ( ) ;
1784
1792
auto navi = new_def_hash[ uint] ( ) ;
1785
- cx . tags . insert ( tag_id , rec ( th= mk_type_handle ( ) ,
1786
- variant_indices=vi ,
1787
- n_ary_variant_indices=navi ) ) ;
1793
+ let vec [ tup ( ast . def_id , arity ) ] variant_info = vec ( ) ;
1794
+ cx . tags . insert ( tag_id , @ rec ( th= mk_type_handle ( ) ,
1795
+ mutable variants=variant_info ) ) ;
1788
1796
}
1789
1797
1790
1798
case ( _) { /* fall through */ }
@@ -1973,7 +1981,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output) {
1973
1981
fn_names = new_str_hash[ ValueRef ] ( ) ,
1974
1982
fn_ids = new_def_hash[ ValueRef ] ( ) ,
1975
1983
items = new_def_hash[ @ast. item ] ( ) ,
1976
- tags = new_def_hash[ tag_info] ( ) ,
1984
+ tags = new_def_hash[ @ tag_info] ( ) ,
1977
1985
glues = glues,
1978
1986
names = namegen ( 0 ) ,
1979
1987
path = "_rust" ) ;
0 commit comments